Skip to content
Nizivo UI

NumberValue

A number formatted once with Intl.NumberFormat, in a <data> element whose value attribute keeps the raw number. Tabular figures, so a column of values lines up. Every dashboard part renders its numbers with it.

Server component, no client JS

Import

import { NumberValue } from '@nizivo/react/number-value';

// Once per app (Getting started), after
// @nizivo/tokens/tokens.css and @nizivo/react/css/base.css
import '@nizivo/react/css/number-value.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 text is formatted on the server with Intl.NumberFormat(locale, format); formatNumber, exported from the same subpath, returns the same text, so CountUp's client frames end on exactly the server's string. 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

48,290$123,307.403.2%1.3M1.250,00 €
import type { JSX } from 'react';
import { NumberValue } from '@nizivo/react/number-value';

export function NumberValueExample(): JSX.Element {
  return (
    <div>
      <NumberValue value={48290} />
      <NumberValue
        value={123307.4}
        format={{ style: 'currency', currency: 'USD', minimumFractionDigits: 2 }}
      />
      <NumberValue value={0.032} format={{ style: 'percent', maximumFractionDigits: 1 }} />
      <NumberValue value={1284000} format={{ notation: 'compact' }} />
      <NumberValue value={1250} format={{ style: 'currency', currency: 'EUR' }} locale="de-DE" />
    </div>
  );
}

Props

A formatted number in a <data> element: tabular figures, isolated from the surrounding direction, never wrapped inside the number (§16.4). It takes the surrounding font; Metric gives it Numeric/*.

Server component Renders data-slot="number-value" with the class nz-number-value. Props: NumberValueProps. Source: src/number-value/number-value.tsx.

NameTypeDefaultDescription
formatIntl.NumberFormatOptions{}

Intl.NumberFormat options (serialisable, so a Server Component can pass them).

localestring'en-US'

BCP 47 tag for the number.

renderRenderProp<NumberValueState>–
valuerequirednumber–

The number. The element's value attribute carries it unformatted, for machines.

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

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

NameTypeDefaultDescription
textrequiredstring–

The formatted text the element shows.

valuerequirednumber–

Other exports

NumberValueProps type

import type { NumberValueProps } from '@nizivo/react/number-value'

The props of NumberValue, listed above.

NumberValueState type

import type { NumberValueState } from '@nizivo/react/number-value'

The render state of NumberValue, listed above.

formatNumber function

import { formatNumber } from '@nizivo/react/number-value'

The text NumberValue renders for value: Intl.NumberFormat(locale, format), nothing else.

function formatNumber(value: number, format?: Intl.NumberFormatOptions, locale?: string): string

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
number-value
.nz-number-value
NumberValue
root (takes render)
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.

This stylesheet reads no public hook.

Layers: nz.components. Classes: .nz-number-value.

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