Grid
import { Grid } from "@cherry-design-system/react";
export function Features() {
return (
<Grid cols={3}>
<div>One</div>
<div>Two</div>
<div>Three</div>
</Grid>
);
}Grid places its children in equal columns, with the column count and gap set per breakpoint. Wrap a child in Col to make it span several columns. Use Flex when items should size to their content.
Examples
Responsive columns
Pass an object keyed by breakpoint (xs, sm, md, lg, xl, xxl, xxxl). Values are mobile first and hold until a larger breakpoint overrides them.
import { Grid } from "@cherry-design-system/react";
export function Gallery({ items }: { items: string[] }) {
return (
<Grid cols={{ xs: 1, md: 2, lg: 4 }} gap={4}>
{items.map((item) => (
<div key={item}>{item}</div>
))}
</Grid>
);
}Spanning columns with Col
span takes a column count or "full" to fill the whole row, and can also change per breakpoint.
import { Col, Grid } from "@cherry-design-system/react";
export function Dashboard() {
return (
<Grid cols={{ xs: 1, lg: 4 }} gap={4}>
<Col span={{ xs: 1, lg: 2 }}>Revenue</Col>
<div>Orders</div>
<div>Refunds</div>
<Col span="full">Activity</Col>
</Grid>
);
}Properties
Grid
Number of equal columns, per breakpoint. Defaults to 3.
Gap as a spacing step: 0, 1, 2, 3, 4, 5, 6, 8, 10, 12, 16, 20 or 24. Defaults to the gutter (20px, 40px from lg).
Grid renders a <div>, forwards its ref to it and passes every other <div> attribute through.
Col
Columns to span, per breakpoint. "full" spans the whole row.
Col renders a <div>, forwards its ref to it and passes every other <div> attribute through. Both parts are safe in Server Components.
Styling
| Hook | Values |
|---|---|
| Class | cherry-grid |
| Parts | cherry-col |
Columns are repeat(n, minmax(0, 1fr)). The default gap reads --cherry-gutter-mobile and --cherry-gutter-desktop; spacing steps map to --cherry-space-<step>.
Accessibility
Grid is layout only and has no role. Keep the DOM order the reading order.