Skip to content
Atoms

Progress

A bar or ring that eases to each value.

Installation

  1. Run the CLI

    Run pnpm dlx asta-ui@latest init once, then this. The file lands in components/astabyte/ and the colour tokens go into your CSS.

    $ pnpm dlx asta-ui@latest add progress

    Or with the shadcn CLI: pnpm dlx shadcn@latest add https://ui.astabyte.com/r/progress.json

  2. Or install the package

    Don’t want the file? Import from asta-ui/progress and update with pnpm update asta-ui. Add the stylesheet once. More.

    $ pnpm add asta-ui
    import { ProgressBar } from "asta-ui/progress";
  3. Or copy it by hand

    Copy this file. Keep the paths, or fix the @/ imports. Then add the tokens from globals.css.

    "use client";
    
    import type { ReactNode } from "react";
    
    const cx = (...c: (string | false | null | undefined)[]) => c.filter(Boolean).join(" ");
    
    const KEYFRAMES = `@keyframes asta-progress-sweep { from { transform: translateX(-100%) } to { transform: translateX(260%) } }
    @keyframes asta-progress-spin { to { transform: rotate(360deg) } }
    @keyframes asta-progress-breathe { 50% { opacity: .45 } }`;
    
    const EASE = "cubic-bezier(.16,1,.3,1)";
    
    function clamp(value: number | undefined, max: number) {
      if (value === undefined || Number.isNaN(value)) return undefined;
      return Math.max(0, Math.min(max, value));
    }
    
    interface Shared {
      /** Current amount. Leave it out for an indeterminate state. */
      value?: number;
      max?: number;
      /** Accessible name, also shown above the bar. */
      label?: string;
      /** Show the percentage. */
      showValue?: boolean;
      /** Custom text for the value, e.g. "3 of 8 files". */
      valueText?: string;
      className?: string;
    }
    
    export interface ProgressBarProps extends Shared {
      size?: "sm" | "md";
      /** Keep the label visually hidden (it stays for screen readers). */
      hideLabel?: boolean;
    }
    
    /**
     * A linear progress bar. The fill eases to each new value. Without `value` a short segment sweeps
     * across the track, and with reduced motion it breathes in place instead.
     */
    export function ProgressBar({ value, max = 100, label = "Progress", showValue, valueText, size = "md", hideLabel, className }: ProgressBarProps) {
      const v = clamp(value, max);
      const pct = v === undefined ? undefined : (v / max) * 100;
      const text = valueText ?? (pct === undefined ? undefined : `${Math.round(pct)}%`);
    
      return (
        <div className={cx("w-full", className)}>
          <style href="asta-progress" precedence="asta">{KEYFRAMES}</style>
          {(!hideLabel || showValue) && (
            <div className="mb-2 flex items-baseline justify-between gap-4 text-[13px]">
              <span className={cx("text-ink-2", hideLabel && "sr-only")}>{label}</span>
              {showValue && text && <span className="tabular-nums text-mute">{text}</span>}
            </div>
          )}
          <div
            role="progressbar"
            aria-label={label}
            aria-valuemin={0}
            aria-valuemax={max}
            aria-valuenow={v}
            aria-valuetext={v === undefined ? "Loading" : text}
            aria-busy={v === undefined || undefined}
            className={cx("relative w-full overflow-hidden rounded-full bg-[color-mix(in_srgb,var(--color-ink)_9%,transparent)]", size === "md" ? "h-1.5" : "h-1")}
          >
            {pct === undefined ? (
              <span
                className="absolute inset-y-0 left-0 w-[38%] rounded-full bg-brand motion-reduce:!w-full motion-reduce:![animation:asta-progress-breathe_1.8s_ease-in-out_infinite]"
                style={{ animation: `asta-progress-sweep 1.5s ${EASE} infinite` }}
              />
            ) : (
              <span
                className="absolute inset-0 rounded-full bg-brand transition-transform duration-700 motion-reduce:transition-none"
                style={{ transform: `translateX(${pct - 100}%)`, transitionTimingFunction: EASE }}
              />
            )}
          </div>
        </div>
      );
    }
    
    export interface ProgressRingProps extends Shared {
      /** Diameter in px. */
      size?: number;
      /** Ring thickness in px. */
      thickness?: number;
      /** Shown in the middle. Defaults to the percentage when `showValue` is on. */
      children?: ReactNode;
    }
    
    /**
     * A circular progress ring. The arc eases to each new value. Without `value` a quarter arc spins,
     * and with reduced motion it breathes in place instead.
     */
    export function ProgressRing({ value, max = 100, label = "Progress", showValue, valueText, size = 44, thickness = 3.5, children, className }: ProgressRingProps) {
      const v = clamp(value, max);
      const pct = v === undefined ? undefined : (v / max) * 100;
      const text = valueText ?? (pct === undefined ? undefined : `${Math.round(pct)}%`);
      const r = (size - thickness) / 2;
      const c = size / 2;
      const inner = children ?? (showValue && text ? <span className="tabular-nums">{text}</span> : null);
    
      return (
        <span
          role="progressbar"
          aria-label={label}
          aria-valuemin={0}
          aria-valuemax={max}
          aria-valuenow={v}
          aria-valuetext={v === undefined ? "Loading" : text}
          aria-busy={v === undefined || undefined}
          className={cx("relative inline-flex shrink-0 items-center justify-center", className)}
          style={{ width: size, height: size }}
        >
          <style href="asta-progress" precedence="asta">{KEYFRAMES}</style>
          <svg
            viewBox={`0 0 ${size} ${size}`}
            width={size}
            height={size}
            aria-hidden
            className={cx("absolute inset-0", pct === undefined && "motion-reduce:![animation:asta-progress-breathe_1.8s_ease-in-out_infinite]")}
            style={pct === undefined ? { animation: "asta-progress-spin 1s linear infinite" } : { transform: "rotate(-90deg)" }}
          >
            <circle cx={c} cy={c} r={r} fill="none" strokeWidth={thickness} style={{ stroke: "color-mix(in srgb, var(--color-ink) 9%, transparent)" }} />
            <circle
              cx={c}
              cy={c}
              r={r}
              fill="none"
              strokeWidth={thickness}
              strokeLinecap="round"
              pathLength={100}
              strokeDasharray="100 100"
              strokeDashoffset={pct === undefined ? 75 : 100 - pct}
              className="stroke-brand transition-[stroke-dashoffset] duration-700 motion-reduce:transition-none"
              style={{ transitionTimingFunction: EASE, opacity: pct === 0 ? 0 : 1 }}
            />
          </svg>
          {inner && <span className="relative text-[11px] font-medium text-ink">{inner}</span>}
        </span>
      );
    }
    
    export default ProgressBar;
    
  4. Or ask your AI agent

    Paste this into Claude Code, Cursor, Codex, v0 or Lovable. Fill in the last line. More in Prompts.

    Add the Astabyte UI Progress component to my project.
    
    A bar or ring that eases to each value.
    It includes: ProgressBar, ProgressRing, determinate, indeterminate, label, value text.
    
    Install it:
    ```sh
    pnpm dlx asta-ui@latest add progress --radix
    ```
    Or with the shadcn CLI:
    ```sh
    pnpm dlx shadcn@latest add https://ui.astabyte.com/r/progress.json
    ```
    If the project isn't set up yet, run `pnpm dlx asta-ui@latest init --radix` first: it runs `shadcn init` when needed and adds the @astabyte registry (Next.js, Vite, React Router, Astro, TanStack Start; Tailwind CSS v4).
    
    Import it like this:
    ```tsx
    import { ProgressBar, ProgressRing } from "@/components/astabyte/progress";
    ```
    
    Usage example and props: https://ui.astabyte.com/progress
    Full catalogue for context: https://ui.astabyte.com/llms.txt
    
    Rules:
    - Keep the colour tokens (paper, paper-2, ink, ink-2, mute, brand). Don't restyle with hard-coded colours; rebrand by changing the token values in the CSS.
    - Keep the motion as it is: transform and opacity only, and the prefers-reduced-motion fallback.
    - Keep keyboard, focus and ARIA behaviour.
    - Use fake data and fake brand names in examples.
    
    Use it to: [describe where it goes and what it should do]
  5. Or use plain HTML + CSS

    Not on React? Use it from Django, Rails, Laravel, Go html/template, htmx or a static page. Load asta.css and asta.js once (the head.html tab), then paste the markup. The ui.astabyte.com/cdn link is temporary: pin a version from jsDelivr for production. More in HTML + CSS.

    <div style="display:grid;gap:12px">
    <div class="asta-progress"><div class="asta-progress-header"><span class="asta-progress-label">Upload</span><span class="asta-progress-value">62%</span></div><div class="asta-progress-track" role="progressbar" aria-label="Upload" aria-valuemin="0" aria-valuemax="100" aria-valuenow="62" aria-valuetext="62%"><span class="asta-progress-fill" style="transform:translateX(-38%)"></span></div></div>
    <div class="asta-progress asta-progress-sm"><div class="asta-progress-header"><span class="asta-progress-label">Progress</span></div><div class="asta-progress-track" role="progressbar" aria-label="Progress" aria-valuemin="0" aria-valuemax="100" aria-valuetext="Loading" aria-busy="true"><span class="asta-progress-fill"></span></div></div>
    <span class="asta-progress-ring" role="progressbar" aria-label="Progress" aria-valuemin="0" aria-valuemax="100" aria-valuenow="70" style="width:44px;height:44px"><svg viewBox="0 0 44 44" width="44" height="44" aria-hidden="true"><circle class="asta-progress-ring-track" cx="22" cy="22" r="20.25" stroke-width="3.5"/><circle class="asta-progress-ring-bar" cx="22" cy="22" r="20.25" stroke-width="3.5" pathLength="100" stroke-dasharray="100 100" stroke-dashoffset="30"/></svg><span class="asta-progress-ring-value">70%</span></span><span class="asta-progress-ring" role="progressbar" aria-label="Progress" aria-valuemin="0" aria-valuemax="100" aria-valuetext="Loading" aria-busy="true" style="width:44px;height:44px"><svg viewBox="0 0 44 44" width="44" height="44" aria-hidden="true"><circle class="asta-progress-ring-track" cx="22" cy="22" r="20.25" stroke-width="3.5"/><circle class="asta-progress-ring-bar" cx="22" cy="22" r="20.25" stroke-width="3.5" pathLength="100" stroke-dasharray="100 100" stroke-dashoffset="75"/></svg></span>
    </div>

