Components / Display

Progress17

Shows how far along something is. The fill springs forward in Sticker, fills block by block in Retro, prints halftone in Comic and flows like an energy bar in Arcade.

Progress · PlaygroundLive
Uploading60%
variant
JSX
<Progress label="Uploading" value={60} showValue />

Usage

import { Progress } from "plonk-ui";

export function Upload({ percent }: { percent: number }) {
  return <Progress label="Uploading" value={percent} showValue />;
}

value goes from 0 to max (100 by default); values outside are clamped.

Custom values

max can be any unit. formatValue writes the text next to the label, and the same text is what screen readers hear, so "3.5 of 8.4 MB" beats "42%".

Progress · UploadLive
moodboard.zip0.0 of 8.4 MB
import { useEffect, useState } from "react";
import { Button, Progress } from "plonk-ui";

const SIZE = 8.4;

export default function Upload() {
  const [sent, setSent] = useState<number | null>(null);
  const uploading = sent !== null && sent < SIZE;

  useEffect(() => {
    if (!uploading) return;
    const id = setTimeout(
      () => setSent((s) => Math.min((s ?? 0) + 0.7, SIZE)),
      250,
    );
    return () => clearTimeout(id);
  }, [uploading, sent]);

  return (
    <div className="flex w-full max-w-xs flex-col gap-4">
      <Progress
        label="moodboard.zip"
        value={sent ?? 0}
        max={SIZE}
        showValue
        variant={sent === SIZE ? "success" : "primary"}
        formatValue={(value, max) =>
          `${value.toFixed(1)} of ${max.toFixed(1)} MB`
        }
      />
      <Button
        className="self-start"
        loading={uploading}
        onPress={() => setSent(0)}
      >
        {sent === SIZE ? "Upload again" : "Upload"}
      </Button>
    </div>
  );
}

Indeterminate

Leave out value, or pass null, when you can't tell how long something will take. A segment slides back and forth until you have a value.

Progress · IndeterminateLive
Connecting to the printer
TSX
import { Progress } from "plonk-ui";

export default function Indeterminate() {
  return (
    <Progress
      className="w-full max-w-xs"
      label="Connecting to the printer"
      variant="secondary"
    />
  );
}

Personalities

Sticker's fill springs to the new value with a little overshoot. Retro splits the bar into blocks and fills it in steps. Comic prints the fill in halftone dots, and Arcade's stripes keep flowing like an energy bar. With reduced motion the fill still moves, without the overshoot, and the indeterminate segment slows down.

Accessibility

  • A progressbar with aria-valuenow, aria-valuemin and aria-valuemax; indeterminate bars leave out the value.
  • label names the bar. Without one, pass aria-label.
  • formatValue's text is the aria-valuetext, so screen readers hear the same thing you show.
  • Screen readers don't announce every change. When something finishes, say so in text too, for example with a toast.

API

All other <div> props go to the bar itself.

PropTypeDefaultDescription
valuenumber | nullnullCurrent value. Leave it out or pass null for an indeterminate bar.
maxnumber100Value that means done.
labelReactNode—Visible label, linked to the bar.
showValuebooleanfalseShows the formatted value on the right of the label.
formatValue(value: number, max: number) => stringpercent, e.g. "60%"Formats the value for the label and for screen readers (aria-valuetext).
variant"primary" | "secondary" | "accent" | "success" | "warning" | "danger""primary"Fill color.