Badge
A short status label with an optional decorative dot. The label carries the meaning, never the colour alone.
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
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.
| Name | Type | Default | Description |
|---|---|---|---|
dot | boolean | true | Figma "Dot": a decorative status dot before the label. The label carries the meaning. |
render | RenderProp<BadgeState> | – | Composition, for example |
tone | BadgeTone"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):
| Name | Type | Default | Description |
|---|---|---|---|
dotrequired | boolean | – | |
tonerequired | BadgeTone"neutral""success""warning""critical""info""brand" | – |
Other exports
BadgePropstypeimport type { BadgeProps } from '@nizivo/react/badge'The props of
Badge, listed above.BadgeStatetypeimport type { BadgeState } from '@nizivo/react/badge'The render state of
Badge, listed above.BadgeTonetypeimport type { BadgeTone } from '@nizivo/react/badge'Figma "Tone".
brandis 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.
| Slot | Rendered by | Data attributes |
|---|---|---|
badge.nz-badge | Badgeroot (takes render) |
|
badge-dot.nz-badge-dot | Badgeinner 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.
| Hook | Default | Read as |
|---|---|---|
--nz-badge-bg |
|
|
--nz-badge-dot-bg |
|
|
--nz-badge-fg |
|
|
--nz-badge-font | --nz-font-label-m |
|
--nz-badge-gap | --nz-space-1-5 |
|
--nz-badge-padding-inline | --nz-space-2 |
|
--nz-badge-radius | --nz-radius-full |
|
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.
- Canonical: Figma node
7275:11374 - Ghost masters: Figma node
744:315
Avatar
A person's or store's photo with an initials fallback that needs no script, and AvatarGroup, a stack of avatars and a count announced as one item ("Maya, Jonah, Priya, and 4 more").
Banner
A page-wide message under the header, one at a time, with a title, a line of text, one action and an optional dismiss. Server-rendered; only the dismiss button hydrates.