Grid Component
A layout component that uses CSS Grid for two-dimensional layouts with configurable columns, rows, gap, flow, justification, and alignment.import { Grid } from "@locus-ui/components";
<Grid columns="3" gap="4" align="center"> <Box px="2" py="1" className="border">Item 1</Box> <Box px="2" py="1" className="border">Item 2</Box> <Box px="2" py="1" className="border">Item 3</Box></Grid>Anatomy
Import the component:Anatomy
import { Grid } from "@locus-ui/components";
<Grid />Examples
Gaps
Thegap prop controls the spacing between grid items using predefined scale values 0 through 8.
0
1
2
3
4
5
6
7
8
gaps.tsx
import { Grid } from "@locus-ui/components";
const gaps = ["0", "1", "2", "3", "4", "5", "6", "7", "8"];
return gaps.map((gap) => ( <Box key={gap} px="2" py="1"> <Text>{gap}</Text> <Grid columns="2" gap={gap}> <Box px="2" py="1" className="border">Item 1</Box> <Box px="2" py="1" className="border">Item 2</Box> </Grid> </Box>Columns
Thecolumns prop sets the number of grid columns: 1 through 12.
1
2
3
4
5
6
columns.tsx
import { Grid } from "@locus-ui/components";
const columns = ["1", "2", "3", "4", "5", "6"];
return columns.map((col) => ( <Box key={col} px="2" py="1"> <Text>{col}</Text> <Grid columns={col} gap="2"> {Array.from({ length: Number(col) }).map((_, i) => ( <Box key={i} px="2" py="1" className="border">Item {i + 1}</Box> ))} </Grid>Rows
Therows prop sets the number of grid rows: 1 through 6.
1
2
3
4
5
6
rows.tsx
import { Grid } from "@locus-ui/components";
const rows = ["1", "2", "3", "4", "5", "6"];
return rows.map((row) => ( <Box key={row} px="2" py="1"> <Text>{row}</Text> <Grid rows={row} flow="column" gap="2"> {Array.from({ length: Number(row) }).map((_, i) => ( <Box key={i} px="2" py="1" className="border">Item {i + 1}</Box> ))} </Grid>Flow
Theflow prop controls the auto-placement direction: row, column, dense, row-dense, or column-dense.
row
column
dense
row-dense
column-dense
flow.tsx
import { Grid } from "@locus-ui/components";
const flows = ["row", "column", "dense", "row-dense", "column-dense"];
return flows.map((flow) => ( <Box key={flow} px="2" py="1"> <Text>{flow}</Text> <Grid columns="3" rows="2" flow={flow} gap="2"> <Box px="2" py="1" className="border col-span-2">Item 1</Box> <Box px="2" py="1" className="border col-span-2">Item 2</Box> <Box px="2" py="1" className="border">Item 3</Box> <Box px="2" py="1" className="border">Item 4</Box>Justify
Thejustify prop controls the inline-axis alignment: start, end, center, between, around, or evenly.
start
end
center
between
around
evenly
justify.tsx
import { Grid } from "@locus-ui/components";
const justifies = ["start", "end", "center", "between", "around", "evenly"];
return justifies.map((justify) => ( <Box key={justify} px="2" py="1" className="w-full"> <Text>{justify}</Text> <Grid justify={justify} gap="2" style={{ gridTemplateColumns: "auto auto" }}> <Box px="2" py="1" className="border">Item 1</Box> <Box px="2" py="1" className="border">Item 2</Box> </Grid> </Box>Align
Thealign prop controls the block-axis alignment: start, end, center, stretch, or baseline.
start
end
center
stretch
baseline
align.tsx
import { Grid } from "@locus-ui/components";
const aligns = ["start", "end", "center", "stretch", "baseline"];
return aligns.map((align) => ( <Box key={align} px="2" py="1"> <Text>{align}</Text> <Grid columns="2" align={align} gap="2" style={{ height: "100px" }}> <Box px="2" py="1" className="border">Item 1</Box> <Box px="2" py="1" className="border">Item 2</Box> </Grid> </Box>