SimpleGrid
If you're like me, you probably tend to check the MDN docs for anything CSS grid.
SimpleGrid provides a friendly interface to create responsive grid layouts with
ease. It renders a div
element with display: grid
.
Import#
import { SimpleGrid } from "@chakra-ui/react"
Usage#
Specifying the number of columns for the grid layout.
You can also make it responsive by passing array or object values into the
columns
prop.
Auto-responsive grid#
To make the grid responsive and adjust automatically without passing columns
,
simply pass the minChildWidth
prop to specify the min-width
a child should
have before adjusting the layout.
This uses css grid auto-fit
and minmax()
internally.
Changing the spacing for columns and rows#
Simply pass the spacing
prop to change the row and column spacing between the
grid items. SimpleGrid
also allows you pass spacingX
and spacingY
to
define the space between columns and rows respectively.
Props#
SimpleGrid composes Box
so you can pass all the Box
props and css grid props
with addition of these:
Name | Type | Description | Default |
---|---|---|---|
area | SystemProps["gridArea"] | Short hand prop for `gridArea` | - |
autoColumns | SystemProps["gridAutoColumns"] | Short hand prop for `gridAutoColumns` | - |
autoFlow | SystemProps["gridAutoFlow"] | Short hand prop for `gridAutoFlow` | - |
autoRows | SystemProps["gridAutoRows"] | Short hand prop for `gridAutoRows` | - |
column | SystemProps["gridColumn"] | Short hand prop for `gridColumn` | - |
columnGap | SystemProps["gridColumnGap"] | Short hand prop for `gridColumnGap` | - |
columns | number | ResponsiveArray<number> | ResponsiveObject<number> | The number of columns | - |
gap | SystemProps["gridGap"] | Short hand prop for `gridGap` | - |
minChildWidth | string | number | (string & {}) | ResponsiveArray<Padding<ReactText>> | ResponsiveObject<Padding<ReactText>> | The width at which child elements will break into columns. Pass a number for pixel values or a string for any other valid CSS length. | - |
row | SystemProps["gridRow"] | Short hand prop for `gridRow` | - |
rowGap | SystemProps["gridRowGap"] | Short hand prop for `gridRowGap` | - |
spacing | string | number | (string & {}) | ResponsiveArray<Padding<ReactText>> | ResponsiveObject<Padding<ReactText>> | The gap between the grid items | - |
spacingX | string | number | (string & {}) | ResponsiveArray<Padding<ReactText>> | ResponsiveObject<Padding<ReactText>> | The column gap between the grid items | - |
spacingY | string | number | (string & {}) | ResponsiveArray<Padding<ReactText>> | ResponsiveObject<Padding<ReactText>> | The row gap between the grid items | - |
templateAreas | SystemProps["gridTemplateAreas"] | Short hand prop for `gridTemplateAreas` | - |
templateColumns | SystemProps["gridTemplateColumns"] | Short hand prop for `gridTemplateColumns` | - |
templateRows | SystemProps["gridTemplateRows"] | Short hand prop for `gridTemplateRows` | - |