Components
Grid
Two-dimensional CSS Grid layout with token gaps and responsive column values.
Grid provides two-dimensional layout with shared spacing tokens and responsive column values.
Responsive rules use CSS media queries, so rendering does not depend on JavaScript viewport
measurements.
Live preview#
import { Box, Grid, Text } from '@orkest/ui';
export function Example() {
return (
<Grid columns={{ base: 1, sm: 2, lg: 3 }} gap={3}>
<Box padding={4} background="surface-sunken" radius="xl">
<Text size="sm" weight="medium">{'One'}</Text>
</Box>
<Box padding={4} background="surface-sunken" radius="xl">
<Text size="sm" weight="medium">{'Two'}</Text>
</Box>
<Box padding={4} background="surface-sunken" radius="xl">
<Text size="sm" weight="medium">{'Three'}</Text>
</Box>
</Grid>
);
}Native templates#
Pass any valid grid-template-columns value when a fixed count is not enough. The example below
uses auto-fit so the grid fills the available width without breakpoints.
import { Box, Grid, Text } from '@orkest/ui';
export function Example() {
return (
<Grid columns="repeat(auto-fit, minmax(12rem, 1fr))" gap={3}>
<Box padding={4} background="surface-sunken" radius="xl">
<Text size="sm">{'Auto-fit item'}</Text>
</Box>
<Box padding={4} background="surface-sunken" radius="xl">
<Text size="sm">{'Auto-fit item'}</Text>
</Box>
<Box padding={4} background="surface-sunken" radius="xl">
<Text size="sm">{'Auto-fit item'}</Text>
</Box>
</Grid>
);
}Gaps and alignment#
columnGap and rowGap override gap for one axis. align and justify map to align-items and
justify-items.
Column gap
Row gap
Alignment
Tokens
import { Box, Grid, Text } from '@orkest/ui';
export function Example() {
return (
<Grid columns={2} columnGap={6} rowGap={2} align="center">
<Box padding={3} background="surface-sunken" radius="xl">
<Text as="p" size="sm" align="center">{'Column gap'}</Text>
</Box>
<Box padding={3} background="surface-sunken" radius="xl">
<Text as="p" size="sm" align="center">{'Row gap'}</Text>
</Box>
<Box padding={3} background="surface-sunken" radius="xl">
<Text as="p" size="sm" align="center">{'Alignment'}</Text>
</Box>
<Box padding={3} background="surface-sunken" radius="xl">
<Text as="p" size="sm" align="center">{'Tokens'}</Text>
</Box>
</Grid>
);
}Responsive values#
columns, rows, gap, columnGap, and rowGap accept an object with base, sm, md, lg,
and xl keys. Values carry forward to larger breakpoints.
<Grid columns={{ base: 1, sm: 2, lg: 3 }} gap={{ base: 2, lg: 6 }}>
{/* items */}
</Grid>| Key | Media query |
|---|---|
base | No media query |
sm | min-width: 40rem (640px) |
md | min-width: 48rem (768px) |
lg | min-width: 64rem (1024px) |
xl | min-width: 80rem (1280px) |
Props#
| Prop | Type | Default |
|---|---|---|
columns | number | string | ResponsiveValue<number | string> | 1 |
| Column count or any valid grid-template-columns value. Numbers become equal minmax tracks. | ||
rows | number | string | ResponsiveValue<number | string> | 'auto' |
| Row count or any valid grid-template-rows value. Numbers become equal minmax tracks. | ||
gap | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 8 | 10 | 12 | 16 | 20 | ResponsiveValue<...> | 0 |
| Row and column gap as a spacing token step. | ||
columnGap | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 8 | 10 | 12 | 16 | 20 | ResponsiveValue<...> | — |
| Column gap. Falls back to gap. | ||
rowGap | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 8 | 10 | 12 | 16 | 20 | ResponsiveValue<...> | — |
| Row gap. Falls back to gap. | ||
autoFlow | 'row' | 'column' | 'dense' | 'row dense' | 'column dense' | 'row' |
| CSS grid-auto-flow behavior. | ||
align | 'start' | 'center' | 'end' | 'stretch' | 'stretch' |
| Vertical alignment of grid items. | ||
justify | 'start' | 'center' | 'end' | 'stretch' | 'stretch' |
| Horizontal alignment of grid items. | ||
as | ElementType | 'div' |
| Element to render, preserving native attributes. | ||
className | string | — |
| Merged with the internal class name. | ||
native attributes | ComponentPropsWithRef<T> | — |
| Inherited from the element selected by as. | ||
GridProps<T>, GridResponsiveValue<T>, and the individual value types are exported for wrapper
components.
Accessibility#
Gridchanges visual layout only. It adds no ARIA roles or keyboard behavior.- Reading order remains DOM order. Avoid visual reordering that contradicts the source order.
autoFlow="dense"can move items visually; use it only when the content order does not carry meaning.- Use
asto render semantic elements such assection,ul, ornavwhen appropriate. - Responsive behavior is CSS-only. There are no resize listeners and no client-side viewport reads.