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 shorthandprops
forgridTemplateColumns
.templateRows
: This is a shorthandprops
forgridTemplateRows
.templateAreas
: This is a shorthandprops
forgridTemplateAreas
.column
: This is a shorthandprops
forgridColumn
.row
: This is a shorthandprops
forgridRow
.area
: This is a shorthandprops
forgridArea
.autoFlow
: This is a shorthandprops
forgridAutoFlow
.autoColumns
: This is a shorthandprops
forgridAutoColumns
.autoRows
: This is a shorthandprops
forgridAutoRows
.
The shorthand available for GridItem
is as follows:
area
: This is a shorthandprops
forgridArea
.colStart
: This is a shorthandprops
forgridColumnStart
.colEnd
: This is a shorthandprops
forgridColumnEnd
.rowStart
: This is a shorthandprops
forgridRowStart
.rowEnd
: This is a shorthandprops
forgridRowEnd
.
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