Grid
Grid is a component for managing grid layouts. It also comes with handy style shorthand.
Import
import { Grid, GridItem } from "@yamada-ui/react"
The shorthand available for Grid is as follows:
templateColumns: This is a shorthandpropsforgridTemplateColumns.templateRows: This is a shorthandpropsforgridTemplateRows.templateAreas: This is a shorthandpropsforgridTemplateAreas.column: This is a shorthandpropsforgridColumn.row: This is a shorthandpropsforgridRow.area: This is a shorthandpropsforgridArea.autoFlow: This is a shorthandpropsforgridAutoFlow.autoColumns: This is a shorthandpropsforgridAutoColumns.autoRows: This is a shorthandpropsforgridAutoRows.
The shorthand available for GridItem is as follows:
area: This is a shorthandpropsforgridArea.colStart: This is a shorthandpropsforgridColumnStart.colEnd: This is a shorthandpropsforgridColumnEnd.rowStart: This is a shorthandpropsforgridRowStart.rowEnd: This is a shorthandpropsforgridRowEnd.
In addition to the shorthand, you can also pass verbose props.
Usage
Editable example
<Grid templateColumns="repeat(4, 1fr)" gap="md"> <For each={["primary", "secondary", "warning", "danger"]}> {(bg, index) => ( <GridItem key={index} w="full" h="4xs" rounded="md" bg={bg} /> )} </For> </Grid>
Using templateAreas
Editable example
<Grid templateAreas={` "one one two three" "four five two six" "four seven seven eight" `} gap="md" > <For each={[ { area: "one", bg: "primary" }, { area: "two", bg: "secondary" }, { area: "three", bg: "warning" }, { area: "four", bg: "danger" }, { area: "five", bg: "primary" }, { area: "six", bg: "secondary" }, { area: "seven", bg: "warning" }, { area: "eight", bg: "danger" }, ]} > {({ area, bg }, index) => ( <GridItem key={index} area={area} w="full" minH="4xs" rounded="md" bg={bg} /> )} </For> </Grid>
Spanning Multiple Columns and Rows
Editable example
<Grid w="full" templateColumns="repeat(4, 1fr)" templateRows="repeat(3, 1fr)" gap="md" > <GridItem colSpan={2} w="full" minH="4xs" rounded="md" bg="primary" /> <GridItem colSpan={2} rowSpan={3} w="full" minH="4xs" rounded="md" bg="secondary" /> <GridItem rowStart={2} rowEnd={4} w="full" minH="4xs" rounded="md" bg="warning" /> <GridItem colStart={2} colEnd={3} rowStart={2} rowEnd={4} w="full" minH="4xs" rounded="md" bg="danger" /> </Grid>
Edit this page on GitHub

