Stepper
Progress steps with done, current and upcoming states.
Demo
Usage
import { Button, Slant, Stepper, Text } from '@tuttn/slant'
const steps = [
{ name: 'Plan', detail: 'Goal and checks agreed' },
{ name: 'Build', detail: 'Agent works from the checkpoint' },
{ name: 'Ship' },
]
// Steps before `current` are complete; `current` equal to steps.length means all done.
<Stepper steps={steps} current={1} label="Release progress" />
// A status per step, for steps that finish out of order, fail or are skipped.
// body and action sit under the name and the detail.
<Stepper label="Set up the site" steps={[
{ name: 'Connect the domain', status: 'complete' },
{ name: 'Import posts', status: 'failed', detail: '3 posts had no title',
action: <Button size="sm" onClick={retry}>Retry</Button> },
{ name: 'Invite editors', status: 'skipped' },
{ name: 'Publish', status: 'current', body: <Text>Review the home page, then publish.</Text> },
]} />
// Both: a step's own status wins, and the steps without one follow current.
<Stepper current={2} label="Release run" steps={[
{ name: 'Build' }, { name: 'Lint', status: 'failed' }, { name: 'Test' }, { name: 'Ship' },
]} />
// Each step's state is read out after its name, in the root's words.
<Slant messages={{ stepComplete: 'terminé', stepCurrent: 'en cours', stepUpcoming: 'à venir', stepFailed: 'échoué', stepSkipped: 'ignoré' }}>
<Stepper steps={steps} current={1} label="Avancement" />
</Slant>Props
| Prop | Type | Default | Description |
|---|---|---|---|
steps | StepperStep[] | — | The steps, in order. |
current | number | — | Index of the current step: earlier steps are complete, later ones upcoming. `steps.length` marks every step complete. It sets only the steps without a `status` of their own; leave it out and those steps are upcoming. |
label | string | — | The list's accessible name. |
StepperStep | { name: ReactNode; detail?: ReactNode; status?: StepperStatus; body?: ReactNode; action?: ReactNode } | — | One entry of steps: its name, a line under it, its own state (which wins over current), content under those, and a control at the end. |
StepperStatus | 'complete' | 'current' | 'failed' | 'skipped' | 'upcoming' | — | A step's state, from its own status, else from current, else upcoming. |
…rest | HTMLAttributes<HTMLOListElement> | — | className, style, other attributes and the ref go on the <ol>. |
Keyboard
| Tab | moves through the controls in the steps’ bodies and actions, in order; the steps themselves take no focus |
Accessibility
- The steps are an
<ol>named bylabel(or youraria-labelledby), so a screen reader announces a list and how many steps it holds. - Each step reads its state after its name (“Import posts, failed”) in the root’s
messages.stepComplete,stepCurrent,stepUpcoming,stepFailedandstepSkipped. The marks arearia-hidden, so colour and shape are never the only signal. - Every step whose state is current carries
aria-current="step". With statuses of their own, several steps can be current at once. - A step’s
bodyandactionfollow its name and detail in reading order. Stepper is not a live region: announce a change of state yourself, with a polite status line. When an action goes away with the state it answered, as a Retry that succeeds does, move focus somewhere useful, such as the list itself withtabIndex={-1}. - A failed step’s name keeps the text colour, so it reads at full contrast; a skipped step’s name is muted, as an upcoming one’s is.
States
A step’s state comes from its own status first. Steps without one follow current as they always have: earlier steps complete, that step current, later ones upcoming, and current equal to steps.length marks them all complete. With neither, a step is upcoming. So a run that moves in order needs only current; an onboarding checklist whose steps finish in any order gives each step its status and leaves current out; and a release run can do both, moving current along while a step that failed says so.
Marks and connectors
A complete step is checked on an accent fill, a current one carries the slanted pixel in an accent outline, a failed one is crossed on a danger fill, a skipped one shows a muted dash, and an upcoming one is empty. The line down to the next step is accent after a complete step and the plain line after any other, failed and skipped included, so the accent runs only through what is done. Each step’s <li> carries its state as data-state.
Body and action
body renders in .sl-step-content under the name and the detail: instructions, a short form, a link. action renders after it in .sl-step-action, a wrapping row, so a Retry or a pair of buttons sits at the end of the step. Slant spaces them but leaves your content’s own styles alone. A step can have either without the other.
Right to left
Under dir="rtl" the layout mirrors: the marks and their connector move to the right edge, and names, bodies and actions start from the right.