Not only React anymoreStepperize now runs in Vue, Svelte, Solid, Angular, Lit, and HTML
Skip to Content
Stepperize

defineStepper

The definition and everything it returns.

import { defineStepper } from "@stepperize/svelte";

const checkout = defineStepper(steps, options?);
ArgumentDescription
stepsAn array of steps. Each needs a unique id; schema types and validates its data; every other field is yours.
optionsDefaults for every flow created from this definition. See Options.

It returns:

stepsThe array you passed.
useStepper(options?)A flow owned by the calling component.
useStepperContext()The flow of the nearest Provider or Stepper.Root.
ProviderShares one flow with the components below.
StepperThe primitives. Not in /headless.
create(options?)A flow without Svelte. See Core. Wrap it in fromFlow to read it reactively.

useStepper

const stepper = checkout.useStepper();
const stepper = checkout.useStepper({ linear: true, onFinish });
const stepper = checkout.useStepper(() => ({ step: page.params.step }));

Call it while the component initialises. It returns the stepper as a reactive object: reads are tracked, so markup, $derived and $effect follow the flow. Do not destructure its state.

  • Options can be an object or a function. A function is read again when the state it uses changes, and the flow gets the new options.
  • snapshot is read once, when the flow is created.
  • The flow is destroyed with the component: a running move is cancelled.
  • On the server it renders the current step and runs no callback.
  • Outside a component (module scope, an event handler) it throws SZ104 in the browser: nothing would destroy the flow. On the server it does not throw, so a call at module scope can pass server rendering and fail once the page runs; never call it there. Use fromFlow instead.

useStepperContext

const stepper = checkout.useStepperContext();

Returns the shared reactive stepper. Call it while the component initialises. Outside the flow's Provider or Stepper.Root it throws SZ100.

There is no selector argument: wrap what you need in $derived.

Provider

<checkout.Provider linear snapshot={saved} onChange={save} onFinish={submit}>
  {@render children()}
</checkout.Provider>

Every option is a prop. It renders its children and no element.

fromFlow

import { fromFlow } from "@stepperize/svelte";

const flow = checkout.create({ linear: true });
const stepper = fromFlow(flow);

Turns a flow you created into the same reactive stepper useStepper() returns. It creates no effect, so it works in a .svelte.ts module, a class or a component that receives a flow from elsewhere. It is also exported by /headless.

  • It subscribes to the flow only while an effect reads it, and stops with the last one. Outside an effect a read returns the latest state.
  • The flow stays yours: change its options with flow.setOptions() and stop it with flow.destroy().
  • At module scope the flow is shared by everything that imports it, on the server too: see Outside a component.

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 primitives' props are exported too (RootProps<S>, ButtonProps, ChildProps and the others): see Primitives.

Edit on GitHub

Last updated on

On this page