A utility component for building CSS grid layouts.

Importing

The component can be imported via:

import { Grid } from '@customerio/pluma-components/react';
<Grid columns={2} gap="200">
  <Box backgroundColor="information" p="200" />
  <Box backgroundColor="information" p="200" />
  <Box backgroundColor="information" p="200" />
  <Box backgroundColor="information" p="200" />
  <Box backgroundColor="information" p="200" />
</Grid>

Columns

The columns prop accepts a number, string, or array of strings.

If the value is a number, the grid will have that many equal columns. If the value is a string, it will be set as the CSS grid-template-columns property, which defines the number and sizes of columns. If a string array is provided, it will also be used for grid-template-columns, with the values joined by a space (e.g. ['1fr', 'auto'] becomes 1fr auto).

<Grid columns={3} gap="200">
  {[...Array(10)].map((_, index) => (
    <Box key={index} backgroundColor="information" p="200" />
  ))}
</Grid>
<Grid columns="1fr auto 2fr" gap="200">
  {[...Array(10)].map((_, index) => (
    <Box key={index} backgroundColor="information" p="200" />
  ))}
</Grid>

Gap

The gap between items can be controlled with the gap prop, which accepts space token values. rowGap and columnGap are also available for more fine-grained control of the gaps.

<Grid columns={3} gap="400">
  {[...Array(10)].map((_, index) => (
    <Box key={index} backgroundColor="information" p="200" />
  ))}
</Grid>
<Grid columns={3} columnGap="100" rowGap="300">
  {[...Array(10)].map((_, index) => (
    <Box key={index} backgroundColor="information" p="200" />
  ))}
</Grid>

Areas

grid-template-areas can be set via the areas prop. It accepts a string, or an array of strings, which will be mapped into one string (e.g. ["header header", "nav main", "footer footer"] turns into "header header" "nav main" "footer footer").

<Grid areas={['a a', 'b c', 'd d']} gap="200">
  <Box 
    backgroundColor="information"
    p="200" 
    style={{ gridArea: 'a' }}
  />
  <Box 
    backgroundColor="success"
    p="200" 
    style={{ gridArea: 'b' }}
  />
  <Box 
    backgroundColor="caution"
    p="200" 
    style={{ gridArea: 'c' }}
  />
  <Box 
    backgroundColor="critical"
    p="200" 
    style={{ gridArea: 'd' }}
  />
</Grid>

API

PlumaGrid extends Box

grid-template-areas definitions for the grid.

grid-template-columns definitions for the grid, or number of columns.

Default:grid

The display property.

Defines default justifySelf for all items in the grid. MDN Justify Items

grid-template-rows definitions for the grid.

On this page