Progress Bar
FreeNewA linear bar that fills with a transform, with a formatted value and a sweep for an unknown total.
Installation
pnpm dlx shadcn@latest add @viewport/progress-bar
First time? Add the @viewport registry to components.json. Setup takes one minute.
Usage
The code behind the preview above.
"use client";
import { useEffect, useState } from "react";
import { ProgressBar } from "@/components/viewport/progress-bar";
export default function ProgressBarDemo() {
const [done, setDone] = useState(3);
useEffect(() => {
const timer = setInterval(() => setDone((n) => (n >= 12 ? 0 : n + 1)), 900);
return () => clearInterval(timer);
}, []);
return (
<div className="flex w-full max-w-sm flex-col gap-6 rounded-2xl border border-border bg-card p-5">
<ProgressBar value={done} max={12} label="Importing contacts" showLabel formatValue={(v, max) => `${v} of ${max} files`} />
<ProgressBar value={86} label="Storage used" showLabel tone="warning" formatValue={(v) => `${v}% of 50 GB`} />
<ProgressBar value={null} label="Preparing export" showLabel size="sm" />
</div>
);
}Props
| Prop | Type | Default |
|---|---|---|
| value* | number | nullThe current amount. Pass `null` when the total is unknown; the bar then sweeps instead of filling. | — |
| max | number | 100 |
| label* | stringWhat is in progress, e.g. "Uploading". It names the bar for screen readers. | — |
| showLabel | booleanShow the label and the value above the bar. | false |
| formatValue | (value: number, max: number) => stringTurns the value into text, e.g. `(v, max) => `${v} of ${max} files``. Defaults to a percentage. | (v, m) => `${Math.round((v / m) * 100)}%` |
| tone | keyof typeof tones | "default" |
| size | "sm" | "md" | "md" |
| className | string | — |
Accessibility
- Built on Radix Progress with role=progressbar and a value text you format.
- An unknown total is exposed as indeterminate rather than as a made-up number.
- Mirrors in right-to-left layouts.
- Respects prefers-reduced-motion.