Meter

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

Source
$npx @dinachi/cli@latest add meter
Storage Used
x
value
max
MeterLabel
MeterValue

Usage

import {
  Meter,
  MeterIndicator,
  MeterLabel,
  MeterTrack,
  MeterValue,
} from "@/components/ui/meter"

export function StorageMeter() {
  return (
    <Meter value={72}>
      <div className="flex items-center justify-between">
        <MeterLabel>Storage used</MeterLabel>
        <MeterValue />
      </div>
      <MeterTrack>
        <MeterIndicator />
      </MeterTrack>
    </Meter>
  )
}

Examples

Storage Used
x
A label and the formatted value above the track.
import { Meter, MeterTrack, MeterIndicator, MeterLabel, MeterValue } from '@/components/ui/meter';

export function Example() {
  return (
    <Meter value={72} className="w-full max-w-sm">
      <div className="flex items-center justify-between">
        <MeterLabel>Storage Used</MeterLabel>
        <MeterValue />
      </div>
      <MeterTrack>
        <MeterIndicator />
      </MeterTrack>
    </Meter>
  );
}

Notes

Meter or Progress

Meter shows a measurement anywhere in its range, such as disk space. For a task moving towards done, use Progress.

Agent

Meter does not register with the agent bridge. The bridge reads it from the accessibility tree as meter, with value, min and max, and no actions.

agent.snapshot()
// [{ component: "meter", label: "Storage used", value: 72, min: 0, max: 100, actions: [] }]

API

value
agent
number
The current reading. Clamped to min and max.
min
agent
number = 0
The low end of the range.
max
agent
number = 100
The high end of the range.
formatIntl.NumberFormatOptions
Formats the value. Defaults to a percent of the range.
localeIntl.LocalesArgument
Locale for formatting the value.
getAriaValueText(formattedValue, value) => string
Text screen readers announce for the value.

Accessibility

  • The root has the meter role with aria-valuenow, aria-valuemin and aria-valuemax.
  • MeterLabel names it via aria-labelledby; otherwise give the root an aria-label.
  • aria-valuetext is the formatted value, or what getAriaValueText returns.
  • Reduced motion turns off the indicator transition.