Stepper¶
A row of numbered steps for a flow of several stages. Steps before the current one are completed and later ones are upcoming.
Decision¶
| When | Use |
|---|---|
| Showing where the reader is in a setup flow | Stepper |
| A form split into ordered steps | A numbered Collapsible Section |
Usage¶
import { createStepper } from './configurationpage?name=myplugin_stolon.js';
var steps = createStepper({
steps: [{ id: 'connect', label: 'Connect' }, { id: 'choose', label: 'Choose' }],
clickable: true,
onSelect: function (id) { steps.setValue(id); }
});
Classes: stolon-stepper, stolon-stepper-step, stolon-stepper-number, stolon-stepper-control, stolon-stepper-segment. The handle is { element, getValue, getStep, setValue, setItems, next, previous, destroy }.
Parts: stolon-stepper-description, stolon-stepper-label, stolon-stepper-list, stolon-stepper-text.
States and Modifiers¶
- A step is
completed,current, orupcomingby its place. The current step hasaria-current="step", and each step carries hidden status text. - A step's own
statedraws it ascompleted,current,upcoming,attention, oroptionalwherever it sits, for a flow whose steps finish in any order.attentionfills the number orange, andoptionaldashes its ring.attentionTextandoptionalTextreplace their hidden text. clickable: truemakes completed and current steps buttons, andclickable: 'all'makes every step one.layout: 'segments'draws a bar of one segment per step in its state's color, with each label as the segment's tooltip and hidden text. The Setup Checklist uses it as its summary.nextandpreviousmove by one and return the new id.setValuetakes an id or an index, andgetStep(id)returns{ id, index, label, description }ornull.- At 600px and below the steps stack.
Reference¶
Generated from the code by scripts/build-docs.mjs. Edit the code, not this section.
createStepper¶
function createStepper(options?: StepperOptions): StepperHandle
A row of numbered steps for a flow of several stages. Steps before the current one are completed, the current one has aria-current step, and later ones are upcoming. A step can be a button that reports itself. A step's own state draws it as completed, current, upcoming, attention, or optional wherever it sits, and the segments layout draws each step as one segment of a bar.
| Option | Type | What it does |
|---|---|---|
steps |
StepperStep[] |
array of { id, label, description, state } [optional] |
value |
string | number |
the current step, where a string is an id and a number is an index, so a numeric id is given as a string (default the first step) |
clickable |
boolean | 'all' |
true makes completed and current steps buttons, and 'all' makes every step one (default false) |
layout |
'steps' | 'segments' |
'steps' draws numbered steps, and 'segments' draws a bar of one segment per step, its labels kept as tooltips and hidden text (default 'steps') |
navLabel |
string |
aria-label of the list (default 'Progress') |
completedText |
string |
hidden text for a completed step (default 'Completed') |
currentText |
string |
hidden text for the current step (default 'Current') |
upcomingText |
string |
hidden text for a later step (default 'Not started') |
attentionText |
string |
hidden text for a step that needs attention (default 'Needs attention') |
optionalText |
string |
hidden text for an optional step (default 'Optional') |
onSelect |
(id: string | number, index: number): void |
function(id, index) called when a step button is pressed [optional] |
| Handle member | Type |
|---|---|
getValue |
(): string | number | null |
getStep |
(id: unknown): StepperStepInfo | null |
setValue |
(value: string | number): void |
setItems |
(next: StepperStep[], value?: string | number): void |
next |
(): string | number | null |
previous |
(): string | number | null |
destroy |
(): void |
| Type | What it is |
|---|---|
StepperStepState |
How a step is drawn. A step's own state replaces the one its place before or after the current step gives it. |
StepperStep |
One step of a stepper. state sets its look on its own, whatever the current step is. |
StepperStepInfo |
What getStep returns for a step, with its index. |
| Class | What it looks like |
|---|---|
stolon-stepper-list |
Row of steps for a flow of stages, which becomes a column on a narrow screen |
stolon-stepper-control |
One step, as a div or as a button when it can be chosen |
stolon-stepper-number |
Round number, filled with the accent when current and green with a dark check when completed |
stolon-stepper.stolon-segments |
A stepper drawn as a bar of one segment per step, in each step's color, for a summary of progress. Its labels are tooltips and hidden text |
Example¶
Example Code¶
<!-- title: Stepper -->
<div id="mount" style="display: grid; gap: 24px;"></div>
<script type="module">
const base = await window.__baseReady;
const mount = document.getElementById('mount');
const stepper = base.createStepper({
steps: [{ id: 'a', label: 'Connect', description: 'Pick a server' }, { id: 'b', label: 'Choose', description: 'Select content' }, { id: 'c', label: 'Review' }],
value: 'b',
clickable: true,
onSelect: (id) => stepper.setValue(id)
});
mount.appendChild(stepper.element);
// Each step's own state, drawn as a bar of segments.
const bar = base.createStepper({
layout: 'segments',
clickable: 'all',
steps: [
{ id: 'port', label: 'Choose a Port', state: 'completed' },
{ id: 'domain', label: 'Point a Domain', state: 'attention' },
{ id: 'cert', label: 'Add a Certificate', state: 'current' },
{ id: 'relay', label: 'Set Up a Relay', state: 'optional' }
],
value: 'cert'
});
mount.appendChild(bar.element);
</script>