Stack
Lays out its children in a column or a row with a token gap between them. It is a Box with display="flex", so it takes every Box prop, renders on the server, and keeps as for semantics.
import { Stack } from '@blocks/design-system'Usage
A Stack is a column with a md gap unless you say otherwise.
- Freeze the branch
- Run verification
- Pack the tarball
Source · stack/vertical.tsx
import { Box, Stack } from '@blocks/design-system'
export default function Vertical() {
return (
<Stack as="ol" gap="sm" margin="none" padding="none" aria-label="Release steps">
{['Freeze the branch', 'Run verification', 'Pack the tarball'].map((step) => (
<Box as="li" key={step} padding="sm" border="default" dangerouslySetStyle={{ listStyle: 'none' }}>
{step}
</Box>
))}
</Stack>
)
}Rows that wrap
direction="row" with wrap="wrap" lets a list of actions flow onto more lines on a narrow screen. Use native links for navigation and native buttons for actions; the reading and Tab order stay the source order.
Source · stack/item-actions.tsx
import { Box, Stack } from '@blocks/design-system'
const actions = ['Edit item', 'Duplicate', 'Move to another board', 'Copy link', 'Archive']
export default function ItemActions() {
return (
<Stack as="nav" aria-label="Item actions" direction="row" wrap="wrap" gap="sm">
{actions.map((action) => (
<Box as="a" key={action} href={`#${action.toLowerCase().replaceAll(' ', '-')}`} paddingX="md" paddingY="xs" border="default">
{action}
</Box>
))}
<Box as="button" type="button" paddingX="md" paddingY="xs" border="danger">
Delete
</Box>
</Stack>
)
}Spreading items
justify distributes children along the main axis and align places them on the cross axis.
Launch checklist
SettingsSource · stack/spread.tsx
import { Box, Stack } from '@blocks/design-system'
export default function Spread() {
return (
<Stack as="header" direction="row" justify="space-between" align="center" padding="md" border="default">
<Box as="h3" margin="none">
Launch checklist
</Box>
<Box as="a" href="#checklist-settings">
Settings
</Box>
</Stack>
)
}Responsive
Every prop takes a breakpoint object. These actions stack full-width below md and sit side by side above it.
Source · stack/responsive-actions.tsx
import { Box, Stack } from '@blocks/design-system'
export default function ResponsiveActions() {
return (
<Stack direction={{ base: 'column', md: 'row' }} gap={{ base: 'sm', md: 'md' }} align={{ base: 'stretch', md: 'center' }}>
<Box as="button" type="button" paddingX="md" paddingY="xs" border="accent">
Approve changes
</Box>
<Box as="button" type="button" paddingX="md" paddingY="xs" border="default">
Request changes
</Box>
</Stack>
)
}Props
| Prop | Type | Default | Description |
|---|---|---|---|
align | ResponsiveValue<Align> | — | Cross axis alignment. Responsive. |
as | ElementType | — | The element or component to render, e.g. `as={NextLink}`. |
direction | ResponsiveValue<Direction> | column | Main axis. Defaults to `"column"`. Responsive. |
justify | ResponsiveValue<Justify> | — | Main axis distribution. Responsive. |
wrap | ResponsiveValue<"nowrap" | "wrap" | "wrap-reverse"> | — | Whether children wrap onto new lines. Responsive. |
Also accepts Box layout props, styling escape hatches, margin props and padding props, and the native attributes of the element it renders.
Accessibility
- Avoid
row-reverseandcolumn-reversefor content people read or tab through: the visual order would no longer match the order screen readers and the keyboard follow. - Give a Stack rendered
as="nav"a name witharia-label.