Component for creating bidimensional grid layouts.
Component for creating bidimensional grid layouts.
| Prop | Type | Default | Description |
|---|---|---|---|
| inline | boolean | false | Whether the grid is inline or not. |
| cols | "number" | 1 | The number of columns. |
| rows | "number" | 1 | The number of rows. |
| justify | 'start' | 'center' | 'end' | 'between' | 'start' | The horizontal alignment of the grid. |
| align | 'start' | 'center' | 'end' | 'stretch' | 'start' | The vertical alignment of the grid. |
| gapX | 0 to 20 | 0 | The horizontal gap between the grid items. |
| gapY | 0 to 20 | 0 | The vertical gap between the grid items. |
If you set inline, justify has no meaning because the <Grid /> has the least width possible.
Setting align, only has meaning if the <Grid /> has a height. Otherwise it will have the least height possible.
If you set justify="stretch", the children shouldn't have a fixed width. Otherwise they won't stretch.
If you set align="stretch", the children shouldn't have a fixed height. Otherwise they won't stretch.
Setting justify="stretch" has the same effect as setting w-full on all the children (assuming flow="row").
Setting align="stretch" has the same effect as setting h-full on all the children (assuming flow="row").
Changing visual order creates a disconnect between content and presentation and is, therefore, bad for accessibility. For this reason, I've ommitted grid-auto-flow:row dense and grid-auto-flow: column dense.
<Grid cols="3" rows="3" justify="stretch" align="stretch" gapX="6" gapY="6" className="mt-4 h-96 rounded-md bg-slate-200 p-4"> <div className="flex items-center justify-center rounded-sm bg-slate-600 text-white">1</div> <div className="flex items-center justify-center rounded-sm bg-slate-600 text-white">2</div> <div className="flex items-center justify-center rounded-sm bg-slate-600 text-white">3</div> <div className="flex items-center justify-center rounded-sm bg-slate-600 text-white">4</div> <div className="flex items-center justify-center rounded-sm bg-slate-600 text-white">5</div> <div className="flex items-center justify-center rounded-sm bg-slate-600 text-white">6</div> <div className="flex items-center justify-center rounded-sm bg-slate-600 text-white">7</div> <div className="flex items-center justify-center rounded-sm bg-slate-600 text-white">8</div> <div className="flex items-center justify-center rounded-sm bg-slate-600 text-white">9</div></Grid><Grid cols="3" rows="3" justify="start" align="start" gapX="6" gapY="6" className="mt-4 h-96 rounded-md bg-slate-200 p-4"> <div className="flex h-10 w-10 items-center justify-center rounded-sm bg-slate-600 text-white">1</div> <div className="flex h-10 w-10 items-center justify-center rounded-sm bg-slate-600 text-white">2</div> <div className="flex h-10 w-10 items-center justify-center rounded-sm bg-slate-600 text-white">3</div> <div className="flex h-10 w-10 items-center justify-center rounded-sm bg-slate-600 text-white">4</div> <div className="flex h-10 w-10 items-center justify-center rounded-sm bg-slate-600 text-white">5</div> <div className="flex h-10 w-10 items-center justify-center rounded-sm bg-slate-600 text-white">6</div> <div className="flex h-10 w-10 items-center justify-center rounded-sm bg-slate-600 text-white">7</div> <div className="flex h-10 w-10 items-center justify-center rounded-sm bg-slate-600 text-white">8</div> <div className="flex h-10 w-10 items-center justify-center rounded-sm bg-slate-600 text-white">9</div></Grid><Grid cols="3" rows="3" justify="center" align="start" gapX="6" gapY="6" className="mt-4 h-96 rounded-md bg-slate-200 p-4"> <div className="flex h-10 w-10 items-center justify-center rounded-sm bg-slate-600 text-white">1</div> <div className="flex h-10 w-10 items-center justify-center rounded-sm bg-slate-600 text-white">2</div> <div className="flex h-10 w-10 items-center justify-center rounded-sm bg-slate-600 text-white">3</div> <div className="flex h-10 w-10 items-center justify-center rounded-sm bg-slate-600 text-white">4</div> <div className="flex h-10 w-10 items-center justify-center rounded-sm bg-slate-600 text-white">5</div> <div className="flex h-10 w-10 items-center justify-center rounded-sm bg-slate-600 text-white">6</div> <div className="flex h-10 w-10 items-center justify-center rounded-sm bg-slate-600 text-white">7</div> <div className="flex h-10 w-10 items-center justify-center rounded-sm bg-slate-600 text-white">8</div> <div className="flex h-10 w-10 items-center justify-center rounded-sm bg-slate-600 text-white">9</div></Grid><Grid cols="3" rows="3" justify="end" align="start" gapX="6" gapY="6" className="mt-4 h-96 rounded-md bg-slate-200 p-4"> <div className="flex h-10 w-10 items-center justify-center rounded-sm bg-slate-600 text-white">1</div> <div className="flex h-10 w-10 items-center justify-center rounded-sm bg-slate-600 text-white">2</div> <div className="flex h-10 w-10 items-center justify-center rounded-sm bg-slate-600 text-white">3</div> <div className="flex h-10 w-10 items-center justify-center rounded-sm bg-slate-600 text-white">4</div> <div className="flex h-10 w-10 items-center justify-center rounded-sm bg-slate-600 text-white">5</div> <div className="flex h-10 w-10 items-center justify-center rounded-sm bg-slate-600 text-white">6</div> <div className="flex h-10 w-10 items-center justify-center rounded-sm bg-slate-600 text-white">7</div> <div className="flex h-10 w-10 items-center justify-center rounded-sm bg-slate-600 text-white">8</div> <div className="flex h-10 w-10 items-center justify-center rounded-sm bg-slate-600 text-white">9</div></Grid><Grid cols="3" rows="3" justify="start" align="center" gapX="6" gapY="6" className="mt-4 h-96 rounded-md bg-slate-200 p-4"> <div className="flex h-10 w-10 items-center justify-center rounded-sm bg-slate-600 text-white">1</div> <div className="flex h-10 w-10 items-center justify-center rounded-sm bg-slate-600 text-white">2</div> <div className="flex h-10 w-10 items-center justify-center rounded-sm bg-slate-600 text-white">3</div> <div className="flex h-10 w-10 items-center justify-center rounded-sm bg-slate-600 text-white">4</div> <div className="flex h-10 w-10 items-center justify-center rounded-sm bg-slate-600 text-white">5</div> <div className="flex h-10 w-10 items-center justify-center rounded-sm bg-slate-600 text-white">6</div> <div className="flex h-10 w-10 items-center justify-center rounded-sm bg-slate-600 text-white">7</div> <div className="flex h-10 w-10 items-center justify-center rounded-sm bg-slate-600 text-white">8</div> <div className="flex h-10 w-10 items-center justify-center rounded-sm bg-slate-600 text-white">9</div></Grid><Grid cols="3" rows="3" justify="center" align="center" gapX="6" gapY="6" className="mt-4 h-96 rounded-md bg-slate-200 p-4"> <div className="flex h-10 w-10 items-center justify-center rounded-sm bg-slate-600 text-white">1</div> <div className="flex h-10 w-10 items-center justify-center rounded-sm bg-slate-600 text-white">2</div> <div className="flex h-10 w-10 items-center justify-center rounded-sm bg-slate-600 text-white">3</div> <div className="flex h-10 w-10 items-center justify-center rounded-sm bg-slate-600 text-white">4</div> <div className="flex h-10 w-10 items-center justify-center rounded-sm bg-slate-600 text-white">5</div> <div className="flex h-10 w-10 items-center justify-center rounded-sm bg-slate-600 text-white">6</div> <div className="flex h-10 w-10 items-center justify-center rounded-sm bg-slate-600 text-white">7</div> <div className="flex h-10 w-10 items-center justify-center rounded-sm bg-slate-600 text-white">8</div> <div className="flex h-10 w-10 items-center justify-center rounded-sm bg-slate-600 text-white">9</div></Grid><Grid cols="3" rows="3" justify="end" align="center" gapX="6" gapY="6" className="mt-4 h-96 rounded-md bg-slate-200 p-4"> <div className="flex h-10 w-10 items-center justify-center rounded-sm bg-slate-600 text-white">1</div> <div className="flex h-10 w-10 items-center justify-center rounded-sm bg-slate-600 text-white">2</div> <div className="flex h-10 w-10 items-center justify-center rounded-sm bg-slate-600 text-white">3</div> <div className="flex h-10 w-10 items-center justify-center rounded-sm bg-slate-600 text-white">4</div> <div className="flex h-10 w-10 items-center justify-center rounded-sm bg-slate-600 text-white">5</div> <div className="flex h-10 w-10 items-center justify-center rounded-sm bg-slate-600 text-white">6</div> <div className="flex h-10 w-10 items-center justify-center rounded-sm bg-slate-600 text-white">7</div> <div className="flex h-10 w-10 items-center justify-center rounded-sm bg-slate-600 text-white">8</div> <div className="flex h-10 w-10 items-center justify-center rounded-sm bg-slate-600 text-white">9</div></Grid><Grid cols="3" rows="3" justify="start" align="end" gapX="6" gapY="6" className="mt-4 h-96 rounded-md bg-slate-200 p-4"> <div className="flex h-10 w-10 items-center justify-center rounded-sm bg-slate-600 text-white">1</div> <div className="flex h-10 w-10 items-center justify-center rounded-sm bg-slate-600 text-white">2</div> <div className="flex h-10 w-10 items-center justify-center rounded-sm bg-slate-600 text-white">3</div> <div className="flex h-10 w-10 items-center justify-center rounded-sm bg-slate-600 text-white">4</div> <div className="flex h-10 w-10 items-center justify-center rounded-sm bg-slate-600 text-white">5</div> <div className="flex h-10 w-10 items-center justify-center rounded-sm bg-slate-600 text-white">6</div> <div className="flex h-10 w-10 items-center justify-center rounded-sm bg-slate-600 text-white">7</div> <div className="flex h-10 w-10 items-center justify-center rounded-sm bg-slate-600 text-white">8</div> <div className="flex h-10 w-10 items-center justify-center rounded-sm bg-slate-600 text-white">9</div></Grid><Grid cols="3" rows="3" justify="center" align="end" gapX="6" gapY="6" className="mt-4 h-96 rounded-md bg-slate-200 p-4"> <div className="flex h-10 w-10 items-center justify-center rounded-sm bg-slate-600 text-white">1</div> <div className="flex h-10 w-10 items-center justify-center rounded-sm bg-slate-600 text-white">2</div> <div className="flex h-10 w-10 items-center justify-center rounded-sm bg-slate-600 text-white">3</div> <div className="flex h-10 w-10 items-center justify-center rounded-sm bg-slate-600 text-white">4</div> <div className="flex h-10 w-10 items-center justify-center rounded-sm bg-slate-600 text-white">5</div> <div className="flex h-10 w-10 items-center justify-center rounded-sm bg-slate-600 text-white">6</div> <div className="flex h-10 w-10 items-center justify-center rounded-sm bg-slate-600 text-white">7</div> <div className="flex h-10 w-10 items-center justify-center rounded-sm bg-slate-600 text-white">8</div> <div className="flex h-10 w-10 items-center justify-center rounded-sm bg-slate-600 text-white">9</div></Grid><Grid cols="3" rows="3" justify="end" align="end" gapX="6" gapY="6" className="mt-4 h-96 rounded-md bg-slate-200 p-4"> <div className="flex h-10 w-10 items-center justify-center rounded-sm bg-slate-600 text-white">1</div> <div className="flex h-10 w-10 items-center justify-center rounded-sm bg-slate-600 text-white">2</div> <div className="flex h-10 w-10 items-center justify-center rounded-sm bg-slate-600 text-white">3</div> <div className="flex h-10 w-10 items-center justify-center rounded-sm bg-slate-600 text-white">4</div> <div className="flex h-10 w-10 items-center justify-center rounded-sm bg-slate-600 text-white">5</div> <div className="flex h-10 w-10 items-center justify-center rounded-sm bg-slate-600 text-white">6</div> <div className="flex h-10 w-10 items-center justify-center rounded-sm bg-slate-600 text-white">7</div> <div className="flex h-10 w-10 items-center justify-center rounded-sm bg-slate-600 text-white">8</div> <div className="flex h-10 w-10 items-center justify-center rounded-sm bg-slate-600 text-white">9</div></Grid>Here's the <Grid /> component in action.