oakoss/ui
Components

Meter

A value within a known range, such as storage used.

SourceReact Aria
Storage64%

Installation

npx shadcn@latest add @oakoss/meter

Usage

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:

  • A task moving toward done is a Progress bar.
  • A value the user sets is a Slider.

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.

Battery92%
Memory78%
Disk96%
Bandwidth35%

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.

Storage180 GB
Seats18 of 25

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.

Mailbox8 of 20 GB, plenty left
Mailbox16 of 20 GB, running low
Mailbox19 of 20 GB, almost full

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.

CPU42% in use

Accessibility

React Aria renders a meter named by its label and handles:

  • Value: aria-valuenow, aria-valuemin and aria-valuemax, and aria-valuetext with the formatted value or your valueLabel.

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

AttributePresent when
data-slotAlways: meter, and on the parts meter-label, meter-value, meter-track, meter-indicator
data-intentAlways on Meter: the fill color

CSS variables

VariableSets
--meter-fillThe 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.