Grid
A CSS grid of equal columns, or a custom column template. Grid is a Box, so it takes every Box prop and renders on the server.
import { Grid } from '@blocks/design-system'Usage
columns takes a count from 1 to 12. Columns share the width equally and never grow past it because of long content.
Depth
New snow
Wind
Temp
Source · grid/fixed-columns.tsx
import { Box, Grid } from '@blocks/design-system'
export default function FixedColumns() {
return (
<Grid columns={4} gap="sm">
{['Depth', 'New snow', 'Wind', 'Temp'].map((label) => (
<Box key={label} padding="sm" border="default" textAlign="center">
{label}
</Box>
))}
</Grid>
)
}Responsive columns
Pass a breakpoint object to change the count with the screen width. The station catalog is a single readable list below md (48rem) and three columns from md up, with the same markup and reading order.
- Mount HoodOregon · 84 in
- Stevens PassWashington · 61 in
- AltaUtah · 102 in
- MammothCalifornia · 77 in
- Big SkyMontana · 55 in
- TaosNew Mexico · 38 in
Source · grid/station-catalog.tsx
import { Box, Grid } from '@blocks/design-system'
const stations = [
{ name: 'Mount Hood', state: 'Oregon', depth: '84 in' },
{ name: 'Stevens Pass', state: 'Washington', depth: '61 in' },
{ name: 'Alta', state: 'Utah', depth: '102 in' },
{ name: 'Mammoth', state: 'California', depth: '77 in' },
{ name: 'Big Sky', state: 'Montana', depth: '55 in' },
{ name: 'Taos', state: 'New Mexico', depth: '38 in' },
]
export default function StationCatalog() {
return (
<Box as="section" aria-label="Station catalog">
<Grid as="ul" columns={{ base: 1, md: 3 }} gap="md" margin="none" padding="none">
{stations.map((station) => (
<Box as="li" key={station.name} padding="md" border="default" dangerouslySetStyle={{ listStyle: 'none' }}>
<Box as="a" href={`#${station.name.toLowerCase().replaceAll(' ', '-')}`} display="block">
{station.name}
</Box>
<Box as="span" color="text-muted">
{station.state} · {station.depth}
</Box>
</Box>
))}
</Grid>
<Box as="a" href="#all-stations" display="inline-block" marginTop="md">
Browse all stations
</Box>
</Box>
)
}Custom templates
A string becomes grid-template-columns. Custom templates are not responsive; reach for a count when the layout should change with the width.
Results
Source · grid/custom-template.tsx
import { Box, Grid } from '@blocks/design-system'
export default function CustomTemplate() {
return (
<Grid columns="12rem minmax(0, 1fr)" gap="lg">
<Box as="aside" aria-label="Filters" padding="md" border="default">
Filters
</Box>
<Box padding="md" border="default">
Results
</Box>
</Grid>
)
}Props
| Prop | Type | Default | Description |
|---|---|---|---|
as | ElementType | — | The element or component to render, e.g. `as={NextLink}`. |
columns | string | ResponsiveValue<GridColumns> | 1 | Equal columns, from 1 to 12, or a `grid-template-columns` value. A count is responsive, e.g. `{ base: 1, md: 3 }`. Defaults to `1`. |
gap | ResponsiveValue<"sm" | "md" | "lg" | "xl"> | md | `sm`, `md`, `lg` or `xl`. Defaults to `"md"`. Responsive. |
Also accepts Box layout props, styling escape hatches, margin props and padding props, and the native attributes of the element it renders.
Accessibility
- Render lists of cards
as="ul"withas="li"children so screen readers announce the count. - A grid places items in source order, row by row. Keep that order meaningful rather than positioning items out of order.