Fragiola

API: components

Meter

A scalar measurement within a known range, as the APG meter, with its value formatted by Intl.NumberFormat, in each framework.

Shows a measurement within a known range (the APG meter pattern): a disk's usage, a battery's charge, a password's strength. It is not interactive and it is never indeterminate: how far a task has gone is a Progress.

Storage meter
Gallery

Behaviour

  • Value: a number, clamped to [min, max] (0 and 100 by default).
  • Format: without format, the value is written as a percentage of the range ("60%"); with format (Intl.NumberFormatOptions, in locale), as it says ("384 GB"). The Value and the Root's aria-valuetext use it; getAriaValueText wins over it for the Root. Without locale, the runtime's default: a page rendered on a server passes locale.
  • Label: names the Root (aria-labelledby) while it is rendered; or give the Root an aria-label.
  • Indicator: grows from the inline start (right to left in RTL), with --meter-indicator-size for a recipe that draws it otherwise (a ring).
  • No text: the Root renders nothing of its own (Base UI's visually hidden x for NVDA is not rendered).

Anatomy

partelementdata-primitives-partrole
Rootdivmeter-rootthe meter; holds the value
Labelspanmeter-labelnames the Root
Valuespanmeter-valueshows the formatted value
Trackdivmeter-trackthe rail
Indicatordivmeter-indicatorthe filled part, inside the Track

Usage

import { Meter } from "@fragiola/primitives-react/meter";

<Meter.Root value={384} max={512} format={{ style: "unit", unit: "gigabyte" }} locale="en-US">
    <Meter.Label>Storage</Meter.Label>
    <Meter.Value />
    <Meter.Track>
        <Meter.Indicator />
    </Meter.Track>
</Meter.Root>;

Props

Every part also takes what the primitive contract gives: render (Vue: as and the render slot), a class and a style, a ref, and any attribute, which it forwards. Vue binds them as props (:value, :get-aria-value-text), and Angular as inputs ([value], [getAriaValueText]).

Root

proptypedefaultdescription
valuenumberrequiredthe value, clamped to [min, max]
minnumber0the lower bound
maxnumber100the upper bound
formatIntl.NumberFormatOptionsa percentage of the rangehow the Value and aria-valuetext write the value
localestringthe runtime'sthe locale of the format (a BCP 47 tag)
getAriaValueText(formattedValue: string, value: number) => stringthe Root's aria-valuetext instead of the formatted value

Label

proptypedefaultdescription
idstringgeneratedthe id the Root's aria-labelledby points at

Value

No props of its own. Its children replace the formatted value: a function (formattedValue, value) => ReactNode in React, the default scoped slot { formattedValue, value } in Vue, the directive's formattedValue() and value() signals in Angular.

Track

No props of its own.

Indicator

No props of its own.

State and part attributes

No state attribute: a meter has a value and nothing else.

partattributes
Rootrole="meter", aria-valuemin, aria-valuemax, aria-valuenow (the clamped value), aria-valuetext (the formatted value, or getAriaValueText's), aria-labelledby (the Label, while one is rendered)
Labelid
Indicatorstructural inline style: inset-inline-start: 0, inline-size: <percent>% and --meter-indicator-size: <percent>%

Keyboard

None: a meter is not focusable.

Exports

entryexports
@fragiola/primitives-react/meterMeter, MeterIndicatorProps, MeterLabelProps, MeterRootProps, MeterState, MeterTrackProps, MeterValueProps, RenderProp
@fragiola/primitives-vue/meterMeter, MeterLabelProps, MeterRootProps, MeterState, MeterValueSlotProps, MeterValueSlots, RenderSlotProps
@fragiola/primitives-angular/meterMeterIndicator, MeterLabel, MeterRoot, MeterState, MeterTrack, MeterValue