Stack
Arranges children in one column and separates them by a step of the space scale.
Order SO-10482
Placed by Maria Chen on March 4 for the Harbor Street store.import { Badge } from '@slotted/react/badge';import { Inline } from '@slotted/react/inline';import { Stack } from '@slotted/react/stack';import { Heading, Text } from '@slotted/react/typography';export default function StackBasic() { return ( <Stack> <Heading level={2} size="md"> Order SO-10482 </Heading> <Text tone="muted">Placed by Maria Chen on March 4 for the Harbor Street store.</Text> <Inline gap={2}> <Badge tone="success">Shipped</Badge> <Badge tone="info">Wholesale</Badge> </Inline> <Text>Estimated delivery on March 9.</Text> </Stack> );}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.
pnpm add @slotted/react @slotted/theme @slotted/themesGap
gap sets the separation between children as a step on the space scale, from 0 for none to 12. The default is 6. Each column below holds the same three badges at one step. A stack lays out one column; use Inline for a row.
import { Badge } from '@slotted/react/badge';import { Inline } from '@slotted/react/inline';import { Stack } from '@slotted/react/stack';import { Text } from '@slotted/react/typography';const GAPS = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12] as const;export default function StackGap() { return ( <Inline align="start" gap={8}> {GAPS.map((gap) => ( <Stack key={gap} gap={1}> <Text size="xs" tone="muted"> Gap {gap} </Text> <Stack gap={gap}> <Badge tone="success">Packed</Badge> <Badge tone="warning">Late</Badge> <Badge tone="danger">Held</Badge> </Stack> </Stack> ))} </Inline> );}Alignment
align positions children across the column, along the inline axis: start, center or end give each child its own width and place it on that edge. Without align, children stretch to the width of the column, as the last card shows. A button directly inside a stack stretches the same way, so a row of actions belongs in an Inline.
align start
align center
align end
align stretch
import { Badge } from '@slotted/react/badge';import { Card, CardBody, CardHeader } from '@slotted/react/card';import { Stack } from '@slotted/react/stack';import { Heading } from '@slotted/react/typography';const ALIGNS = ['start', 'center', 'end', 'stretch'] as const;export default function StackAlign() { return ( <Stack gap={4}> {ALIGNS.map((align) => ( <Card key={align}> <CardHeader> <Heading level={2} size="sm"> align {align} </Heading> </CardHeader> <CardBody> <Stack align={align} gap={2}> <Badge tone="info">Wholesale</Badge> <Badge tone="warning">Priority shipping</Badge> <Badge tone="secondary">Fragile</Badge> </Stack> </CardBody> </Card> ))} </Stack> );}Justification
justify positions children along the column and distributes the free space between them: start, center, end, between, around or evenly. It moves nothing until the stack is taller than its content, so each stack here has a block size of 12rem. In a page shell the stack takes that height from its container.
justify start
justify center
justify end
justify between
justify around
justify evenly
import { Badge } from '@slotted/react/badge';import { Card, CardBody, CardHeader } from '@slotted/react/card';import { Grid } from '@slotted/react/grid';import { Stack } from '@slotted/react/stack';import { Heading } from '@slotted/react/typography';const JUSTIFIES = ['start', 'center', 'end', 'between', 'around', 'evenly'] as const;export default function StackJustify() { return ( <Grid columns={3} gap={4} minItemWidth="xs"> {JUSTIFIES.map((justify) => ( <Card key={justify}> <CardHeader> <Heading level={2} size="sm"> justify {justify} </Heading> </CardHeader> <CardBody> <Stack align="start" gap={2} justify={justify} style={{ blockSize: '12rem' }}> <Badge tone="info">Packed</Badge> <Badge tone="warning">Shipped</Badge> <Badge tone="success">Delivered</Badge> </Stack> </CardBody> </Card> ))} </Grid> );}Sections and lines
A stack inside a stack gives each level its own gap: a wide gap separates the sections and a narrow gap separates the lines inside one. The outer stack here uses 8 and each inner stack uses 2.
Order SO-10482
import { Card, CardBody, CardHeader } from '@slotted/react/card';import { Stack } from '@slotted/react/stack';import { Heading, Text } from '@slotted/react/typography';const SECTIONS = [ { title: 'Payment method', value: 'Visa ending 4242' }, { title: 'Billing address', value: '200 Harbor Street, Portland' }, { title: 'Shipping method', value: 'Priority shipping, 2 days' },] as const;export default function StackNested() { return ( <Card> <CardHeader> <Heading level={2} size="md"> Order SO-10482 </Heading> </CardHeader> <CardBody> <Stack gap={8}> {SECTIONS.map((section) => ( <Stack key={section.title} gap={2}> <Text weight="semibold">{section.title}</Text> <Text tone="muted">{section.value}</Text> </Stack> ))} </Stack> </CardBody> </Card> );}Another element
A stack paints nothing and claims no semantics, so you choose the element. In React, render replaces the root element. In Angular, the slStack attribute goes on the element itself. Fields that are sent together stand in a form, so Enter in a field submits them. A ul keeps the bullets and the indentation the browser gives it: a stack does not reset them.
import { Button } from '@slotted/react/button';import { Field, FieldLabel } from '@slotted/react/field';import { Inline } from '@slotted/react/inline';import { Stack } from '@slotted/react/stack';import { TextField } from '@slotted/react/text-field';export default function StackForm() { return ( <Stack gap={5} render={(props) => ( <form {...props} onSubmit={(event) => { event.preventDefault(); }} /> )} > <Field required> <FieldLabel>Email</FieldLabel> <TextField type="email" autoComplete="email" /> </Field> <Field required> <FieldLabel>Password</FieldLabel> <TextField type="password" autoComplete="current-password" /> </Field> <Inline justify="end"> <Button type="submit">Sign in</Button> </Inline> </Stack> );}Accessibility
- Stack has no role and no ARIA. It arranges what you write inside it, and the children keep whatever semantics they already had.
- There is no axis that reverses the 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.
- The element is yours to choose. Render a ul when the children are list items and a form when they are fields, so the document says what it means.
- Separation is a step on the space scale, stated in rem, so it grows with the browser zoom WCAG 1.4.4 requires.
- Alignment uses the logical keywords, so a right-to-left document is the same column mirrored.
API
stack
Props
gap0 | 1 | … | 12Default6- Sets the separation between children as a step on the space scale.
align'start' | 'center' | 'end' | 'stretch'- Positions children across the column, along the inline axis. Without it, children stretch to the width of the column.
justify'start' | 'center' | 'end' | 'between' | 'around' | 'evenly'- Positions children along the column and distributes the free space. It moves nothing until the stack is taller than its content.
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 stack inside it.
Theme tokens it reads
| Token | Default |
|---|---|
--slotted-space-1 | 0.125rem |
--slotted-space-10 | 2.5rem |
--slotted-space-11 | 3rem |
--slotted-space-12 | 4rem |
--slotted-space-2 | 0.25rem |
--slotted-space-3 | 0.375rem |
--slotted-space-4 | 0.5rem |
--slotted-space-5 | 0.75rem |
--slotted-space-6 | 1rem |
--slotted-space-7 | 1.25rem |
--slotted-space-8 | 1.5rem |
--slotted-space-9 | 2rem |