Meter
Shows a quantity within a known range, such as disk usage
Usage
import {Label, Meter} from "@peakui/react";Anatomy
import {Label, Meter} from "@peakui/react";
export default () => (
<Meter value={60}>
<Label />
<Meter.Output />
<Meter.Track>
<Meter.Fill />
</Meter.Track>
</Meter>
);A meter shows where a value sits within a known range (storage used, a score). For the progress of a task that finishes, use ProgressBar.
Examples
Sizes
Colors
Without Label
Without a visible Label, aria-label names the meter.
Custom Value
minValue, maxValue and formatOptions set the range and the display format.
Customization
Tailwind CSS
Global CSS
@layer components {
.meter__track {
@apply h-3 rounded-full;
}
.meter__fill {
@apply rounded-full;
}
.meter--success {
--meter-fill: var(--color-success);
}
}Styling Reference
PeakUI follows the BEM methodology, so variants and states are plain class names you can target.
CSS Classes
The Meter component uses these CSS classes (view source styles):
Base & Element Classes
.meter- Base container (grid layout).meter__output- Value text display.meter__track- Track background.meter__fill- Filled portion of the track
Size Classes
.meter--sm- Small size, thinner track.meter--md- Medium size, the default.meter--lg- Large size, thicker track
Color Classes
.meter--default.meter--accent.meter--success.meter--warning.meter--danger
Slots
[data-slot="meter"][data-slot="meter-output"][data-slot="meter-track"][data-slot="meter-fill"]
CSS Variables
| Variable | Purpose |
|---|---|
--meter-fill | Fill color, set by the color classes |
Interactive States
The component supports both CSS pseudo-classes and data attributes:
- Disabled:
:disabled,[data-disabled="true"]or[aria-disabled="true"]
API Reference
Meter
| Prop | Type | Default | Description |
|---|---|---|---|
value | number | 0 | The current value |
minValue | number | 0 | The smallest value |
maxValue | number | 100 | The largest value |
formatOptions | Intl.NumberFormatOptions | {style: 'percent'} | Display format of the value |
valueLabel | ReactNode | - | Text announced as the value, such as "2 of 5" |
color | 'default' | 'accent' | 'success' | 'warning' | 'danger' | 'accent' | Color of the fill |
size | 'sm' | 'md' | 'lg' | 'md' | Height of the track |
children | ReactNode | (values: MeterRenderProps) => ReactNode | - | Content, or a function of the render props |
className | string | (values: MeterRenderProps) => string | - | Additional classes, or a function of the render props |
...rest | Every React Aria Meter attribute is accepted, including aria-label |
Meter.Output
| Prop | Type | Default | Description |
|---|---|---|---|
children | ReactNode | formatted value | Replaces the formatted value |
className | string | - | Additional classes |
render | DOMRenderFunction<E, undefined> | - | Replaces the rendered element; E defaults to 'span' |
...rest | Every <span> attribute is accepted |
Meter.Track
| Prop | Type | Default | Description |
|---|---|---|---|
children | ReactNode | - | Holds Meter.Fill |
className | string | - | Additional classes |
render | DOMRenderFunction<E, undefined> | - | Replaces the rendered element; E defaults to 'div' |
...rest | Every <div> attribute is accepted |
Meter.Fill
| Prop | Type | Default | Description |
|---|---|---|---|
children | ReactNode | - | Content inside the fill |
className | string | - | Additional classes |
style | CSSProperties | - | Merged under the computed width |
render | DOMRenderFunction<E, undefined> | - | Replaces the rendered element; E defaults to 'div' |
...rest | Every <div> attribute is accepted |
Render Props
| Prop | Type | Description |
|---|---|---|
percentage | number | undefined | The value as a percentage between minValue and maxValue |
valueText | string | undefined | The formatted value |