Skip to content
TopClass UI

Meter

A reading inside a known range, such as disk space or a score: a neutral track with a bar in the tone, rendered on the server.

server - 0 KB

Meter

server - 0 KB

A reading inside a known range, such as disk space or a score: a neutral track with a bar in the tone, rendered on the server.

Install
Battery

The code

meter.tsx
import { Meter } from 'topclassui/meter'

/** The docs sample: the visible text names the meter, which reads 60 of 0 to 100. */
export default function Demo() {
  return (
    <div className="grid max-w-sm gap-2">
      <span id="battery-label" className="text-sm">Battery</span>
      <Meter value={60} aria-labelledby="battery-label" />
    </div>
  )
}

It renders no text, so name it with aria-label or aria-labelledby; the type refuses a Meter with neither.

Import from the package

topclassui/meter
import { Meter } from 'topclassui/meter'

Install once:npm i topclassui@beta zod

Examples

  • For a task moving towards done, use Progress; Meter is a reading, with min, max and value of its own.
  • min and max are clamped, max is raised to min when below it, and value is held between the two.
  • aria-valuetext is passed through, so a screen reader says "512 GB of 1 TB" instead of "512".
  • The track fills its container and is never narrower than 4rem; give it a width of its own with className.
basic
Battery
range
Disk: 512 GB of 1 TB
tones
sizes
custom-size
In Arabic, right to left
القرص: ٥١٢ غيغابايت من ١ تيرابايت

Props

The props of Meter
PropTypeDefaultLimitsDescription
aria-labelstring--The name read out when no visible text names the meter.
aria-labelledbystring--The id of the visible text that names the meter.
maxnumber, min -1000000000000000, max 1000000000000000100min -1000000000000000, max 1000000000000000The high end of the range, where the track is full; raised to min when below it.
minnumber, min -1000000000000000, max 10000000000000000min -1000000000000000, max 1000000000000000The low end of the range, where the track is empty.
sizexs | sm | md | lg | xl | custom"md"-The shared size scale, which sets the track height; custom emits none.
toneprimary | neutral | success | warning | danger | info"primary"-The colour of the bar; the track stays neutral in every tone.
valuenumber, min -1000000000000000, max 10000000000000000min -1000000000000000, max 1000000000000000The reading, clamped between min and max before it reaches ARIA or the bar.

Keyboard and accessibility

Nothing to operate: it is not interactive on its own.

  • It writes role="meter" with the clamped minimum, maximum and value.
  • The bar takes the tone's text colour, and a line-strong outline marks the end of the range. Under forced colours the track is Canvas and the bar CanvasText.

Right to left

The bar grows from the inline start: from the right in Arabic, with no class of its own for it.

Server and client

Renders on the server and ships no JavaScript.

Files: index.tsx.

On the chip: server - 0 KB.