Grid
The page grid: --nz-grid-columns columns (4, 8, 12 by viewport). Items snap to spans.
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
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.
| Name | Type | Default | Description |
|---|---|---|---|
gap | LayoutGap"0""0-5""1""1-5""2""3""4""5""6""8""10""12""16""20""24" | – | Space between tracks, as a |
render | RenderProp<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):
| Name | Type | Default | Description |
|---|---|---|---|
gaprequired | LayoutGap | 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.
| Name | Type | Default | Description |
|---|---|---|---|
render | RenderProp<GridItemState> | – | |
span | GridSpan | GridResponsiveSpan | 1 |
- 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):
| Name | Type | Default | Description |
|---|---|---|---|
spanrequired | GridSpan | GridResponsiveSpan | undefined | – |
Other exports
GridItemPropstypeimport type { GridItemProps } from '@nizivo/react/grid'The props of
GridItem, listed above.GridItemStatetypeimport type { GridItemState } from '@nizivo/react/grid'The render state of
GridItem, listed above.GridPropstypeimport type { GridProps } from '@nizivo/react/grid'The props of
Grid, listed above.GridResponsiveSpantypeimport type { GridResponsiveSpan } from '@nizivo/react/grid'A span per breakpoint:
baseis mobile first,smapplies from 40rem (--nz-sm) andlgfrom 80rem (--nz-lg, provisional). An absent breakpoint keeps the one below it.Name Type Default Description baseGridSpan123456789101112"full"– lgGridSpan123456789101112"full"– smGridSpan123456789101112"full"– GridSpantypeimport 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"GridStatetypeimport 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.
| Slot | Rendered by | Data attributes |
|---|---|---|
grid.nz-grid | Gridroot (takes render) |
|
grid-item.nz-grid-item | GridItemroot (takes render) |
|
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
Form
An optional client <form> for forms whose errors come back from the server. Errors keyed by Field name appear in each Field, focus moves to the first invalid control, and an optional error summary links to each one. SubmitButton is pending while the form's action runs; FormMessage is the form-level message.
Heading
A heading whose outline level (h1 to h6) and look (the heading text style) are set independently.