Skip to content
Nizivo UI

Meter

A native meter for a measurement within a known range, such as storage used, with low, high and optimum thresholds.

Server component, no client JS

Import

import { Meter } from '@nizivo/react/meter';

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

Plan storage
Low stock
Used
import type { JSX } from 'react';
import { Meter } from '@nizivo/react/meter';

export function MeterExample(): JSX.Element {
  return (
    <div>
      {/* usage: high is bad, so the optimum is the minimum */}
      <Meter label="Plan storage" value={86} high={80} optimum={0} />
      {/* stock: low is bad, so the optimum is the maximum */}
      <Meter label="Low stock" value={12} low={20} high={50} optimum={100} />
      <Meter label="Used" value={310} max={500} valueText="310 / 500" />
    </div>
  );
}

Props

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

NameTypeDefaultDescription
highnumber–

Lower end of the high range.

labelReactNode–

The visible name. Without it, name the meter with aria-label or aria-labelledby.

localestring'en-US'

BCP 47 tag for the percentage.

lownumber–

Upper end of the low range.

maxnumber100

Must be above min.

minnumber0
optimumnumber–

The best value. Without it the browser puts the optimum in the middle of the range. For a quota or usage meter where high is bad, set optimum={min}; for stock, where low is bad, set optimum={max}.

renderRenderProp<MeterState>–

Composition of the root; the native <meter> inside keeps its semantics.

showValuebooleantrue

Shows the value beside the label (hidden from assistive technology, which reads the meter itself).

toneMeterTone
"brand""success""warning""critical""neutral"
'brand'
valuerequirednumber–

A measurement within a known range (storage used, stock left), not progress. Clamped to min…max.

valueTextstring–

Replaces the shown percentage and is read instead of it, for example "310 of 500".

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

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

NameTypeDefaultDescription
maxrequirednumber–
minrequirednumber–
tonerequiredMeterTone
"brand""success""warning""critical""neutral"
–
valuerequirednumber–

The value clamped to min…max.

Other exports

MeterProps type

import type { MeterProps } from '@nizivo/react/meter'

The props of Meter, listed above.

MeterState type

import type { MeterState } from '@nizivo/react/meter'

The render state of Meter, listed above.

MeterTone type

import type { MeterTone } from '@nizivo/react/meter'

The colour of the optimum region. Outside it the browser's ranges pick warning, then critical.

type MeterTone = "brand" | "success" | "warning" | "critical" | "neutral"

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
meter
.nz-meter
Meter
root (takes render)
  • data-tone: "brand""success""warning""critical""neutral" ← tone
    The tone prop; values in each component manifest
meter-header
.nz-meter-header
Meter
inner element (CSS only)
none
meter-label
.nz-meter-label
Meter
inner element (CSS only)
none
meter-track
.nz-meter-track
Meter
inner element (CSS only); forced colours: fill on ::-webkit-meter-optimum-value, fill on ::-webkit-meter-suboptimum-value, fill on ::-webkit-meter-even-less-good-value, fill on ::-moz-meter-bar
none
meter-value
.nz-meter-value
Meter
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-meter-fill
  • default: var(--nz-chart-primary)
  • data-tone="critical": var(--nz-chart-critical)
  • data-tone="neutral": var(--nz-chart-neutral)
  • data-tone="success": var(--nz-chart-success)
  • data-tone="warning": var(--nz-chart-warning)
  • background on .nz-meter-track::-moz-meter-bar
  • background on .nz-meter-track::-webkit-meter-optimum-value
--nz-meter-gap--nz-space-2
  • gap on .nz-meter
--nz-meter-height--nz-space-1-5
  • block-size on .nz-meter-track
--nz-meter-label-font--nz-font-label-m
  • font on .nz-meter-label
--nz-meter-radius--nz-radius-full
  • border-radius on .nz-meter-track
  • border-radius on .nz-meter-track::-moz-meter-bar
  • border-radius on .nz-meter-track::-webkit-meter-even-less-good-value
  • border-radius on .nz-meter-track::-webkit-meter-optimum-value
  • border-radius on .nz-meter-track::-webkit-meter-suboptimum-value
--nz-meter-track-bg--nz-chart-track
  • background on .nz-meter-track

Layers: nz.components. Classes: .nz-meter, .nz-meter-header, .nz-meter-label, .nz-meter-track, .nz-meter-value.

Tokens this stylesheet reads (14)

--nz-chart-critical, --nz-chart-neutral, --nz-chart-primary, --nz-chart-success, --nz-chart-track, --nz-chart-warning, --nz-font-label-m, --nz-font-numeric-m, --nz-radius-full, --nz-space-1-5, --nz-space-2, --nz-space-3, --nz-text-primary, --nz-text-secondary

Accessibility

Nothing in this component takes focus or keyboard input.

In forced-colours mode these states keep a visible system colour: meter-track::-webkit-meter-optimum-value (fill), meter-track::-webkit-meter-suboptimum-value (fill), meter-track::-webkit-meter-even-less-good-value (fill), meter-track::-moz-meter-bar (fill).

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