Progress bar
A linear bar for one value on a fixed scale, with the value written beside it: an upload, an import, steps done. Use it for work that moves towards an end and finishes. For a quota with thresholds, use the usage meter; for a compact round figure, the ring meter.
Install
npx shadcn@latest add https://thrumui.dev/r/progress-bar.jsonAdds components/ui/progress-bar.tsx and installs motion. Nothing else in your project changes.
import { ProgressBar } from "@/components/ui/progress-bar";Props
| Prop | Type | Default | Description |
|---|---|---|---|
value | number | null | Required | The reading, in the unit of the scale. null means there is no reading yet: the frame and the scale stay, the fill does not, and the number is a dash. |
label | string | Required | What is in progress. Shown above the bar and used as the name screen readers hear. |
min | number | Default 0 | The low end of the scale. A reading below it leaves the bar empty; the number still shows the real reading. |
max | number | Default 100 | The high end of the scale. A reading at or above it fills the bar and reads “Complete”; the number still shows the real reading. |
format | Intl.NumberFormatOptions | Default compact | How the value is written, for example { style: "unit", unit: "percent" }. Pass a unit: a bare number does not say what it counts. |
locale | string | Default "en-US" | Locale for number formatting. |
sound | boolean | Default true | Play a two-note rise when the reading reaches max, if the visitor has sound on. |
className | string | – | Sets the width. The bar fills the width it is given. |
Motion and sound
Motion
- First draw: when the bar scrolls into view, the fill grows from the low end in about 400 ms and the number rolls up from the low end of the scale with it.
- A new value moves the fill and the number from where they are, with no overshoot. A change during a move continues from the current position.
- Only the fill moves. The column for the number is as wide as the wider end of the scale, so the track keeps its length while the number changes.
- Reaching the maximum changes the fill colour and shows the lamp and the word at once. They are steps, so they do not fade.
- Reduced motion: the fill and the number appear at their value and change instantly.
Sound
- A two-note rise when a change takes the reading from below the maximum up to it. It plays once per arrival. Nothing plays when the bar first appears, for the first reading it is given, or on the way down.
Sound is off until the visitor turns it on. Pass sound={false} to keep this component silent. How sound works
Accessibility
- Exposed as a progress bar named by the label, with the minimum, the maximum and the current value. The spoken value is the formatted reading, for example “72%”, and “100%, complete” at the maximum.
- With no reading the bar has no current value, which assistive technology treats as progress of unknown length, and the spoken value is “No data”.
- Complete is a lamp and a word as well as a colour.
- A reading outside the scale is clamped for the bar and for the current value. The number on screen and the spoken value keep the real reading.
- It is not focusable: there is nothing to operate. The word “Complete” and the spoken “No data” are in English and fixed in this version.
Source
"use client";
import { useEffect, useRef } from "react";
import { motion, useInView } from "motion/react";
import { cn } from "@/lib/utils";
import { STATUS, formatValue } from "@/lib/thrum-chart";
import { INSTANT, SPRING, useReducedMotion } from "@/lib/thrum-motion";
import { play } from "@/lib/thrum-sound";
import { AnimatedNumber } from "@/components/ui/animated-number";
export type ProgressBarProps = {
/** The reading, in the unit of the scale. `null` means there is no reading yet. */
value: number | null;
/** What is in progress. Shown above the bar and read by screen readers. Example: "Upload". */
label: string;
/** The low end of the scale. A reading below it leaves the bar empty. */
min?: number;
/** The high end of the scale. A reading at or above it fills the bar and reads "Complete". */
max?: number;
/** How the value is written. Example: `{ style: "unit", unit: "percent" }`. */
format?: Intl.NumberFormatOptions;
locale?: string;
/** Play a two-note rise when the reading reaches `max`, if the visitor has sound on. */
sound?: boolean;
/** Size it with classes. The bar fills the width it is given. */
className?: string;
};
const isNum = (v: unknown): v is number => typeof v === "number" && Number.isFinite(v);
// A graduation under the track at every tenth of the scale. Both ends and the middle are longer.
const TICKS = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10];
/**
* A linear bar for one value on a fixed scale, with the value written beside it.
* The fill grows to the reading and never passes it. Reaching the maximum lights a lamp beside the word "Complete".
*/
export function ProgressBar({ value, label, min = 0, max = 100, format, locale, sound = true, className }: ProgressBarProps) {
const ref = useRef<HTMLDivElement>(null);
const reduced = useReducedMotion();
// The fill waits until the bar is on screen, so it grows together with the number's first roll.
const inView = useInView(ref, { once: true });
const say = (v: number) => formatValue(v, format, locale);
const known = isNum(value);
const span = max - min;
// A reading past either end pins the fill at that end. The number still shows the real reading.
const share = known && span > 0 ? Math.max(0, Math.min(1, (value - min) / span)) : 0;
const done = known && span > 0 && value >= max;
// With reduced motion there is no growth to wait for: the fill is there at once, on screen or not.
const filled = inView || reduced ? share : 0;
// One sound for a change that takes the reading up to the maximum. Never for the first reading, never on the way down.
const before = useRef<boolean | null>(null);
useEffect(() => {
if (!known) return;
if (sound && done && before.current === false) play("success");
before.current = done;
}, [known, done, sound]);
return (
<div
ref={ref}
data-slot="progress-bar"
role="progressbar"
aria-label={label}
aria-valuemin={min}
aria-valuemax={max}
aria-valuenow={known ? Math.max(min, Math.min(max, value)) : undefined}
aria-valuetext={known ? `${say(value)}${done ? ", complete" : ""}` : "No data"}
className={cn("w-full text-sm tabular-nums", className)}
>
<div className="flex flex-wrap items-baseline justify-between gap-x-3 gap-y-1">
<span className="min-w-0 text-[11px] leading-4 font-medium tracking-[0.08em] break-words text-muted-foreground uppercase">{label}</span>
<span className="flex flex-none items-center gap-2">
{/* The finished state is a lamp and a word, so it is never carried by the colour of the fill alone. */}
{done && (
<span className="inline-flex items-center gap-1.5 text-xs leading-4 font-medium">
<span className="size-[7px] flex-none rounded-full" style={{ backgroundColor: STATUS.ok }} />
Complete
</span>
)}
<span className="inline-grid justify-items-end text-sm leading-4 font-medium whitespace-nowrap text-foreground">
{/* Invisible copies of both ends of the scale hold the column width while the number rolls. */}
<span aria-hidden="true" className="invisible [grid-area:1/1]">
{say(min)}
</span>
<span aria-hidden="true" className="invisible [grid-area:1/1]">
{say(max)}
</span>
<span className="[grid-area:1/1]">{known ? <AnimatedNumber value={value} from={min} format={format} locale={locale} sound={false} /> : formatValue(null)}</span>
</span>
</span>
</div>
<div className="mt-2">
<div className="h-3 rounded-[min(var(--radius),3px)] border border-foreground/20 bg-foreground/12 p-0.5">
<div className="h-full overflow-hidden rounded-[min(var(--radius),1px)]">
{/* A full-width bar slid in from the left: only a transform moves, and the value end keeps its corners. */}
<motion.div
className="h-full rounded-r-[min(var(--radius),2px)]"
style={{ backgroundColor: done ? STATUS.ok : STATUS.normal }}
initial={reduced ? false : { x: "-100%" }}
animate={{ x: `${Math.round((filled - 1) * 10000) / 100}%` }}
transition={reduced ? INSTANT : SPRING.data}
/>
</div>
</div>
{/* The scale. It is inset by the frame, so each graduation stands exactly where the fill ends at that tenth. */}
<div aria-hidden="true" className="mx-[3px] mt-1 flex h-1.5 justify-between">
{TICKS.map((tick) => (
<span key={tick} className={cn("w-px", tick % 5 === 0 ? "h-full bg-foreground/55" : "h-1/2 bg-foreground/30")} />
))}
</div>
</div>
</div>
);
}Files and dependencies
- Adds
components/ui/progress-bar.tsx- Packages
motion- Brings along
- Chart foundationsMotion tokensSound engineAnimated number
Changelog
- 1.0.1 · 2026-12-03Corners follow the project's --radius, down to square.
- 1.0.0 · 2026-12-03First release.