Usage Meter
Token, credit or quota usage on a real <meter>, the HTML element for "a measurement within a known range". Not a<progress>: usage isn't a task heading for completion, and <meter>'s low,high and optimum attributes already say "this much is fine, this much is a warning".
Resets on the 1st.
Bands
The colour follows the same region algorithm the browser uses for<meter>, so it always agrees with what assistive tech is told. optimum defaults to min, because for usage less is better: above high the bar turns to warning, and with low set too, thelow–high band is the warning and abovehigh is danger. A full meter is always danger.usageMeterLevel() is exported if you need the same answer elsewhere.
The native bar is restyled with ::-webkit-meter-* and::-moz-meter-bar, since there's no standard, unprefixed way yet, reading tokens only.
Examples
Warning
Above high, with optimum at the default min.
Usage
<UsageMeter
label="Context window"
value={172_000}
max={200_000}
high={160_000}
unit="tokens"
/>More is better
optimum at max flips the bands.
Usage
<UsageMeter
label="Battery"
value={82}
max={100}
low={20}
high={50}
optimum={100}
formatValue={(value) => `${value}%`}
/>Playground
Toggle every adjustable prop and watch the component — and the code — update live.
Usage
<UsageMeter
label="Context window"
value={128000}
max={200000}
high={160000}
unit="tokens"
/><kernel-usage-meter
label="Context window"
value="128000"
max="200000"
high="160000"
unit="tokens"
></kernel-usage-meter>Props
| Prop | Type | Default |
|---|---|---|
label | ReactNode (required) | — |
hideLabel | boolean | false |
value | number (required) | — |
min | number | 0 |
max | number (required) | — |
low / high | number | — |
optimum | number | min |
unit | string | — |
locale | string | the reader's |
formatValue | (value, max) => string | "12,340 / 200,000 tokens" |
description | ReactNode | — |
className / wrapperClassName | on the meter / the wrapper | — |
Accessibility
- The label is a real
<label for>:<meter>is a labelable element. - The formatted text is the meter's
aria-valuetext, so it's read with its unit; the visible copy isaria-hiddenso it isn't read twice. - Colour is never the only signal: the value text is always shown.