Grid
CSS Grid as a Box — tokenized columns, rows, gaps and alignment, with Grid.Item for placement.
1
2
3
4
5
6
import { Grid, Center, Text } from "astralis-ui";
export function GridDemo() {
return (
<Grid columns="3" gap="3" w="full" maxW="md">
{[1, 2, 3, 4, 5, 6].map((n) => (
<Center key={n} bg="brand-subtle" p="4" rounded="lg">
<Text size="sm">{n}</Text>
</Center>
))}
</Grid>
);
}Import#
import { Grid } from "astralis-ui";
// Grid.Item is available on the component itselfSpanning#
Grid.Item places children explicitly: colSpan/rowSpan for size,
colStart/rowStart for position — the dashboard staples.
2 × 2
2 × 1
1
1
"use client";
import { Grid, Center, Text } from "astralis-ui";
export function GridSpan() {
return (
<Grid columns="4" rows="2" gap="3" w="full" maxW="md">
<Grid.Item colSpan="2" rowSpan="2">
<Center bg="orange-solid" rounded="lg" size="full" minH="24">
<Text size="sm" color="inverted">2 × 2</Text>
</Center>
</Grid.Item>
<Grid.Item colSpan="2">
<Center bg="orange-muted" rounded="lg" p="4">
<Text size="sm">2 × 1</Text>
</Center>
</Grid.Item>
<Center bg="orange-subtle" rounded="lg" p="4">
<Text size="sm">1</Text>
</Center>
<Center bg="orange-subtle" rounded="lg" p="4">
<Text size="sm">1</Text>
</Center>
</Grid>
);
}Responsive columns#
columns (like every layout prop) accepts a breakpoint map — the standard
card-grid recipe.
Mercury
Venus
Earth
Mars
Jupiter
Saturn
import { Grid, Center, Text } from "astralis-ui";
export function GridResponsive() {
return (
/* 1 column on mobile, 2 from md, 3 from lg. */
<Grid columns={{ base: "1", md: "2", lg: "3" }} gap="3" w="full" maxW="md">
{["Mercury", "Venus", "Earth", "Mars", "Jupiter", "Saturn"].map((planet) => (
<Center key={planet} bg="blue-subtle" p="4" rounded="lg">
<Text size="sm">{planet}</Text>
</Center>
))}
</Grid>
);
}Named template areas#
For genuinely custom layouts, templateAreas, templateColumns and
templateRows accept raw CSS strings (applied as inline styles), and
Grid.Item area snaps children to the named cells.
header
sidebar
main
footer
"use client";
import { Grid, Center, Text } from "astralis-ui";
export function GridTemplate() {
return (
/* templateAreas + Grid.Item area — the escape hatch for named layouts. */
<Grid
templateAreas={`"header header" "sidebar main" "footer footer"`}
templateColumns="8rem 1fr"
gap="3"
w="full"
maxW="md"
>
<Grid.Item area="header">
<Center bg="green-solid" p="3" rounded="lg">
<Text size="xs" color="inverted">header</Text>
</Center>
</Grid.Item>
<Grid.Item area="sidebar">
<Center bg="green-muted" p="3" rounded="lg" size="full" minH="20">
<Text size="xs">sidebar</Text>
</Center>
</Grid.Item>
<Grid.Item area="main">
<Center bg="green-subtle" p="3" rounded="lg" size="full">
<Text size="xs">main</Text>
</Center>
</Grid.Item>
<Grid.Item area="footer">
<Center bg="green-muted" p="3" rounded="lg">
<Text size="xs">footer</Text>
</Center>
</Grid.Item>
</Grid>
);
}Props#
Grid extends Box, so every style prop works here too.
| Prop | Type | Default | Description |
|---|---|---|---|
columns | "1" – "12" | "none" | — | Number of equal columns. |
rows | "1" – "6" | "none" | — | Number of equal rows. |
gap · rowGap · columnGap | "0.5" – "96" (spacing scale) | — | Track gaps, together or per axis. |
flow | "row" | "col" | "dense" | "col-dense" | "row" | Auto-placement direction. |
autoColumns · autoRows | "auto" | "min" | "max" | "fr" | — | Sizing for implicitly created tracks. |
justifyItems · alignItems · placeItems | "start" | "center" | "end" | "stretch" (+ "baseline" for alignItems) | — | Item alignment within their cells. |
justifyContent · alignContent · placeContent | "start" | "center" | "end" | "between" | "around" | "evenly" | "stretch" | — | Track alignment within the container. |
templateColumns · templateRows · templateAreas | string | — | Escape hatches — arbitrary track/area templates, applied as inline styles. |
Grid.Item#
| Prop | Type | Default | Description |
|---|---|---|---|
colSpan · rowSpan | "1" – "12" | "full" | — | How many tracks the item spans. |
colStart/colEnd · rowStart/rowEnd | "1" – "13" | "auto" | — | Explicit grid-line placement. |
area | string | — | Named area matching the container's templateAreas. |
order | "1" – "12" | "first" | "last" | "none" | — | Visual order, independent of source order. |
alignSelf · justifySelf · placeSelf | "auto" | "start" | "end" | "center" | "stretch" | — | Per-item alignment override. |