Usage

The demo above, as code.

"use client";

import { useEffect, useState } from "react";
import { ProgressBar, ProgressRing } from "@/components/astabyte/progress";

export default function ProgressDemo() {
  const [sent, setSent] = useState(0);

  // Fake an upload: a few uneven chunks, then start over.
  useEffect(() => {
    const t = setTimeout(() => setSent((s) => (s >= 100 ? 0 : Math.min(100, s + 8 + Math.round(Math.random() * 18)))), sent >= 100 ? 1800 : 700);
    return () => clearTimeout(t);
  }, [sent]);

  return (
    <div className="flex min-h-[420px] w-full items-center justify-center p-6 sm:p-10">
      <div className="flex w-full max-w-sm flex-col gap-8">
        <div className="rounded-xl bg-paper-2 p-5">
          <ProgressBar label="brand-film-final.mov" value={sent} showValue valueText={sent >= 100 ? "Done" : `${sent}%`} />
          <p className="mt-2 text-[12px] tabular-nums text-mute">{sent >= 100 ? "Uploaded · 248 MB" : `${Math.round(2.48 * sent)} of 248 MB`}</p>
        </div>

        <div className="flex items-center gap-4 px-1">
          <ProgressRing label="Storage used" value={72} showValue size={52} />
          <div className="min-w-0 flex-1">
            <p className="text-[13.5px] font-medium tracking-[-0.01em] text-ink">Storage</p>
            <p className="text-[12.5px] tabular-nums text-mute">72 of 100 GB used</p>
          </div>
          <ProgressRing label="Syncing" size={20} thickness={2.5} />
        </div>

        <ProgressBar label="Preparing export" hideLabel size="sm" />
        <p className="text-center text-[12.5px] text-mute">Pass a value to fill, leave it out for a loading state.</p>
      </div>
    </div>
  );
}