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"> <GridItem w="full" h="4xs" rounded="md" bg="primary" /> <GridItem w="full" h="4xs" rounded="md" bg="secondary" /> <GridItem w="full" h="4xs" rounded="md" bg="warning" /> <GridItem w="full" h="4xs" rounded="md" bg="danger" /> </Grid>
Using templateAreas
Editable example
<Grid templateAreas={` "one one two three" "four five two six" "four seven seven eight" `} gap="md" > <GridItem area="one" w="full" minH="4xs" rounded="md" bg="primary" /> <GridItem area="two" w="full" minH="4xs" rounded="md" bg="secondary" /> <GridItem area="three" w="full" minH="4xs" rounded="md" bg="warning" /> <GridItem area="four" w="full" minH="4xs" rounded="md" bg="danger" /> <GridItem area="five" w="full" minH="4xs" rounded="md" bg="primary" /> <GridItem area="six" w="full" minH="4xs" rounded="md" bg="secondary" /> <GridItem area="seven" w="full" minH="4xs" rounded="md" bg="warning" /> <GridItem area="eight" w="full" minH="4xs" rounded="md" bg="danger" /> </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