Skip to content
Nizivo UI

Badge

A short status label with an optional decorative dot. The label carries the meaning, never the colour alone.

Server component, no client JS

Import

import { Badge } from '@nizivo/react/badge';

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

PaidPendingRefundedPartially fulfilledDraftNewPaid
import type { ComponentPropsWithRef, JSX } from 'react';
import { Badge } from '@nizivo/react/badge';

/** Stands in for a router link (Next `Link`, React Router `Link`). */
function Link({ children, ...props }: ComponentPropsWithRef<'a'>): JSX.Element {
  return <a {...props}>{children}</a>;
}

export function BadgeExample(): JSX.Element {
  return (
    <div>
      <Badge tone="success">Paid</Badge>
      <Badge tone="warning">Pending</Badge>
      <Badge tone="critical">Refunded</Badge>
      <Badge tone="info">Partially fulfilled</Badge>
      <Badge>Draft</Badge>
      <Badge tone="brand" dot={false}>
        New
      </Badge>
      <Badge render={<Link href="/orders?status=paid" />} tone="success">
        Paid
      </Badge>
    </div>
  );
}

Props

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

NameTypeDefaultDescription
dotbooleantrue

Figma "Dot": a decorative status dot before the label. The label carries the meaning.

renderRenderProp<BadgeState>–

Composition, for example render={<a href="/orders?status=paid" />}.

toneBadgeTone
"neutral""success""warning""critical""info""brand"
'neutral'
  • Also takes every attribute of <span>. (ComponentPropsWithRef<"span">)

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

NameTypeDefaultDescription
dotrequiredboolean–
tonerequiredBadgeTone
"neutral""success""warning""critical""info""brand"
–

Other exports

BadgeProps type

import type { BadgeProps } from '@nizivo/react/badge'

The props of Badge, listed above.

BadgeState type

import type { BadgeState } from '@nizivo/react/badge'

The render state of Badge, listed above.

BadgeTone type

import type { BadgeTone } from '@nizivo/react/badge'

Figma "Tone". brand is the only solid fill.

type BadgeTone = "neutral" | "success" | "warning" | "critical" | "info" | "brand"

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
badge
.nz-badge
Badge
root (takes render)
  • data-tone: "neutral""success""warning""critical""info""brand" ← tone
    The tone prop; values in each component manifest
badge-dot
.nz-badge-dot
Badge
inner element (CSS only)
none

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-badge-bg
  • default: var(--nz-bg-muted)
  • data-tone="brand": var(--nz-bg-brand)
  • data-tone="critical": var(--nz-bg-critical-subtle)
  • data-tone="info": var(--nz-bg-info-subtle)
  • data-tone="success": var(--nz-bg-success-subtle)
  • data-tone="warning": var(--nz-bg-warning-subtle)
  • background on .nz-badge
--nz-badge-dot-bg
  • default: var(--nz-icon-secondary)
  • data-tone="brand": var(--nz-text-on-brand)
  • data-tone="critical": var(--nz-icon-critical)
  • data-tone="info": var(--nz-icon-info)
  • data-tone="success": var(--nz-icon-success)
  • data-tone="warning": var(--nz-icon-warning)
  • background on .nz-badge-dot
--nz-badge-fg
  • default: var(--nz-text-secondary)
  • data-tone="brand": var(--nz-text-on-brand)
  • data-tone="critical": var(--nz-text-critical)
  • data-tone="info": var(--nz-text-info)
  • data-tone="success": var(--nz-text-success)
  • data-tone="warning": var(--nz-text-warning)
  • color on .nz-badge
--nz-badge-font--nz-font-label-m
  • font on .nz-badge
--nz-badge-gap--nz-space-1-5
  • gap on .nz-badge
--nz-badge-padding-inline--nz-space-2
  • padding-inline on .nz-badge
--nz-badge-radius--nz-radius-full
  • border-radius on .nz-badge

Layers: nz.components. Classes: .nz-badge, .nz-badge-dot.

Tokens this stylesheet reads (22)

--nz-bg-brand, --nz-bg-critical-subtle, --nz-bg-info-subtle, --nz-bg-muted, --nz-bg-success-subtle, --nz-bg-warning-subtle, --nz-font-label-m, --nz-icon-critical, --nz-icon-info, --nz-icon-secondary, --nz-icon-success, --nz-icon-warning, --nz-radius-full, --nz-space-0-5, --nz-space-1-5, --nz-space-2, --nz-text-critical, --nz-text-info, --nz-text-on-brand, --nz-text-secondary, --nz-text-success, --nz-text-warning

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.

On this page