Web and native

Meter in kanso-ui 0.59.0, for React.

import { Meter } from '@kanso-labs/kanso-ui'

How full something is, on a scale it names: storage used, space left, a rating out of five.

It is Material Design's linear progress indicator drawn for a measurement rather than a task: the same active indicator, track and stop indicator at 4dp, with the label row above. Two things differ: it carries the meter role, so a screen reader announces it as a level rather than as progress, and tone can say whether the value is good or bad.

What you provide

  • A name: label, shown above the line, or aria-label when the surroundings already name it.
  • value between minValue and maxValue (0 and 100 by default).

Props

PropTypeDefaultDescription
captionReactNode—A short line under the bar, in `t-caption` and `ink-muted`, which a screen reader hears as the meter's description. With `late` set it is drawn in `caution` at weight 700, and it should say how many are late in words: "1 late".
classNameMeterProps$1['className']—A function may compute the class from the meter's render state.
labelReactNode—What is being measured, shown above the bar. A screen reader reads it as the meter's name; a meter whose surroundings name it takes `aria-label` instead and leaves this out.
latenumber—How many segments after the done ones are late, drawn hatched in `caution`. Read only with `segments`. Say it in `caption` as well, and in `valueLabel` for a screen reader: "2 of 4 done, 1 late".
segmentsnumber—Draws one segment per item rather than a continuous fill, for a count of up to eight. The segments the value fills are done; pass `maxValue` as the count and `value` as how many are done. The value then reads as the count, "2/4", unless `valueLabel` says otherwise.
showValuebooleantrueWhether the value is shown beside the label.
size'lg' | 'md''md'How thick the bar is: `md` is Kanso's 4px meter, `lg` its thick 8px one, for a share of a whole.
styleMeterProps$1['style']—A function may compute the style from the meter's render state.
targetnumber—A value on the meter's scale to mark across the bar with a 2px line, such as a target or an even share. Not drawn on a segmented meter. A screen reader hears no marker, so name the target in words: in `caption`, which describes the meter, as "Target 50%", or in `valueLabel`, as "64%, target 50%".
tone'accent' | 'ink' | 'negative' | 'positive' | 'primary''accent'Which colour fills the bar. `accent` is Kanso's, for progress towards a goal; `ink` is for a bar that compares people rather than counting towards something. `negative` and `positive` say the value is bad or good, and each draws a glyph before the value, an exclamation mark for `negative` and a check for `positive`, so the tone reads without its colour. A screen reader hears neither glyph, so say the status in `label` or `valueLabel` as well. `primary` is deprecated: it is Material Design's name for what is now `accent`, and draws the accent.

Also takes the props of Omit<MeterProps$1, 'children' | 'className' | 'style'>.

Example

import { Meter } from '@kanso-labs/kanso-ui'

<Meter label="Label" value={40} />
<Meter label="Label" value={94} tone="negative" />
<Meter
  label="Label"
  value={318}
  maxValue={512}
  formatOptions={{ style: 'unit', unit: 'gigabyte', notation: 'compact' }}
/>

The design’s classes

k-meter, k-meter__head, k-meter__value, k-meter__track, k-meter__fill, k-meter__fill--late, k-meter__fill--ink, k-meter__fill--empty, k-meter--segmented, k-meter--thick, k-meter__caption. The marker (k-meter__marker), the caution caption (k-meter__caption--caution) and equal segments are written in the preview until bundle.css has them.

Maps to Meter in kanso-ui and react-native-kanso-ui.