Grid
The Grid component is a layout component that allows you to create a responsive grid layout. It uses a flexbox based layout system to create a grid of columns and rows.
Component
Basic Usage
Use the Grid component to create a container and nested items. Here’s an example of a basic grid layout:
In this example, each Grid item takes up the full width on extra-small devices (xs=12) and half width on small devices (sm=6), eventually becoming a quarter of the width on medium-sized devices and larger (md=3).
Responsive Layout
The Grid system is responsive, adapting to various screen sizes using the props xs, sm, md, and lg. These props define how many columns the item should span at different breakpoints.
Aligning Items
Control the alignment of items within the container using verticalAlign and horizontalAlign props. For example:
Gap Handling
Define the space between grid items using gap, columnGap, and rowGap props. For instance:
This sets a uniform gap between grid items.
You can also use columnGap
and rowGap
to define the space between columns and rows, respectively.
Auto column sizing
You can use the auto
size prop to make a column automatically take up the remaining space. For example:
Nested Grids
You can nest Grid components to create complex layouts. For example:
Props
The Grid
component has the following props.
Name | Type | Default | Description |
---|---|---|---|
container | boolean | false | Defines a row in the grid |
gap | OptionalSizeProp | - | Defines the gap between columns and rows |
columnGap | OptionalSizeProp | - | Defines the gap between columns |
rowGap | OptionalSizeProp | - | Defines the gap between rows |
xs | 1-12 | ‘auto’ | - | Defines the column size for mobile devices and larger |
sm | 1-12 | ‘auto’ | - | Overrides the column size for Tablet devices and larger |
md | 1-12 | ‘auto’ | - | Overrides the column size for Small Desktop devices and larger |
lg | 1-12 | ‘auto’ | - | Overrides the column size for Large Desktop devices and larger |
verticalAlign | ”flex-start” | “center” | “flex-end" | "flex-start” | Defines how the content will be placed vertically within the column |
horizontallyAlign | ”left” | “center” | “right" | "left” | Defines how the content will be placed horizontally within the column |
class | string | - | Override or extend the styles applied to the component. |