Skip to content
Nizivo UI

Grid

The page grid: --nz-grid-columns columns (4, 8, 12 by viewport). Items snap to spans.

Server component, no client JS

Import

import { Grid, GridItem } from '@nizivo/react/grid';

// Once per app (Getting started), after
// @nizivo/tokens/tokens.css and @nizivo/react/css/base.css
import '@nizivo/react/css/grid.css';

Static or interactive

Server. It ships no client JavaScript when a Server Component renders it, in every Next.js build mode; its code is bundled only when a client component (a 'use client' file) imports it. How to choose.

In a client app (a Vite or React Router single-page app, or a 'use client' file) it is an ordinary React component: event handlers, refs and state work as usual. In a client app.

Examples

Basic

Revenue
Top products
Orders
Visitors
Conversion
Average order
import type { JSX } from 'react';
import { Grid, GridItem } from '@nizivo/react/grid';

export function GridExample(): JSX.Element {
  return (
    <Grid>
      {/* Desktop 8 + 4; tablet and mobile take the full row. */}
      <GridItem span={{ base: 'full', lg: 8 }}>Revenue</GridItem>
      <GridItem span={{ base: 'full', lg: 4 }}>Top products</GridItem>
      {/* KPI tiles: one column on mobile, 2 × 2 on tablet, four across on desktop. */}
      <GridItem span={{ base: 'full', sm: 4, lg: 3 }}>Orders</GridItem>
      <GridItem span={{ base: 'full', sm: 4, lg: 3 }}>Visitors</GridItem>
      <GridItem span={{ base: 'full', sm: 4, lg: 3 }}>Conversion</GridItem>
      <GridItem span={{ base: 'full', sm: 4, lg: 3 }}>Average order</GridItem>
    </Grid>
  );
}

Props

Grid

The page grid: --nz-grid-columns columns (4, 8, 12 by viewport). Items snap to spans.

Server component Renders data-slot="grid" with the class nz-grid. Props: GridProps. Source: src/grid/grid.tsx.

NameTypeDefaultDescription
gapLayoutGap
"0""0-5""1""1-5""2""3""4""5""6""8""10""12""16""20""24"
–

Space between tracks, as a --nz-space-* key. Absent, the responsive gutter (--nz-grid-gutter: 16, 20, 24 px).

renderRenderProp<GridState>–
  • Also takes every attribute of <div>. (ComponentPropsWithRef<"div">)

render takes an element, or, in client code, a function of the props and this state (GridState):

NameTypeDefaultDescription
gaprequiredLayoutGap | undefined
"0""0-5""1""1-5""2""3""4""5""6""8""10""12""16""20""24"
–

GridItem

Server component Renders data-slot="grid-item" with the class nz-grid-item. Props: GridItemProps. Source: src/grid/grid.tsx.

NameTypeDefaultDescription
renderRenderProp<GridItemState>–
spanGridSpan | GridResponsiveSpan1
  • Also takes every attribute of <div>. (ComponentPropsWithRef<"div">)

render takes an element, or, in client code, a function of the props and this state (GridItemState):

NameTypeDefaultDescription
spanrequiredGridSpan | GridResponsiveSpan | undefined–

Other exports

GridItemProps type

import type { GridItemProps } from '@nizivo/react/grid'

The props of GridItem, listed above.

GridItemState type

import type { GridItemState } from '@nizivo/react/grid'

The render state of GridItem, listed above.

GridProps type

import type { GridProps } from '@nizivo/react/grid'

The props of Grid, listed above.

GridResponsiveSpan type

import type { GridResponsiveSpan } from '@nizivo/react/grid'

A span per breakpoint: base is mobile first, sm applies from 40rem (--nz-sm) and lg from 80rem (--nz-lg, provisional). An absent breakpoint keeps the one below it.

NameTypeDefaultDescription
baseGridSpan
123456789101112"full"
–
lgGridSpan
123456789101112"full"
–
smGridSpan
123456789101112"full"
–
GridSpan type

import type { GridSpan } from '@nizivo/react/grid'

Columns an item spans, or 'full' for the whole row. Clamped to the columns available.

type GridSpan = 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | "full"

GridState type

import type { GridState } from '@nizivo/react/grid'

The render state of Grid, listed above.

Data attributes and slots

Style parts by class (.nz-<slot>) and state by data attribute. Attribute meanings come from contracts/vocabulary.json.

SlotRendered byData attributes
grid
.nz-grid
Grid
root (takes render)
  • data-gap: "0""0-5""1""1-5""2""3""4""5""6""8""10""12""16""20""24" ← gap
    The gap prop: a --nz-space-* step; values in each component manifest
grid-item
.nz-grid-item
GridItem
root (takes render)
  • data-span: "1""2""3""4""5""6""7""8""9""10""11""12""full" ← span
    The span prop: columns spanned, mobile first and clamped to --nz-grid-columns; values in the Grid manifest
  • data-span-lg: "1""2""3""4""5""6""7""8""9""10""11""12""full"
    The span prop's value from --nz-lg (provisional); values in the Grid manifest
  • data-span-sm: "1""2""3""4""5""6""7""8""9""10""11""12""full"
    The span prop's value from --nz-sm; values in the Grid manifest

CSS hooks

Set a hook on the component's class or any ancestor to restyle it without specificity games; leave it unset for the default shown.

This stylesheet reads no public hook.

Layers: nz.components. Classes: .nz-grid, .nz-grid-item.

Tokens this stylesheet reads (17)

--nz-grid-columns, --nz-grid-gutter, --nz-space-0, --nz-space-0-5, --nz-space-1, --nz-space-1-5, --nz-space-10, --nz-space-12, --nz-space-16, --nz-space-2, --nz-space-20, --nz-space-24, --nz-space-3, --nz-space-4, --nz-space-5, --nz-space-6, --nz-space-8

Accessibility

Nothing in this component takes focus or keyboard input.

Keyboard

None.

Figma

Node ids from design/component-map.json, which nz gen writes from component.json. The links open the Nizivo Figma library, which may ask you to sign in.

  • Canonical: none
  • Ghost masters: none

On this page