Stack
Slant / Primitives
A column of children with a gap between them, in pixels.
Demo
Usage
import { Badge, Button, Input, Row, Stack, Text } from '@tuttn/slant'
// Children in a column, 10px apart.
<Stack>
<Text variant="title">Notifications</Text>
<Text muted>Choose what you hear about.</Text>
</Stack>
// gap is in pixels. Nest a tight stack in a loose one to group a label with its field.
<Stack as="form" gap={16} onSubmit={create}>
<Stack gap={6}>
<Text as="label" variant="label" htmlFor="title">Title</Text>
<Input id="title" name="title" />
</Stack>
{/* Children stretch to the column; a Row keeps the button its own width. */}
<Row justify="end"><Button type="submit" variant="primary">Create task</Button></Row>
</Stack>
// as="ul" keeps list semantics without bullets or padding; each child is an li.
<Stack as="ul" role="list" gap={4}>
{tags.map(tag => <li key={tag}><Badge>{tag}</Badge></li>)}
</Stack>Props
| Prop | Type | Default | Description |
|---|---|---|---|
gap | number | 10 | Space between children, in pixels. |
as | 'div' | 'section' | 'form' | 'nav' | 'header' | 'footer' | 'ul' | 'li' | 'div' | The element to render. |
…rest | HTMLAttributes<HTMLElement> | — | className, style, id, aria-* and handlers go on the root element, and so does the ref. A gap in style wins over the gap prop. |
Accessibility
- Stack adds no role. Pick
asfor what the content is:formfor a form,navfor a group of links,sectionfor a region with a heading,ulfor a list. - Children appear in DOM order, top to bottom, so the reading order and the Tab order match the screen.
- With
as="ul"the bullets are gone, and Safari's VoiceOver stops announcing it as a list. Addrole="list"where the item count matters.
Stack is a one-column grid, so every child stretches to the column's width: inputs and cards fill it, and so does a Button placed directly inside. Put a button in a Row, or give it justify-self: start, to keep its own width. Stack has no margin or padding of its own, so its spacing is the gap and nothing else.