Meter
A meter displaying a value within a known range
Installation
bunx @prototyperco/cli add meterpnpm dlx shadcn@latest add https://prototyper-ui.com/r/meter.jsonnpx shadcn@latest add https://prototyper-ui.com/r/meter.jsonyarn dlx shadcn@latest add https://prototyper-ui.com/r/meter.jsonbunx --bun shadcn@latest add https://prototyper-ui.com/r/meter.jsonThis will add the following files to your project:
components/ui/meter.tsx
Usage
import {
Meter,
MeterTrack,
MeterIndicator,
MeterLabel,
MeterValue,
} from "@/components/ui/meter";
<Meter value={60}>
<MeterLabel>Storage</MeterLabel>
<MeterTrack>
<MeterIndicator />
</MeterTrack>
</Meter>;Anatomy
<Meter>
<MeterLabel />
<MeterValue />
<MeterTrack>
<MeterIndicator />
</MeterTrack>
</Meter>| Sub-component | data-slot | Purpose | Required |
|---|---|---|---|
Meter | meter | Root provider, manages value state | Yes |
MeterTrack | meter-track | Background track for the indicator | Yes |
MeterIndicator | meter-indicator | Filled portion representing the value | Yes |
MeterLabel | meter-label | Accessible label for the meter | No |
MeterValue | meter-value | Displays the current value as text | No |
Examples
Custom Format
Reusable
Value Format
Styling
Data Slots
Use data-slot attributes to target specific parts of the meter:
| Slot name | Element |
|---|---|
meter | Root wrapper |
meter-track | Background track bar |
meter-indicator | Filled indicator bar |
meter-label | Label text |
meter-value | Value text |
Customization Examples
/* Make the meter track taller */
[data-slot="meter-track"] {
@apply h-4 rounded-lg;
}
/* Custom indicator color */
[data-slot="meter-indicator"] {
@apply bg-gradient-to-r from-blue-500 to-purple-500;
}{
/* Override track color via className */
}
<MeterTrack className="bg-blue-100" color="default">
<MeterIndicator className="bg-blue-500" />
</MeterTrack>;API Reference
Meter
Root component that provides meter value context.
Prop
Type
All Base UI Meter.Root props are forwarded via ...props.
MeterTrack
Background track that contains the indicator.
Prop
Type
All Base UI Meter.Track props are forwarded via ...props.
MeterIndicator
The filled portion of the track representing the current value.
Prop
Type
All Base UI Meter.Indicator props are forwarded via ...props.
MeterLabel
Accessible label for the meter.
Prop
Type
All Base UI Meter.Label props are forwarded via ...props.
MeterValue
Displays the current meter value as formatted text.
Prop
Type
All Base UI Meter.Value props are forwarded via ...props.
meterTrackVariants
A cva helper exported for applying meter track styles outside of the <MeterTrack> component.
import { meterTrackVariants } from "@/components/ui/meter";
<div className={meterTrackVariants({ color: "success", size: "lg" })}>
Custom track
</div>;meterIndicatorVariants
A cva helper exported for applying meter indicator styles outside of the <MeterIndicator> component.
import { meterIndicatorVariants } from "@/components/ui/meter";
<div className={meterIndicatorVariants({ color: "warning" })}>
Custom indicator
</div>;Accessibility
Keyboard Interactions
The meter is a non-interactive display element and does not have keyboard interactions. Focus management is handled by surrounding interactive elements.
ARIA Attributes
- The meter renders with
role="meter"via the Base UI primitive. aria-valuenowreflects the current value.aria-valueminandaria-valuemaxdefine the range.aria-labelledbyis automatically linked toMeterLabelwhen present.- Screen readers announce the meter value and its label.