Skip to main content

Module: @robo-wizard/react

Type aliases

WizardProviderProps

Ƭ WizardProviderProps<Values>: PropsWithChildren<{ initialValues?: Values }>

Type parameters

NameType
Valuesextends Record<string, unknown>

Defined in

react/src/contexts/index.tsx:41

Variables

WizardContext

Const WizardContext: Context<null | RoboWizard<object>>

internal

Defined in

react/src/contexts/index.tsx:39

Functions

Step

Step(_props): React.ReactElement | null

Parameters

NameType
_propsStepConfig<object> & { element: ReactNode }

Returns

React.ReactElement | null

Defined in

react/src/contexts/index.tsx:8


Wizard

Wizard<Values>(props): Element

example Set up the Wizard with Step components

function App() {
return (
<Wizard<Values> initialValues={{ firstName: '', lastName: '' }}>
<Step name="first" element={<First />} />
<Step name="second" element={<Second />} />
<Step name="third" element={<Third />} />
</Wizard>
)
}

example An example step component

const First = () => {
const wizard = useWizardContext<Values>();

const onSubmit = (event: FormEvent<HTMLFormElement>) => {
event.preventDefault();
const values = Object.fromEntries(new FormData(event.currentTarget))
wizard.goToNextStep({ values })
}

return (
<>
<p>{wizard.currentStep} step</p>
<form onSubmit={onSubmit}>
<div>
<label htmlFor="firstName" id="firstName-label">
First Name:
</label>
<input
type="text"
name="firstName"
id="firstName"
aria-labelledby="firstName-label"
defaultValue={wizard.currentValues.firstName}
autoFocus={true}
/>
</div>
<div>
<button type="button" onClick={() => wizard.goToPreviousStep()} role="link">Previous</button>
<button type="submit">Next</button>
</div>
</form>
</>
)
}

Type parameters

NameTypeDescription
Valuesextends Record<string, unknown>Optional object to describe values being gathered by the wizard

Parameters

NameTypeDescription
propsWizardProviderProps<Values>Create a wizard experience

Returns

Element

Defined in

react/src/contexts/index.tsx:104


createStepsFromChildren

createStepsFromChildren(steps): StepConfig & { element: ReactNode }[]

Parameters

NameTypeDescription
stepsReactNode= The Children opaque object passed to components, only Step components will be processed

Returns

StepConfig & { element: ReactNode }[]

Defined in

react/src/contexts/index.tsx:15


useWizard

useWizard<Values>(steps, initialValues?, actions?): RoboWizard<Values>

example Basic usage


const App: React.FC = () => {
const wizard = useWizard<Values>(['first', 'second', 'third']);

const onSubmit: React.FormEventHandler<HTMLFormElement> = event => {
event.preventDefault();
const values = Object.fromEntries(new FormData(event.currentTarget))
wizard.goToNextStep({ values });
};

return (
<div>
<p>{wizard.currentStep} step</p>
<form onSubmit={onSubmit}>
{wizard.currentStep === 'first' && (
<div>
<label
htmlFor="firstName"
id="firstName-label"
>
First Name:
</label>
<input
type="text"
name="firstName"
id="firstName"
aria-label="firstName-label"
defaultValue={wizard.currentValues.firstName}
/>
</div>
)}

{wizard.currentStep === 'second' && (
<div>
<label
htmlFor="lastName"
id="lastName-label"
>
Last Name:
</label>
<input
type="text"
name="lastName"
id="lastName"
aria-label="lastName-label"
defaultValue={wizard.currentValues.lastName}
/>
</div>
)}

{wizard.currentStep === 'third' && (
<div>
<p>
Welcome {wizard.currentValues.firstName}{' '}
{wizard.currentValues.lastName}!
</p>
</div>
)}

<div>
<button
type="button"
role="link"
onClick={() => wizard.goToPreviousStep()}
>
Previous
</button>
<button type="submit">
Next
</button>
</div>
</form>
</div>
);
};

Type parameters

NameTypeDescription
Valuesextends object = objectGeneric type for object of values being gathered through the wizard steps

Parameters

NameTypeDescription
stepsFlowStep<Values>[]Configuration of steps for the wizard, see FlowStep
initialValuesValuesOptional object with intial values to use when starting the wizard
actionsundefined | { navigate?: ActionFunction<object, WizardEvent<object>> }Optional object with navigate field with a function to be called when entering a step

Returns

RoboWizard<Values>

Defined in

react/src/hooks/use-wizard.ts:89


useWizardContext

useWizardContext<Values>(): RoboWizard<Values>

Type parameters

NameTypeDescription
Valuesextends objectobject describing the currentValues gathered by RoboWizard Access the RoboWizard from the Wizard Context Provider

Returns

RoboWizard<Values>

Defined in

react/src/contexts/index.tsx:121