Skip to content
Slotted

Grid

Arranges children in equal columns that reflow with the width of the grid itself, with no breakpoints.

Rotterdam

12,480 units on hand
Healthy

Chicago

8,215 units on hand
Low stock

Singapore

3,902 units on hand
Delayed

Lisbon

6,730 units on hand
Healthy

Osaka

5,118 units on hand
Audit due

Denver

2,044 units on hand
Opening soon

Installation

The packages are a 0.x beta on npm, and their public API changes between beta releases without deprecation. One line installs the binding and the default theme.

bash
pnpm add @slotted/react @slotted/theme @slotted/themes

Grid, Stack, Inline and Container

Use Grid for cells of equal width that wrap into rows, such as cards, metrics or form fields. Use Stack to lay children out in one column and Inline to lay them out in one row, each sized by its content. Use Container to bound the width of a whole page or section; a grid fills whatever width it is given. The root is a div; pass render in React, or write slGrid on a ul or section in Angular, to change the element. The order of the children is the reading order and the Tab order.

Minimum cell width

Without a column count, the grid draws as many equal columns as fit while each stays at least minItemWidth wide, and drops a column when it would not. The steps are xs (8rem), sm (12rem), md (16rem, the default), lg (20rem) and xl (24rem). A minimum wider than the grid becomes one full-width column. A column left empty collapses, so two cells fill the row. Each group below holds the same four cells at one step.

minItemWidth: xs (8rem)
Bay A1
Bay A2
Bay B1
Bay B2
minItemWidth: sm (12rem)
Bay A1
Bay A2
Bay B1
Bay B2
minItemWidth: md (16rem)
Bay A1
Bay A2
Bay B1
Bay B2
minItemWidth: lg (20rem)
Bay A1
Bay A2
Bay B1
Bay B2
minItemWidth: xl (24rem)
Bay A1
Bay A2
Bay B1
Bay B2

Column count

columns sets the most columns a row may hold, from 1 to 12. It is a ceiling, not a promise: a row never holds a cell narrower than minItemWidth, so the grid uses fewer columns when it narrows. A count above the number of children leaves the remaining tracks empty. Four metrics below fill two, three and four columns; with three, the fourth starts a second row.

columns: 2
Revenue

$48,200

Refunds

$1,940

Disputes

7

Payouts

$44,310

columns: 3
Revenue

$48,200

Refunds

$1,940

Disputes

7

Payouts

$44,310

columns: 4
Revenue

$48,200

Refunds

$1,940

Disputes

7

Payouts

$44,310

Gap

gap is the separation between cells, a step on the space scale from 0 to 12, 6 by default. It applies to rows and columns alike. At 0 the cells touch.

gap: 0
SO-10482
SO-10483
SO-10484
gap: 2
SO-10482
SO-10483
SO-10484
gap: 6
SO-10482
SO-10483
SO-10484
gap: 12
SO-10482
SO-10483
SO-10484

Alignment across the row

align positions each child along the block axis inside its own cell. By default, and with stretch, every child takes the height of its row. start, center and end give a child its own height and place it at the top, middle or bottom of the row.

align: start
Ships today.
Waits for the carrier pickup window on Thursday afternoon.
Held until payment clears and the customs check for the destination country finishes.
align: center
Ships today.
Waits for the carrier pickup window on Thursday afternoon.
Held until payment clears and the customs check for the destination country finishes.
align: end
Ships today.
Waits for the carrier pickup window on Thursday afternoon.
Held until payment clears and the customs check for the destination country finishes.
align: stretch
Ships today.
Waits for the carrier pickup window on Thursday afternoon.
Held until payment clears and the customs check for the destination country finishes.

Justification along the row

justify positions each child along the inline axis inside its own cell. With stretch a child fills its cell. start, center and end size the child to its content and place it at the start, middle or end of the cell.

justify: start
Ship
Hold for review
Return to supplier
justify: center
Ship
Hold for review
Return to supplier
justify: end
Ship
Hold for review
Return to supplier
justify: stretch
Ship
Hold for review
Return to supplier

Spanning every column

Grid has no prop that places a child. A child that crosses the row states it on itself with grid-column: 1 / -1, through style: it spans the columns the row holds at that width, and stays one cell when the grid is one column. span 2 would add a second column to a grid that had reflowed to one. In this form the company field spans both columns, and the other four fields fill the two rows below it.

Reflow follows the grid

The grid measures its own width, not the window, so no breakpoint is involved. The same grid with columns={4} and minItemWidth="xs" holds four columns across the preview and fewer inside a card that is half as wide.

Across the whole preview
Bay 1: FullBay 2: HalfBay 3: LowBay 4: Empty
The same grid inside two half-width cards

Zone A

Bay 1: FullBay 2: HalfBay 3: LowBay 4: Empty

Zone B

Bay 1: FullBay 2: HalfBay 3: LowBay 4: Empty

Accessibility

  • This is not the APG grid widget. There is no role="grid", no cell and no arrow-key navigation: Grid lays children out, and the children keep whatever semantics they already had.
  • There is no prop that reorders or places children. Visual order stays DOM order, which is what WCAG 2.2 SC 1.3.2 asks for (technique C27, failure F1) and what keeps the Tab order matching the page.
  • A stated count is a ceiling the grid may lower. Twelve columns become six and then one as the grid narrows, so a page reflows to 320 CSS pixels without scrolling in two dimensions, as WCAG 1.4.10 requires.
  • The reflow is measured against the grid’s own inline size, not the viewport, so a grid inside a narrow panel behaves the same as one inside a narrow window. Grid uses no breakpoint and no container query.
  • minItemWidth is stated in rem, so the point at which a column is dropped moves with the browser zoom WCAG 1.4.4 requires.

API

grid

Props

gap0 | 1 | … | 12Default 6
Sets the separation between cells as a step on the space scale.
columns1 | 2 | … | 12Default auto
Sets the most columns a row may hold. When absent, the grid fits as many as it can.
minItemWidth'xs' | 'sm' | 'md' | 'lg' | 'xl'Default md
Sets the narrowest a cell may become before a column is dropped.
align'start' | 'center' | 'end' | 'stretch'
Positions a child along the block axis, inside its own cell.
justify'start' | 'center' | 'end' | 'stretch'
Positions a child along the inline axis, inside its own cell.
render(props) => ReactNode
Renders a different root element from the props it receives.

Theming

Each token is a CSS custom property: set it in a theme, or on any element to retune every grid inside it.

Grid tokens

TokenDefault
--slotted-grid-columns1
--slotted-grid-min-item-width-lg20rem
--slotted-grid-min-item-width-md16rem
--slotted-grid-min-item-width-sm12rem
--slotted-grid-min-item-width-xl24rem
--slotted-grid-min-item-width-xs8rem

Theme tokens it reads

TokenDefault
--slotted-space-10.125rem
--slotted-space-102.5rem
--slotted-space-113rem
--slotted-space-124rem
--slotted-space-20.25rem
--slotted-space-30.375rem
--slotted-space-40.5rem
--slotted-space-50.75rem
--slotted-space-61rem
--slotted-space-71.25rem
--slotted-space-81.5rem
--slotted-space-92rem