Meter
A value within a known range, such as storage used.
Installation
npx shadcn@latest add @oakoss/meterUsage
import { Meter } from '#/components/ui/feedback/meter';
<Meter label="Storage" value={64} />;label renders the default layout: the label and value in a row, then the
track. For a different layout, pass children instead (see
Layout).
A meter shows a measurement that stays where it is, such as storage used, battery left or a password's strength. Other values have their own component:
Examples
Intents
intent colors the fill: primary (the default), success, warning,
destructive or info. Each keeps 3:1 against the track in light and dark.
Value
formatOptions formats the value for the locale, a percentage by default
or a unit such as gigabytes. valueLabel replaces it with your own text, and
minValue and maxValue set the range.
Thresholds
Meter has no thresholds of its own; compute intent from the value. Put the
level in valueLabel too, so it doesn't rely on color, and screen readers
read it as the value.
Layout
Children replace the default layout, built from MeterTrack, MeterLabel
and MeterValue in any order. MeterValue takes a function of the formatted
value to add words around it, and a function child of Meter gets React
Aria's render props, such as percentage.
Accessibility
React Aria renders a meter named by its label and handles:
- Value:
aria-valuenow,aria-valueminandaria-valuemax, andaria-valuetextwith the formatted value or yourvalueLabel.
A meter needs a name: label, a MeterLabel in your layout, or
aria-label when there's no visible label. The fill grows by width, logical
in right-to-left locales, and takes the system highlight color in Windows
High Contrast, where the track keeps a border. React Aria adds no keys.
API
Meter
Extends React Aria's Meter.
Props
Prop
Type
Also accepts all React Aria Meter props.
Takes label or children, not both: children replace the layout, and a
function child gets React Aria's render props, such as percentage and
valueText.
Data attributes
| Attribute | Present when |
|---|---|
data-slot | Always: meter, and on the parts meter-label, meter-value, meter-track, meter-indicator |
data-intent | Always on Meter: the fill color |
CSS variables
| Variable | Sets |
|---|---|
--meter-fill | The fill color |
MeterLabel
React Aria's Label, which names
the meter.
MeterValue
A span with the formatted value.
Props
Prop
Type
Also accepts span props.
MeterTrack
The track, a span that draws the fill inside it. Accepts span props
other than children.