Meter
How much of something on a fixed scale, such as password strength. Not a loading or step indicator: for loading, use a Spinner.
Installation
bun add @harmo-ui/css @harmo-ui/reactnpm install @harmo-ui/css @harmo-ui/reactpnpm add @harmo-ui/css @harmo-ui/reactyarn add @harmo-ui/css @harmo-ui/reactbunx harmo-ui add meternpx harmo-ui add meterpnpm dlx harmo-ui add meteryarn dlx harmo-ui add meterUsage
import { Meter } from "@harmo-ui/react";
<Meter
value={1}
max={3}
status="error"
aria-label="Password strength"
aria-valuetext="Too weak"
/>Examples
Password strength
Too weak, medium, and strong. data-filled fills a segment and data-status colors the filled ones; without it they are gray. role="meter" and its aria-value* attributes give screen readers the value, such as "Password strength, Medium".
Other scales
Use as many segments as the scale has steps. warning and info color the fill too.
API reference
React
<Meter> renders the meter, one segment per step, and sets role and the aria-value* attributes from its value. Name it with aria-label, and put the value in words with aria-valuetext. Other props are the <div>'s attributes.
| Prop | Effect |
|---|---|
value | How many segments are filled |
max | How many segments there are |
status | success, warning, info, or error; gray when left out |
HTML
A <div class="hmeter" role="meter"> with one .hmeter-segment per step of the scale, and aria-label, aria-valuemin, aria-valuemax, and aria-valuenow; aria-valuetext when the number alone means little. The meter is only the bar: words such as "Too weak", hints, and when to show it belong to the component using it, such as Password input. Load meter.css.
| Hook | Effect |
|---|---|
data-filled on a segment | Filled |
(no data-status) | Filled segments in --harmo-color-text-tertiary (gray) |
data-status="success" | Filled segments in --harmo-status-color-success (green) |
data-status="warning" | Filled segments in --harmo-status-color-warning (amber) |
data-status="info" | Filled segments in --harmo-status-color-info (cyan) |
data-status="error" | Filled segments in --harmo-status-color-error (red) |
hidden | Hides the meter, for example until a password has been typed |
It needs a script to change the value. See Meter's full contract.
Accessibility
role="meter" and its aria-value* attributes give screen readers the value, for example "Password strength, Medium".