Skip to content

Segmented Meter

Show resource usage in cells, with warning and danger thresholds.

import { SegmentedMeter, SegmentedMeterThreshold } from '@youj/react'

Installation & usage

npm i @youj/react

For an app already set up with npx @youj/cli init, which installs the peers (@youj/core, @youj/motion, motion and Base UI) and wires the provider. New app? Start at Installation.

Use a segmented meter for usage people compare across a panel: threads, disk, a backlog, seats. The discrete cells make levels countable, and the cells past a threshold light in its tone, so the warning shows exactly where usage crossed the line. For one headline score, use a Gauge; for progress through a task, use Progress.

import { SegmentedMeter } from '@youj/react'

<SegmentedMeter label="Disk" value={84} thresholds={[{ value: 80, tone: 'warning', label: 'High' }]} />
<SegmentedMeter label="Backlog" value={870} max={2400} format={{}} />

The value on the end side is a percentage of the range by default; pass format (Intl.NumberFormat options) to show the raw value, as the backlog does. segments sets the number of cells (default 40), tone the lit cells' tone below every threshold (default neutral, the ink) and showValue={false} hides the value.

Reference

Propsvalue, min, max… (11)

Props

SegmentedMeter props
PropType
valueRequirednumber–
minnumber

default 0

0
maxnumber

default 100

100
labelReactNode

The visible name on the start side: "CPU".

–
segmentsnumber

How many cells.

default 40

40
toneMeterTone
'accent''success''warning''danger''neutral'

The lit cells' tone below every threshold.

default 'neutral'

'neutral'
thresholdsSegmentedMeterThreshold[]

Bands: cells from a threshold's value up light in its tone.

–
colorBy'position' | 'value'

position: each lit cell takes the band it sits in. value: every lit cell takes the value's band, as a score does.

default 'position'

'position'
formatIntl.NumberFormatOptions

Intl.NumberFormat options for the value. Default: a percentage of the range.

–
localestring

Default: the YoujProvider locale.

–
showValueboolean

Show the value on the end side.

default true

true
Other props pass through: extends MeterPrimitive.Root.Props.
StylingParts and data attributes

Styling

Parts: segmented-meter, segmented-meter-header, segmented-meter-label, segmented-meter-value, segmented-meter-track and segmented-meter-cell. Each cell has data-state (on or off) and, when lit, data-tone. The label takes the theme's label voice (mono capitals in Basalt).

MotionFill, each cell, new value · reduced motion

Motion

Motion tokens
MomentTokens
Fillwhen half of it scrolls into view the cells light one after another at a constant rate, the whole row spanning the deliberate token
duration.deliberate

560ms

560ms
Each cellfades to its tone
duration.fastease.standard

140ms · cubic-bezier(0.2, 0, 0, 1)

140mscubic-bezier(0.2, 0, 0, 1)
New valuelights or darkens the cells between the edge on screen and the new one, in order
duration.fastease.standard

140ms · cubic-bezier(0.2, 0, 0, 1)

140mscubic-bezier(0.2, 0, 0, 1)

Reduced motion

The cells are lit at once, and a new value relights them in place.

Reduced motion

Every cell is lit at once, with no stagger.

AccessibilityARIA

Accessibility

  • It's a meter (Base UI Meter) named by its visible label; without one, give it aria-label.
  • The value is spoken with its band: "88%, High". A warning or danger band without a label is spoken as "Warning" or "Critical".
  • The cells are hidden from assistive tech. They fill from the inline start, so right to left in RTL.