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 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%".
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.
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
progressbarwitharia-valuenow,aria-valueminandaria-valuemax; indeterminate bars leave out the value. labelnames the bar. Without one, passaria-label.formatValue's text is thearia-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.
| Prop | Type | Default | Description |
|---|---|---|---|
value | number | null | null | Current value. Leave it out or pass null for an indeterminate bar. |
max | number | 100 | Value that means done. |
label | ReactNode | — | Visible label, linked to the bar. |
showValue | boolean | false | Shows the formatted value on the right of the label. |
formatValue | (value: number, max: number) => string | percent, 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. |