import type { JSX, ReactNode } from 'react'; import type { AriaLabelingProps } from '../../core/types/a11y-props.js'; import type { StylingProps } from '../../core/types/styling-props.js'; import type { WithChildren } from '../../core/types/with-children.js'; import type { StepStatus, StepperStore } from './store/StepperStore.types.js'; /** * Props of `Stepper.Step`. * @public */ export interface StepperStepProps extends Pick { /** * Stable identifier of the step, used as the store key. Must be unique * within the Stepper. */ id: TStepId; /** * Step content. Typically `Stepper.Title`, `Stepper.Description`, * `Stepper.Hint`, `Stepper.ErrorMessage` and `Stepper.Content`. * * Only these elements are read, and only when they are direct children. * Elements inside a Fragment or returned by a wrapper component are ignored. */ children?: ReactNode; /** * Called when the user presses Next on this step. Return a step id to * navigate there, or `undefined` to keep the default verdict. Throw a * `StepperRefusal` to stay on the step and mark it invalid. Any other error * is reported and the step stays as it is. */ onNext?: (payload: TNavigationPayload) => TStepId | void | Promise; /** * Called after the user pressed Back on this step and navigation completed. */ onBack?: (payload: TNavigationPayload) => void; /** * Marks the step as required. An optional step never blocks Next. * @defaultValue true */ required?: boolean; /** * Blocks navigating to the step. * @defaultValue false */ disabled?: boolean; } /** * Payload of `onNext`, `onBack` and `onStepSelected`. * @public */ export interface StepperNavigationPayload = Record> { /** * The step the user is leaving. */ currentStepId: keyof T & string; /** * The step the user is going to. */ nextStepId: keyof T & string; /** * The departing step's status in the store. The key is always present. */ status?: StepStatus; /** * Values of every step currently in the flow, keyed by step id. */ snapshot: T; } /** * An invalid step reported to `onComplete`. * @public */ export interface StepperInvalidStep = Record> { /** * The invalid step. */ id: keyof T & string; /** * `false` when the step is marked optional. */ required: boolean; } /** * Payload of `onComplete`. * @public */ export interface StepperCompletePayload = Record> { /** * The step the user completed from, always the last step in the flow. */ currentStepId: keyof T & string; /** * Every step in the flow with an invalid status, in navigation order. Empty * when none. Required steps the user never visited are included. */ invalidSteps: Array>; /** * Values of every step currently in the flow, keyed by step id. */ snapshot: T; } /** * Props of the `Stepper` returned by `createStepper`. * @public */ export interface StepperProps = Record> extends StylingProps { /** * One or more `Stepper.Step` elements with unique ids. * * Only `Stepper.Step` elements that are direct children are rendered. A step * inside a Fragment or returned by a wrapper component is ignored. In * development, the Stepper logs a warning for ignored elements and for * duplicate ids. */ children?: ReactNode; /** * The step the wizard starts on. * @defaultValue first step in declaration order */ defaultStepId?: keyof T & string; /** * Called after the user selects a step in the navigation and the step has * changed. Never fires for Next, Back or `goToStep()`. */ onStepSelected?: (payload: StepperNavigationPayload) => void; /** * Called when the user presses Finish, whether or not a step is invalid. * Return a step id to navigate there, or the current step id to handle it * yourself. Returning `undefined` goes to the first invalid step, if any. * Throw a `StepperRefusal` to stay on the step and mark it invalid. Any other * error is reported and the step stays as it is. */ onComplete?: (payload: StepperCompletePayload) => (keyof T & string) | void | Promise<(keyof T & string) | void>; } /** * The values of one step, falling back to a loose record for untyped steps. * @public */ export type StepValues, K extends keyof T> = T[K] extends Record ? T[K] : Record; /** * Field names of the given step, or of every step when `K` is the union of all * step ids. * @public */ export type StepFieldName, K extends keyof T> = K extends unknown ? keyof StepValues & string : never; /** * Value type of a field. Across several steps, the union of its types. * @public */ export type StepFieldValue, K extends keyof T, N extends string> = K extends unknown ? N extends keyof StepValues ? StepValues[N] : never : never; /** * The field a `Stepper.Control` passes to its render function. * @public */ export interface StepperControlField { /** * The field name, without any step prefix. */ name: string; /** * The current value in the store. `null` while the store holds no value. */ value: V | null; /** * Writes a new value to the store. */ onChange: (value: V) => void; } /** * Props of `Stepper.Control`. * @public */ export interface StepperControlProps = Record, K extends keyof T & string = keyof T & string, N extends StepFieldName = StepFieldName> { /** * Narrows `name` and the value type. The field always belongs to the * enclosing step. */ step?: K; /** * Identifies the field within its step. */ name: N; /** * Render function that receives the field and returns the control. */ children: (field: StepperControlField>) => ReactNode; } /** * The values, status and setters of one step, returned by `useStep`. * @public */ export interface UseStepResult = Record, K extends keyof T & string = keyof T & string> { /** * The id of the step the hook reads and writes. */ id: K; /** * The step's values. */ values: StepValues; /** * The step's status. */ status?: StepStatus; /** * Shallow-merges into the step's values. */ setValues: (update: Partial> | ((prev: StepValues) => Partial>)) => void; /** * Writes the step's status. */ setStatus: (status: StepStatus | undefined) => void; } /** * Config object of `useStep`. * @public */ export interface UseStepConfig = Record, K extends keyof T & string = keyof T & string> { /** * The step to read and write. Defaults to the enclosing `Stepper.Step`. * Pass it to access another step's data, also from outside a * `Stepper.Step`. */ id?: K; /** * The step's initial values. Read once, on the first render of the step. * Later changes to this value are ignored, and `resetStepData` returns the * step to the value from that first render. To fill in data that loads * later, use `setValues` instead. * * It never overwrites a value already in the store. Fields it does not name * start as `null`. Applies to the step named by `id`. If several `useStep` * calls name the same step, pass `initialState` in only one of them. * @defaultValue \{\} */ initialState?: Partial>; } /** * Type of `Stepper.Step`, typed with the step ids and payload of the Stepper. * @public */ export type StepperStepComponent> = (props: StepperStepProps, keyof T & string>) => JSX.Element | null; /** * Type of the `Stepper` returned by `createStepper`, including its compound * components such as `Stepper.Step` and `Stepper.Control`. * @public */ export type StepperComponent = Record> = ((props: StepperProps) => JSX.Element) & { Step: StepperStepComponent; Title: (props: WithChildren) => ReactNode; Description: (props: WithChildren) => ReactNode; Hint: (props: WithChildren) => ReactNode; ErrorMessage: (props: WithChildren) => ReactNode; Content: (props: WithChildren) => ReactNode; Control: = StepFieldName>(props: StepperControlProps) => JSX.Element; }; /** * Type of `useStepper`. Reads the Stepper store, optionally narrowed by a * selector. * @public */ export type UseStepper = Record> = >(selector?: (state: StepperStore) => TSelected) => TSelected; /** * Type of `useStep`. Reads and writes the data of one step, given by id or by * the enclosing `Stepper.Step`. * @public */ export type UseStep = Record> = (idOrConfig?: K | UseStepConfig) => UseStepResult; //# sourceMappingURL=Stepper.types.d.ts.map