Skip to content
Nizivo UI

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.

Server component, no client JS

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

+12.4% vs last week-3.1% vs last week0% vs last week+8% refunds vs last month+1.250,00 €
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.

NameTypeDefaultDescription
comparisonstring–

Visually hidden phrase read after the value, for example "vs last week".

formatIntl.NumberFormatOptions–

Replaces the default { style: 'percent', maximumFractionDigits: 1 }. signDisplay stays 'exceptZero' unless you set it: the sign tells the direction without colour, so if you hide it, say the direction in comparison.

iconReactNode–

Decorative leading glyph; choose it from the sign, for example <TrendingUp />.

localestring'en-US'

BCP 47 tag for the number.

renderRenderProp<DeltaState>–
toneDeltaTone
"success""critical""neutral"
–

Overrides the colour derived from the sign, for example critical when a rise is bad.

valuerequirednumber–

The change. With the default percent format it is a fraction: 0.124 renders "+12.4%".

  • Also takes every attribute of <span> except children. (Omit<ComponentPropsWithRef<"span">, "children">)

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

NameTypeDefaultDescription
tonerequiredDeltaTone
"success""critical""neutral"
–
trendrequiredDeltaTrend
"up""down""flat"
–

Other exports

DeltaProps type

import type { DeltaProps } from '@nizivo/react/delta'

The props of Delta, listed above.

DeltaState type

import type { DeltaState } from '@nizivo/react/delta'

The render state of Delta, listed above.

DeltaTone type

import type { DeltaTone } from '@nizivo/react/delta'

The colour: up is success, down is critical, flat is neutral unless tone says otherwise.

type DeltaTone = "success" | "critical" | "neutral"

DeltaTrend type

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

SlotRendered byData attributes
delta
.nz-delta
Delta
root (takes render)
  • data-tone: "success""critical""neutral" ← tone
    The tone prop; values in each component manifest
delta-icon
.nz-delta-icon
Delta
inner element (CSS only)
none
delta-value
.nz-delta-value
Delta
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-delta-bg
  • default: var(--_nz-delta-fill, var(--nz-bg-subtle))
  • data-tone="critical": var(--_nz-delta-fill, var(--nz-bg-critical-subtle))
  • data-tone="success": var(--_nz-delta-fill, var(--nz-bg-success-subtle))
  • background on .nz-delta
--nz-delta-fg
  • default: var(--nz-text-secondary)
  • data-tone="critical": var(--nz-text-critical)
  • data-tone="success": var(--nz-text-success)
  • color on .nz-delta
--nz-delta-font--nz-font-label-m-strong
  • font on .nz-delta
--nz-delta-gap--nz-space-1
  • gap on .nz-delta
--nz-delta-padding-inline--nz-space-2
  • padding-inline on .nz-delta
--nz-delta-radius--nz-radius-full
  • border-radius on .nz-delta

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.

On this page