Components
UsageMeter
Unstable: how much AI usage is left, as a meter with the value written out and a note such as when it resets. From 80 % it turns to the warning colour. Import it from @nizivo/react/unstable/usage-meter.
Examples
Basic
Credits left this month, and the warning from 80 %.
Resets on Nov 1 · Upgrade for more
Resets on Nov 1 · Upgrade for more
import type { JSX } from 'react';
import { UsageMeter } from '@nizivo/react/unstable/usage-meter';
export function UsageMeterExample(): JSX.Element {
return (
<div style={{ display: 'grid', gap: 16, inlineSize: 320 }}>
<UsageMeter value={640} max={1000} note="Resets on Nov 1 · Upgrade for more" />
<UsageMeter value={910} max={1000} note="Resets on Nov 1 · Upgrade for more" />
</div>
);
}
Import
import { UsageMeter } from '@nizivo/react/unstable/usage-meter';
// Once per app (Getting started), after
// @nizivo/tokens/tokens.css and @nizivo/react/css/base.css and @nizivo/react/css/meter.css
import '@nizivo/react/css/usage-meter.css';Static or interactive
Server. No client JavaScript: it is a native <meter> (Meter).
How to choose.
Values
value is how much is used and max the allowance; the card shows "640 / 1,000" and a screen reader
hears "640 of 1,000 credits used" (labels.valueText, with {value} and {max}). label names it
("AI credits" by default) and note adds a line under the bar.
Warning
From warnAt (0.8, so 80 %) the bar turns to chart/warning: Meter's high range, with optimum at
zero, since less used is better. Say what happens next in the note, and never stop people silently
when the allowance runs out.
Props
Server component Renders data-slot="usage-meter" with the class nz-usage-meter. Props: UsageMeterProps. Source: src/unstable/usage-meter/usage-meter.tsx.
| Name | Type | Default | Description |
|---|---|---|---|
label | ReactNode | – | The visible name. Replaces |
labels | Partial<UsageMeterLabels> | – | |
locale | string | 'en-US' | BCP 47 tag for the numbers. |
maxrequired | number | – | The allowance. |
note | ReactNode | – | A line under the bar: when it resets, how to get more. |
render | RenderProp<Record<string, never>> | – | Must render a |
valuerequired | number | – | How much is used. |
warnAt | number | 0.8 | The share from which the bar warns. |
- 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 no state.
Other exports
UsageMeterLabelstypeimport type { UsageMeterLabels } from '@nizivo/react/unstable/usage-meter'UsageMeter's own strings (§16.4): serialisable, English defaults.
Name Type Default Description labelrequiredstring'AI credits'The visible name, unless
labelis given.valueTextrequiredstring'{value} of {max} credits used'What a screen reader hears for the meter:
{value}and{max}.UsageMeterPropstypeimport type { UsageMeterProps } from '@nizivo/react/unstable/usage-meter'The props of
UsageMeter, listed above.
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 |
|---|---|---|
usage-meter.nz-usage-meter | UsageMeterroot (takes render) | none |
usage-meter-label.nz-usage-meter-label | UsageMeterinner element (CSS only) | none |
usage-meter-note.nz-usage-meter-note | UsageMeterinner element (CSS only) | none |
usage-meter-value.nz-usage-meter-value | UsageMeterinner 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-usage-meter-bg | --nz-bg-subtle |
|
--nz-usage-meter-radius | --nz-radius-lg |
|
Layers: nz.components. Classes: .nz-meter-track, .nz-usage-meter, .nz-usage-meter-bar, .nz-usage-meter-header, .nz-usage-meter-icon, .nz-usage-meter-label, .nz-usage-meter-note, .nz-usage-meter-value.
Tokens this stylesheet reads (15)
--nz-bg-subtle, --nz-border-subtle, --nz-border-width-default, --nz-font-body-s, --nz-font-label-m, --nz-font-label-m-strong, --nz-icon-brand, --nz-radius-lg, --nz-space-0-5, --nz-space-1-5, --nz-space-2, --nz-space-3, --nz-space-4, --nz-text-primary, --nz-text-secondary
Accessibility
Nothing in this component takes focus or keyboard input.
Keyboard
None.
TrendCard
A headline number with its change, a period control and a comparison chart, on Card's surface. The design's Revenue card is one example of it. Every region is an element slot.
VoiceOrb
Unstable: voice mode, an orb, a written state (Tap to talk, Listening…, Speaking…) and one big control that starts and stops. Import it from @nizivo/react/unstable/voice-orb.