Range meter
A ruler of ticks that rises at the value.
Demo
Usage
import { RangeMeter } from '@tuttn/slant'
// Read-only: it shows the value you pass and keeps no state.
<RangeMeter value={34} max={90} label="Average session" format={value => `${value} min`} />
// A scale that does not start at 0, a tone, fewer ticks.
<RangeMeter value={21.5} min={16} max={28} label="Room" format={value => `${value} °C`} tone="success" ticks={25} />
// Out of range: drawn at the end, still read and written as given ("130 ms").
<RangeMeter value={130} max={100} label="Latency" format={value => `${value} ms`} tone="danger" />
// The number written elsewhere: leave out the readout.
<RangeMeter value={71} label="Disk" hideValue />Props
| Prop | Type | Default | Description |
|---|---|---|---|
value | number | — | The reading. Outside `min` to `max` it is drawn, and reported as `aria-valuenow`, at the nearest end; the readout and `aria-valuetext` still say the value as given. A value that is not a number reads as `min`. |
min | number | 0 | The start of the scale. |
max | number | 100 | The end of the scale. |
label | string | — | The accessible name, e.g. "Average session". |
ticks | number | 41 | How many ticks the ruler draws, at least 2. An odd count puts a tick on the middle of the scale. |
format | (value: number) => string | String | Writes the value for the readout above the peak and for `aria-valuetext`, e.g. `value => \`${value} ms\``. |
tone | Tone | 'accent' | The colour of the ticks up to the value and of the readout. |
hideValue | boolean | false | Leaves out the readout above the peak, when the value is written elsewhere. The meter still reports it. |
…rest | HTMLAttributes<HTMLDivElement> | — | className, style, other attributes and the ref go on the root, which is the meter. |
A range meter shows one reading against a scale: a ruler of thin ticks, leaning back 9° like the slanted pixel, that rise in a smooth hump centred on the value. The ticks up to the value take the tone; the rest stay quiet. The value is written above the peak in monospace, and the readout slides with it but never leaves the meter, so a reading at either end stays legible. For a level that fills toward a maximum (storage, a quota), use a Meter; for a single headline number, a Stat.
Accessibility
The root is role="meter", named by label, with aria-valuemin, aria-valuemax and aria-valuenow. A value outside the scale is drawn at the nearest end and reported there as aria-valuenow, while the readout and aria-valuetext (both from format) still say the value as given, so "130 ms" on a 0 to 100 scale is not read as 100. The ruler and the readout are hidden from assistive technology; the meter carries the value. It is read-only and takes no focus.
Direction and motion
The ticks run along the inline axis, so under <Slant dir="rtl"> the scale starts on the right; the lean stays the same, as it does for every slanted shape. A new value eases the hump and the readout across in --sl-duration-slow; under prefers-reduced-motion they move at once. Nothing runs between changes, so there is no animation to pause off screen.