# 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.

```tsx
import { Stack } from '@blocks/design-system'
```

## Usage

A Stack is a column with a `md` gap unless you say otherwise.

**Example: Release steps** (`examples/stack/vertical.tsx`)

```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.

**Example: Wrapping item actions** (`examples/stack/item-actions.tsx`)

```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.

**Example: Header with a trailing link** (`examples/stack/spread.tsx`)

```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.

**Example: Responsive actions** (`examples/stack/responsive-actions.tsx`)

```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

**`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](https://design-system.blocks-ui.com/components/box.md#props), [styling escape hatches](https://design-system.blocks-ui.com/components/box.md#escape-hatches), [margin props](https://design-system.blocks-ui.com/components/box.md#spacing) and [padding props](https://design-system.blocks-ui.com/components/box.md#spacing), and the native attributes of the element it renders.

## Accessibility

- Avoid `row-reverse` and `column-reverse` for 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 with `aria-label`.
