Skip to content

Meter

How much of something there is, on a scale that is known in advance: disk used, seats taken, quota spent. It looks like a progress bar and is not one: the number is already known, and where it sits is what it means.

tsx
import { Meter } from 'neba';

<Meter value={38} label="Storage" showValue />;

Props

PropTypeDefaultDescription
value * numberHow much there is. Required, and that is the difference from ProgressLinear: a meter reports a quantity that is already known, so there is no indeterminate case
minnumber0The bottom of the range
maxnumber100The top of the range
thresholdsreadonly NebaThreshold[]Where the bar changes colour, as { from, color } entries listed smallest first. The last one the value has reached wins; below all of them color stands
labelReactNodeA name for what is being measured. Read out with the value
showValuebooleanfalseShows the value as text beside the bar. A share of the range unless format says otherwise
formatIntl.NumberFormatOptionsHow to write the value. A meter usually has real units, which is when this matters more than it does on a progress bar
sizeshared'xs' | 'sm' | 'md' | 'lg' | 'xl''md'Thickness of the groove, on the same ladder ProgressLinear uses
thicknessnumberThe groove's thickness in pixels. The same prop a ProgressLinear takes
colorshared'primary' | 'secondary' | 'success' | 'warning' | 'danger' | 'info''primary'The family the bar carries before any threshold is reached

Native <div> attributes pass through to the root. Only color and children are excluded, since the table above spells them differently.

value is required, and that is the difference from ProgressLinear. A progress bar is about time: something is happening, it may have no value at all, and it is expected to move on its own. A meter is about quantity: it does not move unless the thing it measures does.

NebaThreshold

PropTypeDefaultDescription
from * numberThe value from which this family applies, in the meter's own units
color * shared'primary' | 'secondary' | 'success' | 'warning' | 'danger' | 'info'What the bar turns at and above that point

Examples

thresholds

Where the bar changes colour. Each entry is a point on the scale and the family the bar takes from there up; the last one the value has reached wins, and below all of them color stands. List them smallest from first: they are read in the order they are given.

min · max · format

showValue prints the reading beside the label. Without a format it is a share of minmax; with one it is the number itself, through Intl.NumberFormat: which is the usual case here, because a meter normally has real units.

size

size is the thickness of the groove, on the same ladder a ProgressLinear uses, so the two line up when a page carries both.

thickness

The same prop a ProgressLinear takes, and for the same reason: size is a step on the ladder, thickness is a number of pixels.

Accessibility

  • Carries role="meter" with the value and range attributes.
  • label becomes the accessible name, and aria-valuetext says the same thing as the printed value.
  • Colour is never the only carrier: a bar that has crossed a threshold is also longer, and the printed value says the number.

Released under the MIT License