defineStepper
The definition and everything it returns.
import { defineStepper } from "@stepperize/solid";
const checkout = defineStepper(steps, options?);| Argument | Description |
|---|---|
steps | An array of steps. Each needs a unique id; schema types and validates its data; every other field is yours. |
options | Defaults for every flow created from this definition. See Options. |
It returns:
steps | The array you passed. |
useStepper(options?) | A flow owned by the calling component. |
useStepperContext(selector?) | The flow of the nearest Provider or Stepper.Root. |
Provider | Shares one flow with the components below. |
Stepper | The primitives. Not in /headless. |
create(options?) | A flow without Solid. See Core. |
useStepper
const stepper = checkout.useStepper();
const stepper = checkout.useStepper({ linear: true, onFinish });
const stepper = checkout.useStepper(() => ({ step: params.step }));It returns the stepper as a reactive object: reads are tracked, so JSX, memos and effects follow the flow. Do not destructure its state.
- Options can be an object or a function. Pass a function when an option depends on a signal or on props.
- Callbacks (
onChange,onFinish,onInvalidStep,guard) andnextare read when the flow calls them, so it always calls the latest, even one changed in the samebatchas the action, or under aSuspensethat is still loading. linearandstepare followed when they change, once the component is mounted.snapshotis read once, when the flow is created.- An option that is
undefinedkeeps the definition's default, like an absent prop. - The flow is destroyed with its owner: the component, or the
createRootit was called under. - On the server it renders the current step and runs no callback.
useStepperContext
const stepper = checkout.useStepperContext();
const index = checkout.useStepperContext((stepper) => stepper.index); // Accessor<number>Without arguments it returns the shared reactive stepper. With a selector it
returns a memo of its result; the selector receives an immutable view of the
flow. Outside the flow's Provider or Stepper.Root it throws
SZ100.
Provider
<checkout.Provider linear snapshot={saved} onChange={save} onFinish={submit}>
{props.children}
</checkout.Provider>Every option is a prop, read like
useStepper's options. It renders its children and no element. Providers nest:
each component reads the nearest one of its own definition.
Types
Everything @stepperize/core exports as a type is re-exported:
Stepper<S>, Options<S>, Snapshot<S>, Result<S>, Id<S> and the rest.
The props of the primitives are exported too: RootProps<S>,
ListProps<S, T>, ItemProps<S, T>, ContentProps<S, T>, ButtonProps<T>
and TextProps<T>, where T is what as renders (its default tag when
omitted). PolymorphicProps<T, Own> builds the same shape for your own
wrappers.
Last updated on