Skip to Content

Grid

Responsive grid layout component that steps from one column up to six by the width of its own wrapper rather than the viewport, with shared gap sizes from xs to xl. The base for most editorial and card groups.

Installation

pnpm dlx shadcn@latest add @01orbital/grid

Usage

import { Grid } from "@/components/grid/grid"

// One tile per palette: its name and the two colors its swatch runs between.
const PALETTES = [
  { name: "Warmth", from: "oklch(0.75 0.13 80)", to: "oklch(0.55 0.15 40)" },
  { name: "Vesper", from: "oklch(0.55 0.12 300)", to: "oklch(0.25 0.06 280)" },
  { name: "Tide", from: "oklch(0.6 0.1 220)", to: "oklch(0.25 0.05 240)" },
  { name: "Fern", from: "oklch(0.62 0.08 150)", to: "oklch(0.2 0.02 150)" },
  { name: "Ember", from: "oklch(0.6 0.17 35)", to: "oklch(0.3 0.08 30)" },
  { name: "Graphite", from: "oklch(0.55 0 0)", to: "oklch(0.2 0 0)" },
] as const

/** A three-column Grid of palette tiles: one column on a phone, two from
 * 40rem, three from 48rem. */
export default function GridDemo() {
  return (
    <Grid cols={3} gap="md" className="max-w-3xl">
      {PALETTES.map((palette) => (
        <div key={palette.name} className="flex flex-col gap-2">
          <div
            aria-hidden="true"
            className="aspect-[4/3] rounded-lg"
            style={{
              background: `linear-gradient(${palette.from}, ${palette.to})`,
            }}
          />
          <span className="text-sm font-medium">{palette.name}</span>
        </div>
      ))}
    </Grid>
  )
}

This example installs with everything it uses:

pnpm dlx shadcn@latest add @01orbital/grid-demo

API reference

Columns follow the screen, stepping at 40rem and 48rem (and 64rem for six). Gap sizes read the shared --gap-* values in globals.css. The grid fills its parent's width: without that, a grid given mx-auto or set inside a centering parent shrinks to fit its content, and a part built on it that is a container collapses to nothing.

className, render and every other prop go to the grid. To narrow a Grid, pass a max-w-* class or size its parent.

Prop

Type

It also accepts the props of the Base UI part it wraps, and the HTML attributes of the element it renders.

Dependencies

npm: @base-ui/react, class-variance-authority, cn. The CLI installs them for you.

Used in blocks

14 blocks are built with Grid; the first 12:

Last updated on