Skip to content
Nizivo UI

Stack

Children in a column.

Server component, no client JS

Import

import { Stack } from '@nizivo/react/stack';

// Once per app (Getting started), after
// @nizivo/tokens/tokens.css and @nizivo/react/css/base.css
import '@nizivo/react/css/stack.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

Order #1040
Paid
  • Stoneware mug
  • Linen napkins
import type { JSX } from 'react';
import { Stack } from '@nizivo/react/stack';

export function StackExample(): JSX.Element {
  return (
    <Stack gap="4">
      <div>Order #1040</div>
      <div>Paid</div>
      <Stack gap="2" render={<ul />}>
        <li>Stoneware mug</li>
        <li>Linen napkins</li>
      </Stack>
    </Stack>
  );
}

Props

Children in a column.

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

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

Space between children. Absent, there is none.

renderRenderProp<StackState>–

Another element, for example render={<ul />} for a list.

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

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

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

Other exports

LayoutGap type

import type { LayoutGap } from '@nizivo/react/stack'

A --nz-space-* key: '4' is --nz-space-4 (1rem), '0-5' is --nz-space-0-5. Token keys only.

type LayoutGap = "0" | "0-5" | "1" | "1-5" | "2" | "3" | "4" | "5" | "6" | "8" | "10" | "12" | "16" | "20" | "24"

StackProps type

import type { StackProps } from '@nizivo/react/stack'

The props of Stack, listed above.

StackState type

import type { StackState } from '@nizivo/react/stack'

The render state of Stack, 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
stack
.nz-stack
Stack
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

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.

HookDefaultRead as
--nz-stack-gap
  • default: 0
  • data-gap="0": var(--nz-space-0)
  • data-gap="0-5": var(--nz-space-0-5)
  • data-gap="1": var(--nz-space-1)
  • data-gap="1-5": var(--nz-space-1-5)
  • data-gap="10": var(--nz-space-10)
  • data-gap="12": var(--nz-space-12)
  • data-gap="16": var(--nz-space-16)
  • data-gap="2": var(--nz-space-2)
  • data-gap="20": var(--nz-space-20)
  • data-gap="24": var(--nz-space-24)
  • data-gap="3": var(--nz-space-3)
  • data-gap="4": var(--nz-space-4)
  • data-gap="5": var(--nz-space-5)
  • data-gap="6": var(--nz-space-6)
  • data-gap="8": var(--nz-space-8)
  • gap on .nz-stack

Layers: nz.components. Classes: .nz-stack.

Tokens this stylesheet reads (15)

--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