Balanced Rows¶
Groups of equal tiles wrap in rows of even size, so a wrapped row never holds a single tile. Four tiles that do not fit in one row become two rows of two, five become three and two, and seven become three, two, and two.
Decision¶
| When | Use |
|---|---|
| Stolon's own groups, such as count cards, choice cards, the check grid, and a List in its grid layout | Nothing. Stolon balances them, and a page built with createConfigPage also balances every such group on it. |
| A group of tiles a plugin builds itself, such as a row of plain cards | balanceRows. |
| Text chips that size to their words, such as tags, pills, and breadcrumbs | No balanceRows. They wrap like text. |
Usage¶
import * as base from './configurationpage?name=myplugin_stolon.js';
var balance = base.balanceRows(container, { minWidth: 160, maxColumns: 4 });
// later, on viewhide
balance.destroy();
bindBalancedRows(view) balances every count card group, choice group, and check grid under a page, and the ones added later. Both return { update, destroy }.
States and Modifiers¶
minWidthis the least a tile takes, 160 by default, and sets how many tiles fit in a row.maxColumnscaps a row.- A group's CSS may set
--stolon-balance-minand--stolon-balance-maxinstead, which win over the options, such asstyle="--stolon-balance-max: 4"in page markup. - The rows stay within one tile of each other. When a row would hold one tile, the group uses fewer, fuller rows instead.
- Below two columns, as on a phone, each tile takes its own row.
- It lays out again when the group resizes or its tiles change.
update()lays it out on demand.
Gotchas¶
- The group becomes a grid with the
stolon-balancedclass, so a group's owndisplayand column rules give way to it.
Reference¶
Generated from the code by scripts/build-docs.mjs. Edit the code, not this section.
bindBalancedRows¶
function bindBalancedRows(root: ParentNode): BalanceHandle
Balances every group of tiles under a root, such as count cards, status cards, choice cards, and a check grid, so a wrapped row never holds a single tile. It also balances groups added later. createConfigPage runs it on every page.
| Class | What it looks like |
|---|---|
stolon-balanced |
Tiles in rows of even size, so no row holds a single tile, laid out by balanceRows |
Example¶
Example Code¶
<!-- title: Balanced Rows -->
<div id="mount"></div>
<script type="module">
const base = await window.__baseReady;
const mount = document.getElementById('mount');
const shared = base.createShared(document.getElementById('view'), 'preview-plugin', 'Preview');
const colors = ['blue', 'green', 'orange', 'purple', 'red', 'gray', 'teal'];
[4, 5, 7].forEach((count) => {
const note = document.createElement('p');
note.className = 'fieldDescription';
note.textContent = count + ' cards';
mount.appendChild(note);
const box = document.createElement('div');
mount.appendChild(box);
shared.renderCards(box, colors.slice(0, count).map((color, i) => ({ count: (i + 1) * 7, label: 'Group ' + (i + 1), color: color })));
});
</script>