progress
import { progress } from '@markless/ui';export default function ProgressBasic() @{ <progress.root class="bar" value={30}> <span class="bar-head"> <progress.label>Export data</progress.label> <progress.valuelabel class="bar-value" /> </span> <progress.track class="bar-track"> <progress.indicator class="bar-fill" /> </progress.track> </progress.root>;}
.bar { display: grid; gap: 0.6em; width: min(31rem, 100%); font-family: 'Shantell Sans', system-ui, sans-serif; font-size: var(--step--1); line-height: 1.5; color: var(--ink);}.bar-head { display: flex; justify-content: space-between; gap: 1em;}.bar-value { font-variant-numeric: tabular-nums;}.bar-track { position: relative; height: 1.1em; overflow: clip; border: 1px solid var(--ink); border-radius: 999px; background: var(--paper);}.bar-fill { width: 100%; height: 100%; background: color-mix(in srgb, var(--purple) 60%, var(--cream)); transition: transform 140ms ease; html.dark & { --ink: var(--on-accent); color: var(--on-accent); }}.bar-fill[ui-progress='complete'] { background: color-mix(in srgb, var(--switch-on) 65%, var(--cream)); html.dark & { --ink: var(--on-accent); --paper: var(--cream); color: var(--on-accent); }}.bar-fill[ui-progress='indeterminate'] { width: 35%; animation: sweep 1.4s ease-in-out infinite;}@keyframes sweep { from { translate: 0 0; } to { translate: 390% 0; }}@media (prefers-reduced-motion: reduce) { .bar-fill { transition: none; } .bar-fill[ui-progress='indeterminate'] { width: 100%; translate: 100% 0; animation: none; opacity: 0.45; }}
progress is a progress bar. Use it to show how far along a task is, such as an export or an
upload.
import { progress } from '@markless/ui';
export default function Export() @{
<progress.root value={30}>
<progress.label>Export data</progress.label>
<progress.valuelabel />
<progress.track>
<progress.indicator />
</progress.track>
</progress.root>
}The root writes role="progressbar", with aria-valuemin, aria-valuemax, aria-valuenow and
aria-valuetext. progress.label gives the bar its name.
Anatomy
The progress bar itself; the label, track and indicator go inside it.
progress.rootholds the value and the range.progress.labelis a<span>that names the bar.progress.valuelabelis a<span>that shows the value as text. Left empty, it shows a percentage.progress.trackis the full length of the range.progress.indicatoris the filled part. It sits inside the track.
Every part writes the same four attributes:
| Attribute | Value |
|---|---|
ui-progress |
loading, complete, or indeterminate when the amount is unknown. |
ui-value |
The current value. It is missing while the amount is unknown. |
ui-min |
The bottom of the range. |
ui-max |
The top of the range. |
How the fill moves
progress.indicator writes its own style, a transform: translateX(...). At 30 out of 100 it is
translateX(-70%). So the indicator is as wide as the track, and it slides in from the left.
Give the track overflow: hidden. Without that rule, the part of the indicator that slid out still
shows to the left of the bar.
.track {
overflow: hidden;
}
.indicator {
height: 100%;
background: currentColor;
}A value past max draws a full bar, and a value below min draws an empty one. aria-valuenow
reports the clamped value. ui-value keeps the number you passed, such as 150.
An unknown amount
Leave value out, or pass null, when you do not know how far along the task is. The bar then
reports no current value. That is not the same as zero to a screen reader. Use [ui-progress='indeterminate']
to draw a moving stripe or a pulse.
Your own wording
Text you write inside progress.valuelabel replaces the percentage. The bar also reports that text
as aria-valuetext, so a screen reader reads your words.
<progress.valuelabel>30 of 100 rows</progress.valuelabel>Props on progress.root
| Prop | Type | What it does |
|---|---|---|
value |
number | null |
How far along the task is. Omit it, or pass null, for an unknown amount. |
min |
number |
The bottom of the range. The default is 0. |
max |
number |
The top of the range. The default is 100. |
The root passes anything a <div> accepts to its element. A bar with no progress.label has no
name. Give it an aria-label instead.