Skip to content
ProLifetime access for $199, paid once, every future release included
Truffle UI

Progress Bar

FreeNew

A 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.

progress-bar-demo.tsx
"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

PropTypeDefault
value*number | null

The current amount. Pass `null` when the total is unknown; the bar then sweeps instead of filling.

—
maxnumber100
label*string

What is in progress, e.g. "Uploading". It names the bar for screen readers.

—
showLabelboolean

Show the label and the value above the bar.

false
formatValue(value: number, max: number) => string

Turns the value into text, e.g. `(v, max) => `${v} of ${max} files``. Defaults to a percentage.

(v, m) => `${Math.round((v / m) * 100)}%`
tonekeyof typeof tones"default"
size"sm" | "md""md"
classNamestring—

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.