import { SvelteComponentTyped } from "svelte"; import type { SvelteHTMLElements } from "svelte/elements"; type $RestProps = SvelteHTMLElements["div"]; type $Props = { /** * Specify the step labels, in order. * If the list gets shorter than `currentIndex`, the stepper moves to its * last step. * @default [] */ steps?: ReadonlyArray; /** * Specify the index of the current step, as on ProgressIndicator. * @default 0 */ currentIndex?: number; /** * Specify a check that runs when Continue is pressed, such as one that * marks invalid fields. Return `false`, or a promise of `false`, to stay * on the step; focus then moves to the step's first invalid field. While * a promise is pending, Continue shows its loading state. When it throws * or rejects, the stepper stays on the step and dispatches `validate:error`. * @default () => true */ validate?: (index: number) => boolean | Promise; /** * Specify the work to run on submit, after the `submit` event. When it * returns a promise, the submit button shows its loading state until the * promise settles: on success `submitted` becomes `true`, and on failure * the stepper dispatches `submit:error` and focuses the submit button. * Without it, set `submitting` and `submitted` yourself. */ submit?: undefined | (() => void | Promise); /** * Set to `true` to disable Continue, or the submit button on the last step * @default false */ nextDisabled?: boolean; /** * Specify the text of the Back button * @default "Back" */ backText?: string; /** * Specify the text of the Continue button * @default "Continue" */ nextText?: string; /** * Specify the text of the submit button on the last step * @default "Submit" */ submitText?: string; /** * Specify the text announced while an async `validate` runs * @default "Checking" */ validatingDescription?: string; /** * Set to `true` while the submission runs: the submit button shows its * loading state and Back is disabled. `submit` sets this state on its own. * @default false */ submitting?: boolean; /** * Specify the text announced while submitting * @default "Submitting" */ submittingDescription?: string; /** * Set to `true` once the submission succeeds: every step is complete, * the buttons are removed, and focus moves to the content. Set it back * to `false`, with `currentIndex` to `0`, to start again. * @default false */ submitted?: boolean; /** * Set to `true` to space the progress steps equally * @default false */ spaceEqually?: boolean; /** The current step's content, and the confirmation once `submitted` is `true`. */ children?: (this: void, ...args: [{ currentIndex: number; submitted: boolean }]) => void; [key: `data-${string}`]: unknown; }; export type StepperProps = Omit<$RestProps, keyof $Props> & $Props; export default class Stepper extends SvelteComponentTyped< StepperProps, { change: CustomEvent; /** Continue was pressed on the last step and `validate` passed. */ submit: CustomEvent; "submit:error": CustomEvent<{ error: unknown }>; /** Dispatched when `validate` throws or rejects. The stepper stays on the step. */ "validate:error": CustomEvent<{ error: unknown; index: number }>; }, { /** The current step's content, and the confirmation once `submitted` is `true`. */ default: { currentIndex: number; submitted: boolean }; } > {}