Use the Context API to share data between steps
mainTo share data (like form state) across multiple steps, pass a context prop to the Stepper. This prop should be a function that returns a Svelte writable store.
Every step component within that stepper will automatically receive a context prop containing that same writable store, allowing steps to read from and write to the shared state.
// In the parent page
<script lang="ts">
import { Stepper, makeStep } from '@efstajas/svelte-stepper';
import { writable, type Writable } from 'svelte/store';
interface MyContext { foo: string; bar: number; }
const exampleContext = () => writable<MyContext>({ foo: 'bar', bar: 42 });
const exampleSteps = [ /* ... steps ... */ ];
</script>
<Stepper steps={exampleSteps} context={exampleContext} />
// Inside a Step component
<script lang="ts">
import { createStepController } from '@efstajas/svelte-stepper';
import type { Writable } from 'svelte/store';
import type { MyContext } from './parent.svelte';
export let context: Writable<MyContext>;
const stepController = createStepController();
</script>
<button on:click={() => context.update(v => ({ ...v, bar: v.bar + 1 }))}>Increment</button>
<button on:click={stepController.nextStep}>Next</button>