Meter
A native meter for a measurement within a known range, such as storage used, with low, high and optimum thresholds.
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
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.
| Name | Type | Default | Description |
|---|---|---|---|
high | number | – | Lower end of the high range. |
label | ReactNode | – | The visible name. Without it, name the meter with |
locale | string | 'en-US' | BCP 47 tag for the percentage. |
low | number | – | Upper end of the low range. |
max | number | 100 | Must be above |
min | number | 0 | |
optimum | number | – | 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 |
render | RenderProp<MeterState> | – | Composition of the root; the native |
showValue | boolean | true | Shows the value beside the label (hidden from assistive technology, which reads the meter itself). |
tone | MeterTone"brand""success""warning""critical""neutral" | 'brand' | |
valuerequired | number | – | A measurement within a known range (storage used, stock left), not progress. Clamped to |
valueText | string | – | Replaces the shown percentage and is read instead of it, for example "310 of 500". |
- Also takes every attribute of
<div>exceptchildren. (Omit<ComponentPropsWithRef<"div">, "children">)
render takes an element, or, in client code, a function of the props and this state (MeterState):
| Name | Type | Default | Description |
|---|---|---|---|
maxrequired | number | – | |
minrequired | number | – | |
tonerequired | MeterTone"brand""success""warning""critical""neutral" | – | |
valuerequired | number | – | The value clamped to |
Other exports
MeterPropstypeimport type { MeterProps } from '@nizivo/react/meter'The props of
Meter, listed above.MeterStatetypeimport type { MeterState } from '@nizivo/react/meter'The render state of
Meter, listed above.MeterTonetypeimport 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.
| Slot | Rendered by | Data attributes |
|---|---|---|
meter.nz-meter | Meterroot (takes render) |
|
meter-header.nz-meter-header | Meterinner element (CSS only) | none |
meter-label.nz-meter-label | Meterinner element (CSS only) | none |
meter-track.nz-meter-track | Meterinner 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 | Meterinner 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-meter-fill |
|
|
--nz-meter-gap | --nz-space-2 |
|
--nz-meter-height | --nz-space-1-5 |
|
--nz-meter-label-font | --nz-font-label-m |
|
--nz-meter-radius | --nz-radius-full |
|
--nz-meter-track-bg | --nz-chart-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
Menu
A menu of actions or links opened from a button, with groups, separators, shortcuts, a critical tone, and checkbox and radio items. For choosing a form value, use Select; for navigation between views, use TabNav.
Metric
A label, a number and its change, the block Figma draws in both the KPI tile and the Revenue card. It takes the loading, empty and error contract, and keeps its box in all four states.