Cómo funciona
Fully controlled: the component never times or advances; you bump current as each step finishes, optionally pass progress for the running step, and pass error on failure. The bar fill is a full-width pill moved with translateX inside a clipped 4px track, so it keeps its round end at every value without animating width. The four status labels share one grid cell and the line under the bar is reserved, so no state change alters the list size. An IntersectionObserver starts the first fill when the list is 30% in view; until then every bar rests empty.
Úsalo para
- Several uploads, imports or exports that run one after another, each with its own percentage.
- A multi-step operation that takes a few seconds, such as creating a booking or deploying.
- Cards and dialogs where progress must not shift the buttons below, and where a failure must say which step and why.
Busca otra opción cuando
- A single wait with no meaningful steps: use a spinner or skeleton.
- One task with one percentage: use a single progress bar or a progress ring.
- Long processes with many steps or branches: use a stepper or a log view.
Uso
import { StepLoader } from './StepLoader.jsx'
export function Uploads({ files, current, percent, error }) {
// current: index of the file uploading now (files.length when all are done)
// percent: 0-100 of that file; leave it out to show a gliding bar instead
return (
<StepLoader
steps={files.map((f) => ({ label: f.name, icon: <FileIcon type={f.type} />, description: f.sizeText }))}
current={current}
progress={percent}
error={error}
/>
)
}
// A plain checklist: no icons, no percentages
<StepLoader steps={[{ label: 'Check availability' }, { label: 'Hold the room' }, { label: 'Create booking' }]} current={step} />Propiedades
| Propiedad | Tipo | Por defecto | Qué hace |
|---|---|---|---|
steps | { label: ReactNode; description?: ReactNode | ((percent: number) => ReactNode); icon?: ReactNode }[] | — | Steps in execution order. label is one line and truncated if too long. description is the line under the bar (size, time left); a function receives the percentage the row shows while counting, so text such as “2.6 / 12.8 MB” counts with the bar. When any step has one, every row reserves it. icon replaces the step number in the leading tile. |
current | number | — | Zero-based index of the step in progress; everything before it is done. Equal to steps.length means all done. |
error | boolean | ReactNode | false | Whether the current step failed. true shows only the failed state; text is also shown as the reason, in the line under the bar (or after the name when no step has a description). |
progress | number | — | Percentage (0–100) of the step in progress. Its bar fills to it while the number counts. Leave it out when unknown: a short segment glides along the bar instead. |
duration | number | 700 | Time in ms for a bar and its percentage to reach a new value, on cubic-bezier(0.22, 1, 0.36, 1). |
size | 'sm' | 'md' | 'lg' | 'md' | Leading tile 28 / 36 / 44px, font size 13 / 14 / 16px; the bar is 4px (6px for lg). |
statusText | Partial<Record<'pending' | 'active' | 'done' | 'error', string>> | Waiting / In progress / Completed / Failed | The status shown on the right of each row. While a measured step runs, its percentage shows instead of the active text. |
announce | (info: { index, total, status, step?, error? }) => ReactNode | “Step 2 of 4: Hold the room” | Custom text for the aria-live progress announcement; status is 'active', 'done' or 'error'. |
...rest | HTMLAttributes<HTMLDivElement> | — | Other attributes go to the root element, such as className, style and aria-label. The root carries data-status (active, done, error) for styling; set --ds-step-loader-color on it or an ancestor to change the running color. |
Accesibilidad
- The list is an ordered list; the current row has aria-current="step" and the visible status on the right (“Completed”, “Failed”) is read with each row; hidden labels are aria-hidden.
- A polite live region announces progress, such as “Step 2 of 4: Hold the room”, once per change.
- Failure is shown by an icon, the word “Failed”, colour and the reason text, never colour alone.
- Customize the status words with statusText and the spoken progress with announce.
- Reduced motion sets bars and labels at once, draws strokes at once, and replaces the spinner and the gliding segment with a slow pulse.
Movimiento
Bars fill in 700ms on cubic-bezier(0.22, 1, 0.36, 1), 60ms apart per row, and the percentage counts on the same curve. A finished bar turns green in 240ms while “Completed” rises in; status labels leave in 160ms ease-in and enter in 240ms ease-out. Without a percentage a 36% segment glides across in 1.4s. Number tiles swap to a 0.8s spinner, then a spring check that draws itself; a failed row shakes once in 360ms.
Añádelo a tu proyecto
Los miembros Pro copian un prompt y su agente de programación instala el código, igual que con los gratuitos.
StepLoader.jsxstep-loader.csstokens.cssREADME.md
Los dos archivos se instalan juntos. La hoja de estilos lee las variables de tokens.css y lleva valores de reserva, así que también funciona sola.





