Delta
A signed change, such as +12.4%, coloured by direction and read with a visually hidden comparison. The sign carries the direction without colour.
Import
import { Delta } from '@nizivo/react/delta';
// Once per app (Getting started), after
// @nizivo/tokens/tokens.css and @nizivo/react/css/base.css
import '@nizivo/react/css/delta.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. The
number is formatted on the server with Intl.NumberFormat. 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.
On a tinted surface
Inside a Card, KpiTile or TrendCard with tone="brand" or tone="accent", the pill is
bg/surface, because Figma's bg/success-subtle is the same colour as bg/brand-subtle and the
pill would show no fill there (a deviation from Figma 04 gap 4, M42). Its text colour, and so its
contrast, is unchanged. Set --nz-delta-bg to choose another fill.
Examples
Basic
import type { JSX } from 'react';
import { Delta } from '@nizivo/react/delta';
export function DeltaExample(): JSX.Element {
return (
<div>
<Delta value={0.124} comparison="vs last week" />
<Delta value={-0.031} comparison="vs last week" />
<Delta value={0} comparison="vs last week" />
{/* A rise in refunds is bad news */}
<Delta value={0.08} tone="critical" comparison="refunds vs last month" />
<Delta value={1250} format={{ style: 'currency', currency: 'EUR' }} locale="de-DE" />
</div>
);
}
Props
Server component Renders data-slot="delta" with the class nz-delta. Props: DeltaProps. Source: src/delta/delta.tsx.
| Name | Type | Default | Description |
|---|---|---|---|
comparison | string | – | Visually hidden phrase read after the value, for example "vs last week". |
format | Intl.NumberFormatOptions | – | Replaces the default |
icon | ReactNode | – | Decorative leading glyph; choose it from the sign, for example |
locale | string | 'en-US' | BCP 47 tag for the number. |
render | RenderProp<DeltaState> | – | |
tone | DeltaTone"success""critical""neutral" | – | Overrides the colour derived from the sign, for example |
valuerequired | number | – | The change. With the default percent format it is a fraction: |
- Also takes every attribute of
<span>exceptchildren. (Omit<ComponentPropsWithRef<"span">, "children">)
render takes an element, or, in client code, a function of the props and this state (DeltaState):
| Name | Type | Default | Description |
|---|---|---|---|
tonerequired | DeltaTone"success""critical""neutral" | – | |
trendrequired | DeltaTrend"up""down""flat" | – |
Other exports
DeltaPropstypeimport type { DeltaProps } from '@nizivo/react/delta'The props of
Delta, listed above.DeltaStatetypeimport type { DeltaState } from '@nizivo/react/delta'The render state of
Delta, listed above.DeltaTonetypeimport type { DeltaTone } from '@nizivo/react/delta'The colour: up is
success, down iscritical, flat isneutralunlesstonesays otherwise.type DeltaTone = "success" | "critical" | "neutral"DeltaTrendtypeimport type { DeltaTrend } from '@nizivo/react/delta'Figma "Trend", derived from the sign of
value.type DeltaTrend = "up" | "down" | "flat"
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 |
|---|---|---|
delta.nz-delta | Deltaroot (takes render) |
|
delta-icon.nz-delta-icon | Deltainner element (CSS only) | none |
delta-value.nz-delta-value | Deltainner 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-delta-bg |
|
|
--nz-delta-fg |
|
|
--nz-delta-font | --nz-font-label-m-strong |
|
--nz-delta-gap | --nz-space-1 |
|
--nz-delta-padding-inline | --nz-space-2 |
|
--nz-delta-radius | --nz-radius-full |
|
Layers: nz.components. Classes: .nz-delta, .nz-delta-icon, .nz-delta-value.
Tokens this stylesheet reads (11)
--nz-bg-critical-subtle, --nz-bg-subtle, --nz-bg-success-subtle, --nz-font-label-m-strong, --nz-radius-full, --nz-size-icon-sm, --nz-space-1, --nz-space-2, --nz-text-critical, --nz-text-secondary, --nz-text-success
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:13743 - Ghost masters: Figma node
752:269
DateRangePicker
Unstable: a range of dates from a trigger in Select's look, through a popover with presets, one month of calendar and Cancel and Apply. Values are ISO plain dates; "today" is counted in the time zone you pass. Import it from @nizivo/react/unstable/date-range-picker.
Dialog
A modal dialog or alert dialog with a trigger, title, description, body, footer and close parts. Focus moves in on open and returns to the trigger on close.