/** * Step-by-step assistant component. * * @augments IvComponent */ export class Stepper extends IvComponent { /** @type {Readonly} */ static defaults: Readonly; /** * Returns the stepper instance attached to `el`, if any. * * @param {Element} el Host element. * @returns {Stepper|undefined} The instance or `undefined`. */ static get(el: Element): Stepper | undefined; /** * Returns the existing instance or creates one. * * @param {Element} el Host element. * @param {Partial} [options] Options passed in JavaScript. * @returns {Stepper} The instance. */ static getOrCreate(el: Element, options?: Partial): Stepper; /** * Instantiates every `[data-iv-component="stepper"]` inside `root`. * * @param {ParentNode} [root] Subtree to scan. * @returns {Stepper[]} Newly created instances. */ static initAll(root?: ParentNode): Stepper[]; /** * @param {Element} el The `.iv-stepper` container. * @param {Partial} [options] Options passed in JavaScript. */ constructor(el: Element, options?: Partial); /** @type {Map>} Attributes to restore. */ _saved: Map>; /** @type {StepperEntry[]} The steps, in document order. */ _entries: StepperEntry[]; /** @type {number} Index of the current step. */ _index: number; /** @type {number} Furthest step reached, which stays reachable when going back. */ _furthest: number; /** @type {Map} States forced through `setState`. */ _overrides: Map; /** @type {Map} Screen-reader error notes this instance added. */ _notes: Map; /** @type {HTMLElement|null} The live region this instance added. */ _status: HTMLElement | null; /** @type {Map} `style` attributes as served. */ _styles: Map; /** * Resolved options. * * @returns {Readonly} The options. */ get options(): Readonly; /** * Index of the current step, zero based. * * @returns {number} The index. */ get index(): number; /** * The `__step` elements, in document order. * * @returns {HTMLElement[]} The steps. */ get steps(): HTMLElement[]; /** * Whether the current step is the first one. * * @returns {boolean} `true` on the first step. */ get isFirst(): boolean; /** * Whether the current step is the last one. * * @returns {boolean} `true` on the last step. */ get isLast(): boolean; /** * Tells whether a descendant belongs to this instance and not to a nested stepper. * * @param {Element} el Candidate descendant. * @returns {boolean} `true` when the closest `.iv-stepper` is this element. */ _owns(el: Element): boolean; /** * Resolves the panel a trigger points at through its `href` hash. * * @param {Element} trigger Trigger element. * @returns {HTMLElement|null} The panel, or `null` when it does not exist. */ _panelFor(trigger: Element): HTMLElement | null; /** * The step to start on: the hash when `hash` is on, then the step the author * marked as current, then the first one. * * @returns {number} The starting index. */ _initialIndex(): number; /** * Remembers the current value of an attribute, once per element. * * @param {Element} el Element to remember. * @param {string} name Attribute name. * @returns {void} */ _remember(el: Element, name: string): void; /** * Sets a managed attribute, remembering its previous value. * * @param {Element} el Target element. * @param {string} name Attribute name. * @param {string} value Attribute value. * @returns {void} */ _set(el: Element, name: string, value: string): void; /** * Removes a managed attribute, remembering its previous value. * * @param {Element} el Target element. * @param {string} name Attribute name. * @returns {void} */ _unset(el: Element, name: string): void; /** * The state a step shows: what `setState` forced, or the position of the * step relative to the current one. * * @param {number} index Step index. * @returns {StepperState} The state. */ _stateOf(index: number): StepperState; /** * Whether a step can be reached from the index. Without `linear` every step * is reachable; with it, the ones already done and the current one are. * * @param {number} index Step index. * @returns {boolean} `true` when the trigger is active. */ _reachable(index: number): boolean; /** * Writes the whole visible state: step states, reachability, panels, the * progress custom property and the live region. * * @returns {void} */ _render(): void; /** * Adds or removes the screen-reader note of a step in error. The note is a * node built here and written with `textContent`, never parsed markup. * * @param {number} index Step index. * @param {boolean} wanted Whether the step is in error. * @returns {void} */ _syncNote(index: number, wanted: boolean): void; /** * The triggers the arrow keys move between: the reachable ones. * * @returns {HTMLElement[]} The triggers, in document order. */ _activeTriggers(): HTMLElement[]; /** * The index of the step a descendant belongs to. * * @param {Element} target Element inside the stepper. * @returns {number} The index, or `-1`. */ _indexOf(target: Element): number; /** * Index steps and the `data-iv-step` buttons. The triggers are anchors: they * never navigate while JavaScript runs, so the hash only changes when the * `hash` option asks for it. * * @param {Event} event Click event. * @returns {void} */ _onClick(event: Event): void; /** * Arrow keys along the index, and Space on a trigger (Enter already produces * a click on an anchor). * * @param {Event} event Keydown event. * @returns {void} */ _onKeydown(event: Event): void; /** * Follows the hash when the `hash` option is on. * * @returns {void} */ _onHashChange(): void; /** * Mirrors the current panel in the address bar. `replaceState` is preferred: * writing `location.hash` would scroll the page to the panel. * * @returns {void} */ _syncHash(): void; /** * Validates the controls of one panel. * * @param {number} index Step index. * @returns {boolean} `true` when nothing is invalid. */ _validate(index: number): boolean; /** * Goes to a step. Emits the cancelable `iv:change` first. * * The reachability rule of `linear` guards the index, not this method: the * API is the way a consumer jumps wherever its own flow needs to. * * @param {number} index Zero based step index. * @param {StepperReason} [reason] Why the step changes. * @returns {void} */ go(index: number, reason?: StepperReason): void; /** * Validates the current panel and advances. On the last step it emits * `iv:complete` instead: submitting is the consumer's business. * * @returns {void} */ next(): void; /** * Goes back one step. Never validates: a user must always be able to return. * * @returns {void} */ prev(): void; /** * Returns to the first step and clears every forced state. * * @returns {void} */ reset(): void; /** * Forces the state shown by one step. The forced state survives until that * step is entered again. `"error"` also adds a screen-reader note to the * label, because a colour alone is not a state. * * @param {number} index Zero based step index. * @param {StepperState} state The state to show. * @returns {void} */ setState(index: number, state: StepperState): void; } export type StepperOptions = { /** * Only the steps already done and the current one can be reached from the index. */ linear: boolean; /** * Validate the current panel before advancing. */ validate: boolean; /** * Mirror the current panel in `location.hash`. */ hash: boolean; /** * Where focus lands after a step change. */ focus: "panel" | "none"; /** * Template announced in the live region. */ statusText: string; }; export type StepperReason = "trigger" | "next" | "prev" | "api" | "hash"; export type StepperState = "done" | "current" | "upcoming" | "error"; /** * One step and the parts it owns. */ export type StepperEntry = { /** * The `__step` element. */ step: HTMLElement; /** * Its `__trigger`. */ trigger: HTMLElement; /** * The panel it points at. */ panel: HTMLElement; /** * Its `__label`, when it has one. */ label: HTMLElement | null; /** * Text of the label, read before anything was added to it. */ name: string; }; /** * A native control that takes part in constraint validation. */ export type StepperField = HTMLInputElement | HTMLSelectElement | HTMLTextAreaElement; import { IvComponent } from "../core/component.js";