Overview
Get Started
Storage usage75%
x
import {
Meter,
MeterIndicator,
MeterLabel,
MeterTrack,
MeterValue,
} from "@/components/ui/meter";
export function MeterDemo() {
return (
<Meter value={75} className="max-w-xs">
<div className="flex items-center justify-between gap-2">
<MeterLabel>Storage usage</MeterLabel>
<MeterValue />
</div>
<MeterTrack>
<MeterIndicator />
</MeterTrack>
</Meter>
);
}Installation
import { Meter as MeterPrimitive } from "@base-ui/react/meter";
import { cn } from "@/lib/cn";
export function Meter({
children,
className,
...props
}: React.ComponentProps<typeof MeterPrimitive.Root>) {
return (
<MeterPrimitive.Root
data-slot="meter"
className={cn("flex w-full flex-col gap-2", className)}
{...props}
>
{children ? (
children
) : (
<MeterTrack>
<MeterIndicator />
</MeterTrack>
)}
</MeterPrimitive.Root>
);
}
export function MeterLabel({
className,
...props
}: React.ComponentProps<typeof MeterPrimitive.Label>) {
return (
<MeterPrimitive.Label
data-slot="meter-label"
className={cn("font-medium text-foreground text-sm", className)}
{...props}
/>
);
}
export function MeterTrack({
className,
...props
}: React.ComponentProps<typeof MeterPrimitive.Track>) {
return (
<MeterPrimitive.Track
data-slot="meter-track"
className={cn("block h-1.5 w-full overflow-hidden rounded-full bg-input", className)}
{...props}
/>
);
}
export function MeterIndicator({
className,
...props
}: React.ComponentProps<typeof MeterPrimitive.Indicator>) {
return (
<MeterPrimitive.Indicator
data-slot="meter-indicator"
className={cn("bg-primary transition-all duration-500", className)}
{...props}
/>
);
}
export function MeterValue({
className,
...props
}: React.ComponentProps<typeof MeterPrimitive.Value>) {
return (
<MeterPrimitive.Value
data-slot="meter-value"
className={cn("text-foreground text-sm tabular-nums", className)}
{...props}
/>
);
}
export { MeterPrimitive };Usage
import { Meter, MeterLabel, MeterValue } from "@/components/ui/meter";<Meter value={40}>
<MeterLabel>Progress</MeterLabel>
<MeterValue />
</Meter>Examples
Without label
x
import { Meter } from "@/components/ui/meter";
export function MeterDemo() {
return <Meter value={75} className="max-w-xs" />;
}Formatted value
Rating3 / 5
x
"use client";
import {
Meter,
MeterIndicator,
MeterLabel,
MeterTrack,
MeterValue,
} from "@/components/ui/meter";
const MAX = 5;
export function MeterDemo() {
return (
<Meter max={MAX} value={3} className="max-w-xs">
<div className="flex items-center justify-between gap-2">
<MeterLabel>Rating</MeterLabel>
<MeterValue>{(_formatted, value) => `${value} / ${MAX}`}</MeterValue>
</div>
<MeterTrack>
<MeterIndicator />
</MeterTrack>
</Meter>
);
}