Grid
WARNING
Experimental
The grid is used to create specific layouts within an application’s content. It contains 5 types of media breakpoints that are used for targeting specific screen sizes or orientations:sm
, md
, lg
and xl
.
Components
VRow
The VRow
component is a flexible row container that provides options for controlling the gap between items, alignment, and justification within the row.
VCol
The VCol
component is a flexible column container that allows you to control the column width, offset, and order at different breakpoints.
Usage
The grid components is heavily inspired by the Bootstrap and Vuetify grid . It is implemented by using a series of containers, rows, and columns to layout and align content. If you are new to flexbox, read the CSS Tricks flexbox guide for background, terminology, guidelines, and code snippets.
Column
The VCol
component allows you to define the size of a column using the cols
prop. You can specify the width of the column by providing a number between 1
and 12
or by using the value auto
to let the column adjust its width based on the content.
In this example, we create a row with three columns. The first column has a width of 1, the second column has a width of 3, and the third column has a width of 8.
Offset
You can offset a column within a row using the offset
prop. This allows you to create empty space before a column, pushing it to the right.
In this example, we create a row with three columns. The third column has an offset of 3, which means it will be pushed 3 units to the right, creating empty space before it.
Order
The order
prop allows you to control the order of columns within a row. By default, columns are displayed in the order they appear in the markup. However, you can use the order
prop to override the default order and rearrange the columns as needed.
In this example, we create a row with three columns. The first column has an order of 2, the second column has an order of 3, and the third column has an order of 1. As a result, the columns will be displayed in the order 3, 1, 2.
Alignment
The VRow
component allows you to control the alignment of its child columns using the align
, alignContent
, and justifyContent
props.
In this example, we create a row with three columns. The align
prop controls the alignment of the items within each column, the alignContent
prop controls the alignment of the row's content, and the justifyContent
prop controls the justification of the row's content.
Responsive
The VCol
component supports responsiveness by allowing you to set different column widths for different breakpoints. You can use the sm
, md
, lg
, and xl
props to specify the column widths for small, medium, large, and extra-large screens, respectively.
In this example, we create a row with three columns. On extra-large screens (xl breakpoint), each column occupies 4 units of the available width. On large screens (lg breakpoint), each column occupies 4 units of the available width. On small screens (sm breakpoint) and below, each column occupies 3 units of the available width.
Breakpoints
Breakpoints | Max Width | Device |
---|---|---|
sm | >= 360px | Mobile |
md | >= 640px | Tablet |
lg | >= 768px | Tablet |
xl | >= 834px | Tablet |
2xl | >= 1024px | Tablet |
3xl | >= 1440px | Desktop |
Props
VRow
Prop | Type | Default | Description |
---|---|---|---|
gap | string | number | - | Sets the gap between items in the row. |
gapSm | string | number | - | Sets the gap between items in the row for small screens (sm breakpoint). |
gapMd | string | number | - | Sets the gap between items in the row for medium screens (md breakpoint). |
gapLg | string | number | - | Sets the gap between items in the row for large screens (lg breakpoint). |
gapXl | string | number | - | Sets the gap between items in the row for extra-large screens (xl breakpoint). |
align | string | - | Sets the alignment of items within the row. |
alignContent | string | - | Sets the alignment of the entire row content. |
justifyContent | string | - | Sets the justification of items within the row. |
alignSm | string | - | Sets the alignment of items within the row for small screens (sm breakpoint). |
alignContentSm | string | - | Sets the alignment of the entire row content for small screens (sm breakpoint). |
justifyContentSm | string | - | Sets the justification of items within the row for small screens (sm breakpoint). |
alignMd | string | - | Sets the alignment of items within the row for medium screens (md breakpoint). |
alignContentMd | string | - | Sets the alignment of the entire row content for medium screens (md breakpoint). |
justifyContentMd | string | - | Sets the justification of items within the row for medium screens (md breakpoint). |
alignLg | string | - | Sets the alignment of items within the row for large screens (lg breakpoint). |
alignContentLg | string | - | Sets the alignment of the entire row content for large screens (lg breakpoint). |
justifyContentLg | string | - | Sets the justification of items within the row for large screens (lg breakpoint). |
alignXl | string | - | Sets the alignment of items within the row for extra-large screens (xl breakpoint). |
alignContentXl | string | - | Sets the alignment of the entire row content for extra-large screens (xl breakpoint). |
justifyContentXl | string | - | Sets the justification of items within the row for extra-large screens (xl breakpoint). |
VCol
Prop | Type | Default | Description |
---|---|---|---|
cols | "auto" | string | number | "auto" | Sets the width of the column. |
offset | string | number | - | Sets the offset of the column. |
order | string | number | - | Sets the order of the column. |
sm | "auto" | string | number | - | Sets the width of the column for small screens (sm breakpoint). |
md | "auto" | string | number | - | Sets the width of the column for medium screens (md breakpoint). |
lg | "auto" | string | number | - | Sets the width of the column for large screens (lg breakpoint). |
xl | "auto" | string | number | - | Sets the width of the column for extra-large screens (xl breakpoint). |
offsetSm | string | number | - | Sets the offset of the column for small screens (sm breakpoint). |
offsetMd | string | number | - | Sets the offset of the column for medium screens (md breakpoint). |
offsetLg | string | number | - | Sets the offset of the column for large screens (lg breakpoint). |
offsetXl | string | number | - | Sets the offset of the column for extra-large screens (xl breakpoint). |
orderSm | string | number | - | Sets the order of the column for small screens (sm breakpoint). |
orderMd | string | number | - | Sets the order of the column for medium screens (md breakpoint). |
orderLg | string | number | - | Sets the order of the column for large screens (lg breakpoint). |
orderXl | string | number | - | Sets the order of the column for extra-large screens (xl breakpoint). |
Standalone Installation
You can also install the grid component individually via @morpheme/layouts
package:
npm i @morpheme/layouts
npm i @morpheme/layouts
Storybook
View Storybook documentation here.