Progress
How far a task that takes time has gone, or that it is still going.
Installation
pnpm dlx @human-kit/design add progressnpx @human-kit/design add progressyarn dlx @human-kit/design add progressbunx @human-kit/design add progressThe command copies the files to src/lib/components/ui/progress. It also
installs the packages that the files import.
Usage
<script lang="ts">
import * as Progress from '$lib/components/ui/progress';
</script>
<Progress.Root label="Exporting records" value={62} /> Examples
A value in its unit
By default the value reads as a percent of the range. Give format the options of Intl.NumberFormat to show the value itself, as "340 MB", and getValueText to tell a screen reader the whole of it.
Guidelines
- Use it for a task that takes more than a second or two and whose end is known: an export, an upload, a sync.
- Pass
value={null}while the end is not known yet, and a number as soon as it is. A bar that only moves says nothing of how long is left. - Say in
labelwhat is in progress, as a verb: "Exporting records", not "Progress". - Use
size="sm"inside a row or a card, where the bar is one detail among others. - For a short wait inside a button, use its
pendingstate instead of a bar beside it.
Accessibility
- It renders a
role="progressbar"witharia-valuemin,aria-valuemaxandaria-valuenow, and the formatted value inaria-valuetext. labelnames the bar. Without one, give it anaria-label.- While the value is
nullthe bar has noaria-valuenow: a number for a task of no known end would be wrong. - Where motion is reduced, the bar of no known end stands still: the whole track turns a faint primary in place of the moving stretch.
- A screen reader does not hear every change. Announce the end of the task in a toast or in the page.
API reference
| Prop | Type | Default |
|---|---|---|
value | number | null How far the task is, between | — |
min | number The value at the start of the task. | 0 |
max | number The value at the end of the task. | 100 |
label | string What is in progress, over the bar. | — |
showValue | boolean Shows the value at the end of the label's line, while it is known. | true |
size | 'sm' | 'default' The thickness of the track: 4px or 6px. | 'default' |
format | Intl.NumberFormatOptions How the value is written. Without it, as a percent of the range. | — |
getValueText | (formattedValue: string, value: number | null) => string The text a screen reader gets for the value. | — |
aria-valuetext | string The text a screen reader gets for the value. It wins over | — |
element | HTMLDivElement | null The rendered element. Bindable. | — |
context | ProgressContext The state of the bar: | — |
Plus every attribute of a <div>, on the bar.