Progress
The shadcn/ui Progress bar with a spring-animated indicator and an indeterminate loading state — plus three animated React progress blocks built with Motion and Radix: a circular progress ring with a counting number, a multi-step stepper and a segmented progress bar for chunked uploads.
- Drop-in shadcn API
- Radix Progress
- Spring physics
- prefers-reduced-motion
"use client";
import * as React from "react";
import { Shuffle } from "lucide-react";
import { Button } from "@/components/ui/button";
import { CircularProgress } from "@/components/dusk/progress/circular-progress";
export default function CircularProgressDemo() {
const [values, setValues] = React.useState([72, 45, 90]);
return (
<div className="flex flex-col items-center gap-6">
<div className="flex flex-wrap items-center justify-center gap-8">
<CircularProgress value={values[0]} caption="Storage" aria-label="Storage used" />
<CircularProgress
value={values[1]}
size={96}
strokeWidth={8}
caption="Tasks"
aria-label="Tasks done"
indicatorClassName="text-foreground"
/>
<CircularProgress
value={values[2]}
size={72}
strokeWidth={6}
aria-label="Profile complete"
/>
</div>
<Button
variant="outline"
size="sm"
onClick={() => setValues(values.map(() => Math.round(Math.random() * 100)))}
>
<Shuffle />
Shuffle
</Button>
</div>
);
}Installation
$ npx shadcn@latest add https://duskui.com/r/progress.json1. Install the dependencies.
npm install @radix-ui/react-progress motion2. Copy the source into
components/ui/progress.tsx.progress.tsx "use client" import * as React from "react" import * as ProgressPrimitive from "@radix-ui/react-progress" import { motion, useReducedMotion, type Transition } from "motion/react" import { cn } from "@/lib/utils" const fill: Transition = { type: "spring", duration: 0.4, bounce: 0 } /** * DuskUI Progress — a drop-in upgrade of the shadcn/ui Progress. * * Same API as shadcn (`value`, `max` and the Radix props) plus: * - The indicator eases to each new value (no overshoot), and fills in from * empty when it mounts. * - An indeterminate state: pass `value={null}` (or leave it out) and a * short bar slides across the track. Under reduced motion it gently pulses * instead. * - A solid indicator in the primary color. * - `indicatorClassName` to recolor the bar without touching the track. * Powered by Radix Progress, so role="progressbar" and the aria-value* attributes are set. */ function Progress({ className, indicatorClassName, value, max = 100, ...props }: React.ComponentProps<typeof ProgressPrimitive.Root> & { /** Classes for the moving bar, e.g. a different color. */ indicatorClassName?: string }) { const reduceMotion = useReducedMotion() ?? false const indeterminate = value === null || value === undefined const percent = indeterminate ? 0 : Math.min(100, Math.max(0, (value / max) * 100)) return ( <ProgressPrimitive.Root data-slot="progress" value={value} max={max} className={cn("relative h-2 w-full overflow-hidden rounded-full bg-primary/15", className)} {...props} > <ProgressPrimitive.Indicator data-slot="progress-indicator" asChild> {indeterminate ? ( <motion.div key="indeterminate" className={cn( "h-full w-2/5 rounded-full bg-primary", indicatorClassName )} initial={reduceMotion ? { opacity: 0.4 } : { x: "-100%" }} animate={reduceMotion ? { opacity: [0.4, 1, 0.4] } : { x: "250%" }} transition={{ duration: reduceMotion ? 1.6 : 1.3, ease: "easeInOut", repeat: Infinity, }} /> ) : ( <motion.div key="determinate" className={cn( "h-full w-full rounded-full bg-primary", indicatorClassName )} initial={{ x: "-100%" }} animate={{ x: `${percent - 100}%` }} transition={reduceMotion ? { duration: 0 } : fill} /> )} </ProgressPrimitive.Indicator> </ProgressPrimitive.Root> ) } export { Progress }
Replaces components/ui/progress.tsx with the same API, plus indicatorClassName. Following Radix, a missing or null value now means indeterminate; pass value={0} for an empty bar.
Usage
import { Progress } from "@/components/ui/progress"
export function UploadStatus({ percent }: { percent: number }) {
return <Progress value={percent} aria-label="Upload progress" />
}Examples
Default
The bar fills in from empty when it mounts and springs to every new value, so quick jumps settle naturally instead of snapping. Use the buttons to change it.
"use client";
import * as React from "react";
import { Button } from "@/components/ui/button";
import { Progress } from "@/components/ui/progress";
export default function ProgressBasicDemo() {
const [value, setValue] = React.useState(18);
React.useEffect(() => {
const timer = window.setTimeout(() => setValue(64), 600);
return () => window.clearTimeout(timer);
}, []);
return (
<div className="flex w-full max-w-sm flex-col gap-4">
<div className="flex items-center justify-between text-sm">
<span id="progress-basic-label" className="font-medium">Syncing files</span>
<span className="text-muted-foreground tabular-nums">{value}%</span>
</div>
<Progress value={value} aria-labelledby="progress-basic-label" />
<div className="flex justify-end gap-2">
<Button variant="outline" size="sm" onClick={() => setValue((v) => Math.max(0, v - 15))}>
−15
</Button>
<Button variant="outline" size="sm" onClick={() => setValue((v) => Math.min(100, v + 15))}>
+15
</Button>
</div>
</div>
);
}Indeterminate
When you don't know how long something will take, pass value={null} and a highlight sweeps across the track. Radix sets data-state="indeterminate" and leaves out aria-valuenow.
import { Progress } from "@/components/ui/progress";
export default function ProgressIndeterminateDemo() {
return (
<div className="flex w-full max-w-sm flex-col gap-3">
<span id="progress-indeterminate-label" className="text-sm font-medium">Preparing your export…</span>
<Progress value={null} aria-labelledby="progress-indeterminate-label" />
</div>
);
}Blocks
Ready-made variations composed from the base component with Motion. Each installs on its own and pulls in its dependencies automatically.
Circular Progress
An SVG ring that springs to its value while the number in the middle counts along. Both are driven by one spring motion value, so they never drift apart and React doesn't re-render per frame. Recolor it with text-* classes on the indicator and track.
"use client";
import * as React from "react";
import { Shuffle } from "lucide-react";
import { Button } from "@/components/ui/button";
import { CircularProgress } from "@/components/dusk/progress/circular-progress";
export default function CircularProgressDemo() {
const [values, setValues] = React.useState([72, 45, 90]);
return (
<div className="flex flex-col items-center gap-6">
<div className="flex flex-wrap items-center justify-center gap-8">
<CircularProgress value={values[0]} caption="Storage" aria-label="Storage used" />
<CircularProgress
value={values[1]}
size={96}
strokeWidth={8}
caption="Tasks"
aria-label="Tasks done"
indicatorClassName="text-foreground"
/>
<CircularProgress
value={values[2]}
size={72}
strokeWidth={6}
aria-label="Profile complete"
/>
</div>
<Button
variant="outline"
size="sm"
onClick={() => setValues(values.map(() => Math.round(Math.random() * 100)))}
>
<Shuffle />
Shuffle
</Button>
</div>
);
}$ npx shadcn@latest add https://duskui.com/r/circular-progress.json1. Install the dependencies.
npm install motion @radix-ui/react-progress2. Copy the source into
components/dusk/progress/circular-progress.tsx.circular-progress.tsx "use client"; import * as React from "react"; import * as ProgressPrimitive from "@radix-ui/react-progress"; import { motion, useReducedMotion, useSpring, useTransform } from "motion/react"; import { cn } from "@/lib/utils"; const ringSpring = { stiffness: 90, damping: 20, mass: 0.8 }; export interface CircularProgressProps extends Omit<React.ComponentProps<typeof ProgressPrimitive.Root>, "value" | "max" | "children"> { /** Current value, from 0 to `max`. */ value: number; max?: number; /** Diameter in pixels. */ size?: number; /** Ring thickness in pixels. */ strokeWidth?: number; /** Show the animated number in the middle. */ showValue?: boolean; /** Formats the number in the middle (it counts up with the ring). Defaults to a whole percentage. */ formatValue?: (value: number, max: number) => string; /** Small caption under the number, e.g. "Uploaded". */ caption?: React.ReactNode; /** Classes for the progress arc (use `text-*` to recolor it). */ indicatorClassName?: string; /** Classes for the background track (use `text-*` to recolor it). */ trackClassName?: string; } /** * A ring that springs to its value while the number in the middle counts * along with it. The arc and the number are driven by the same spring motion * value, so they never drift apart and nothing re-renders per frame. Built on * Radix Progress, so it's a real `progressbar` with aria-valuenow/-max and a * readable value label. Jumps straight to the value under reduced motion. */ export function CircularProgress({ value, max = 100, size = 120, strokeWidth = 10, showValue = true, formatValue, caption, indicatorClassName, trackClassName, className, style, getValueLabel, ...props }: CircularProgressProps) { const reduceMotion = useReducedMotion() ?? false; const clamped = Math.min(max, Math.max(0, value)); const progress = useSpring(0, ringSpring); React.useEffect(() => { const target = max > 0 ? clamped / max : 0; if (reduceMotion) progress.jump(target); else progress.set(target); }, [clamped, max, reduceMotion, progress]); // A round line cap draws a dot even at 0, so hide the arc until there's something to show. const arcOpacity = useTransform(progress, (p) => (p > 0.002 ? 1 : 0)); const label = useTransform(progress, (p) => formatValue ? formatValue(p * max, max) : `${Math.round(p * 100)}%` ); const radius = (size - strokeWidth) / 2; const center = size / 2; return ( <ProgressPrimitive.Root value={clamped} max={max} getValueLabel={getValueLabel ?? ((v, m) => `${Math.round((v / m) * 100)}%`)} className={cn("relative inline-grid shrink-0 place-items-center", className)} style={{ width: size, height: size, ...style }} {...props} > <svg aria-hidden width={size} height={size} viewBox={`0 0 ${size} ${size}`} className="col-start-1 row-start-1 -rotate-90 overflow-visible" > <circle cx={center} cy={center} r={radius} fill="none" strokeWidth={strokeWidth} className={cn("stroke-current text-muted", trackClassName)} /> <motion.circle cx={center} cy={center} r={radius} fill="none" strokeWidth={strokeWidth} strokeLinecap="round" className={cn("stroke-current text-primary", indicatorClassName)} style={{ pathLength: progress, opacity: arcOpacity }} /> </svg> {showValue && ( <span aria-hidden className="col-start-1 row-start-1 flex flex-col items-center justify-center text-center leading-none" > <motion.span className="font-semibold tracking-tight tabular-nums" style={{ fontSize: Math.max(12, size * 0.2) }} > {label} </motion.span> {caption && ( <span className="mt-1.5 text-muted-foreground" style={{ fontSize: Math.max(10, size * 0.09) }}> {caption} </span> )} </span> )} </ProgressPrimitive.Root> ); }
| Prop | Type | Default | Description |
|---|---|---|---|
| value | number | — | Current value, 0 to max. Required. |
| max | number | 100 | Maximum value. |
| size | number | 120 | Diameter in pixels. |
| strokeWidth | number | 10 | Ring thickness in pixels. |
| showValue | boolean | true | Show the counting number. |
| formatValue | (value: number, max: number) => string | — | Formats the number. Defaults to a whole percentage. |
| caption | ReactNode | — | Small text under the number. |
| indicatorClassName / trackClassName | string | — | Classes for the arc and the track (use text-*). |
Stepper Progress
A stepper for onboarding, checkout or any multi-step form. Connectors fill with a spring as you advance, finished steps draw a check mark and the current step is outlined. Set current to steps.length to mark everything complete.
- Account (completed)
- Workspace (current step)
- Invite (not started)
- Launch (not started)
"use client";
import * as React from "react";
import { Button } from "@/components/ui/button";
import { StepperProgress } from "@/components/dusk/progress/stepper-progress";
const steps = [
{ title: "Account", description: "Email & password" },
{ title: "Workspace", description: "Name your team" },
{ title: "Invite", description: "Add teammates" },
{ title: "Launch", description: "You're live" },
];
export default function StepperProgressDemo() {
const [current, setCurrent] = React.useState(1);
return (
<div className="flex w-full max-w-xl flex-col gap-8">
<StepperProgress steps={steps} current={current} label="Onboarding progress" />
<div className="flex justify-center gap-2">
<Button variant="outline" size="sm" onClick={() => setCurrent((c) => Math.max(0, c - 1))} disabled={current === 0}>
Back
</Button>
<Button size="sm" onClick={() => setCurrent((c) => Math.min(steps.length, c + 1))} disabled={current === steps.length}>
{current >= steps.length - 1 ? "Finish" : "Next"}
</Button>
</div>
</div>
);
}$ npx shadcn@latest add https://duskui.com/r/stepper-progress.json1. Install the dependencies.
npm install motion2. Copy the source into
components/dusk/progress/stepper-progress.tsx.stepper-progress.tsx "use client"; import * as React from "react"; import { AnimatePresence, motion, useReducedMotion, type Transition } from "motion/react"; import { cn } from "@/lib/utils"; const fill: Transition = { type: "spring", stiffness: 120, damping: 22 }; const pop: Transition = { type: "spring", duration: 0.25, bounce: 0.1 }; export type StepperStep = { /** Short step name shown under the marker. */ title: string; /** Optional second line. */ description?: string; }; export interface StepperProgressProps extends Omit<React.ComponentProps<"ol">, "children"> { steps: (StepperStep | string)[]; /** Index of the step in progress. Steps before it are complete; `steps.length` means all done. */ current: number; /** Accessible name for the list, e.g. "Checkout progress". */ label?: string; } function Check({ instant }: { instant: boolean }) { return ( <svg aria-hidden viewBox="0 0 24 24" className="size-4" fill="none" stroke="currentColor" strokeWidth={3} strokeLinecap="round" strokeLinejoin="round"> <motion.path d="M5 12.5l4.5 4.5L19 7.5" initial={{ pathLength: instant ? 1 : 0 }} animate={{ pathLength: 1 }} transition={instant ? { duration: 0 } : { duration: 0.35, ease: "easeOut", delay: 0.1 }} /> </svg> ); } /** * A horizontal stepper for multi-step flows. Connectors fill with a spring as * you advance, completed markers draw a check mark, and the current marker * is outlined in the primary color. Semantically an ordered list with * `aria-current="step"` on the active step and the state of each step spelled * out for screen readers. Static under reduced motion. */ export function StepperProgress({ steps, current, label = "Progress", className, ...props }: StepperProgressProps) { const reduceMotion = useReducedMotion() ?? false; const items = steps.map((step) => (typeof step === "string" ? { title: step } : step)); const active = Math.min(Math.max(0, current), items.length); return ( <ol aria-label={label} className={cn("flex w-full items-start", className)} {...props}> {items.map((step, index) => { const state = index < active ? "complete" : index === active ? "current" : "upcoming"; const isLast = index === items.length - 1; return ( <li key={`${step.title}-${index}`} aria-current={state === "current" ? "step" : undefined} className="relative flex min-w-0 flex-1 basis-0 flex-col items-center text-center" data-state={state} > {/* Connector to the next step. Columns are equal, so it spans one column minus both markers. */} {!isLast && ( <span aria-hidden className="absolute top-4 left-[calc(50%+1.25rem)] h-0.5 w-[calc(100%-2.5rem)] -translate-y-1/2 overflow-hidden rounded-full bg-muted" > <motion.span className="block h-full origin-left rounded-full bg-primary" initial={false} animate={{ scaleX: index < active ? 1 : 0 }} transition={reduceMotion ? { duration: 0 } : fill} /> </span> )} <span aria-hidden className="relative grid size-8 place-items-center"> <span className={cn( "relative grid size-8 place-items-center rounded-full border-2 text-xs font-semibold tabular-nums transition-colors duration-300", state === "complete" && "border-primary bg-primary text-primary-foreground", state === "current" && "border-primary bg-background text-primary", state === "upcoming" && "border-border bg-background text-muted-foreground" )} > <AnimatePresence initial={false} mode="popLayout"> {state === "complete" ? ( <motion.span key="check" initial={reduceMotion ? false : { scale: 0.8, opacity: 0 }} animate={{ scale: 1, opacity: 1 }} exit={{ scale: 0.8, opacity: 0, transition: { duration: 0.12 } }} transition={pop} > <Check instant={reduceMotion} /> </motion.span> ) : ( <motion.span key="number" initial={reduceMotion ? false : { scale: 0.8, opacity: 0 }} animate={{ scale: 1, opacity: 1 }} exit={{ scale: 0.8, opacity: 0, transition: { duration: 0.12 } }} transition={pop} > {index + 1} </motion.span> )} </AnimatePresence> </span> </span> <span className="mt-2 max-w-28 px-1"> <span className={cn( "block truncate text-xs font-medium transition-colors duration-300 sm:text-sm", state === "upcoming" ? "text-muted-foreground" : "text-foreground" )} > {step.title} </span> {step.description && ( <span className="mt-0.5 hidden truncate text-xs text-muted-foreground sm:block">{step.description}</span> )} <span className="sr-only"> {state === "complete" ? " (completed)" : state === "current" ? " (current step)" : " (not started)"} </span> </span> </li> ); })} </ol> ); }
| Prop | Type | Default | Description |
|---|---|---|---|
| steps | (string | { title: string; description?: string })[] | — | The steps, in order. Required. |
| current | number | — | Index of the step in progress; earlier steps are complete. Required. |
| label | string | "Progress" | Accessible name for the list. |
Segmented Progress
A bar split into segments that fill one after another, for chunked uploads, quotas or checklists. A single spring drives the whole bar and each segment takes its slice of it, so the fill flows from segment to segment.
"use client";
import * as React from "react";
import { Upload } from "lucide-react";
import { Button } from "@/components/ui/button";
import { SegmentedProgress } from "@/components/dusk/progress/segmented-progress";
const total = 8;
export default function SegmentedProgressDemo() {
const [chunks, setChunks] = React.useState(3);
const [running, setRunning] = React.useState(false);
const uploading = running && chunks < total;
React.useEffect(() => {
if (!uploading) return;
const timer = window.setInterval(() => setChunks((c) => Math.min(total, c + 1)), 550);
return () => window.clearInterval(timer);
}, [uploading]);
return (
<div className="flex w-full max-w-sm flex-col gap-4">
<div className="flex items-center justify-between text-sm">
<span id="segmented-label" className="font-medium">Uploading video.mp4</span>
<span className="text-muted-foreground tabular-nums">
{chunks}/{total} chunks
</span>
</div>
<SegmentedProgress value={chunks} max={total} aria-labelledby="segmented-label" />
<div className="flex justify-end gap-2">
<Button variant="ghost" size="sm" onClick={() => { setRunning(false); setChunks(0); }}>
Reset
</Button>
<Button
size="sm"
variant="outline"
loading={uploading}
loadingText="Uploading"
onClick={() => {
if (chunks >= total) setChunks(0);
setRunning(true);
}}
>
<Upload />
Upload
</Button>
</div>
</div>
);
}$ npx shadcn@latest add https://duskui.com/r/segmented-progress.json1. Install the dependencies.
npm install motion @radix-ui/react-progress2. Copy the source into
components/dusk/progress/segmented-progress.tsx.segmented-progress.tsx "use client"; import * as React from "react"; import * as ProgressPrimitive from "@radix-ui/react-progress"; import { motion, useReducedMotion, useSpring, useTransform, type MotionValue } from "motion/react"; import { cn } from "@/lib/utils"; const fillSpring = { stiffness: 70, damping: 18, mass: 0.9 }; export interface SegmentedProgressProps extends Omit<React.ComponentProps<typeof ProgressPrimitive.Root>, "value" | "max" | "children"> { /** Current value, from 0 to `max`. */ value: number; max?: number; /** Number of segments. Defaults to `max` when it's 12 or less, otherwise 10. */ segments?: number; /** Classes for each segment's track. */ segmentClassName?: string; /** Classes for the filled part of each segment (e.g. a different `bg-*`). */ indicatorClassName?: string; } function Segment({ fill, index, className, indicatorClassName, }: { fill: MotionValue<number>; index: number; className?: string; indicatorClassName?: string; }) { // How much of this segment is covered by the overall fill, 0–1. const amount = useTransform(fill, (v) => Math.min(1, Math.max(0, v - index))); return ( <span className={cn("relative h-full flex-1 overflow-hidden rounded-full bg-muted", className)}> <motion.span className={cn("absolute inset-0 origin-left rounded-full bg-primary", indicatorClassName)} style={{ scaleX: amount }} /> </span> ); } /** * A progress bar split into segments that fill one after another, like a * chunked upload or an onboarding checklist. A single spring drives the whole * bar and each segment takes its slice of it, so the fill flows from segment * to segment instead of all of them moving at once. A real Radix `progressbar` underneath. Instant under reduced motion. */ export function SegmentedProgress({ value, max = 100, segments, segmentClassName, indicatorClassName, className, ...props }: SegmentedProgressProps) { const reduceMotion = useReducedMotion() ?? false; const count = Math.max(1, Math.round(segments ?? (max <= 12 ? max : 10))); const clamped = Math.min(max, Math.max(0, value)); const fill = useSpring(0, fillSpring); React.useEffect(() => { const target = max > 0 ? (clamped / max) * count : 0; if (reduceMotion) fill.jump(target); else fill.set(target); }, [clamped, max, count, reduceMotion, fill]); return ( <ProgressPrimitive.Root value={clamped} max={max} className={cn("flex h-2 w-full items-stretch gap-1.5", className)} {...props} > {Array.from({ length: count }, (_, index) => ( <Segment key={index} fill={fill} index={index} className={segmentClassName} indicatorClassName={indicatorClassName} /> ))} </ProgressPrimitive.Root> ); }
| Prop | Type | Default | Description |
|---|---|---|---|
| value | number | — | Current value, 0 to max. Required. |
| max | number | 100 | Maximum value. |
| segments | number | — | Segment count. Defaults to max when it's 12 or less, otherwise 10. |
| segmentClassName / indicatorClassName | string | — | Classes for each segment's track and fill. |
API Reference
Same as shadcn/ui: a single Progress component that forwards the Radix Progress props.
| Prop | Type | Default | Description |
|---|---|---|---|
| value | number | null | — | Current value. null or undefined shows the indeterminate sweep. |
| max | number | 100 | Maximum value. |
| getValueLabel | (value: number, max: number) => string | — | Text for aria-valuetext. Defaults to a percentage. |
| indicatorClassName | string | — | Classes for the moving bar, e.g. a different color. |
Accessibility
- Built on Radix Progress:
role="progressbar"witharia-valuemin,aria-valuemax,aria-valuenowand a readable value text. - Give every bar a name with
aria-labeloraria-labelledbypointing at its visible label. - The circular ring's counting number is hidden from screen readers; the progressbar value is announced instead.
- Stepper Progress is an ordered list with
aria-current="step"and each step's state (completed, current, not started) spelled out. - Under prefers-reduced-motion bars, rings and segments jump to their value and the indeterminate sweep becomes a pulse.