{"id":13806410,"url":"https://github.com/efstajas/svelte-stepper","last_synced_at":"2025-04-05T03:12:01.466Z","repository":{"id":152878645,"uuid":"627435574","full_name":"efstajas/svelte-stepper","owner":"efstajas","description":"🚶 A simple library for building delightfully animated stepped flows with Svelte.","archived":false,"fork":false,"pushed_at":"2024-12-10T10:21:12.000Z","size":4397,"stargazers_count":154,"open_issues_count":6,"forks_count":4,"subscribers_count":3,"default_branch":"main","last_synced_at":"2025-03-29T02:08:37.227Z","etag":null,"topics":["animations","component","stepper","svelte","sveltekit"],"latest_commit_sha":null,"homepage":"https://svelte-stepper.jason-e.dev","language":"Svelte","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/efstajas.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2023-04-13T13:13:10.000Z","updated_at":"2025-03-01T17:09:14.000Z","dependencies_parsed_at":"2025-01-15T17:33:46.593Z","dependency_job_id":"cdc17cc3-0365-4720-b6ca-382c1e6ab63e","html_url":"https://github.com/efstajas/svelte-stepper","commit_stats":null,"previous_names":[],"tags_count":7,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/efstajas%2Fsvelte-stepper","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/efstajas%2Fsvelte-stepper/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/efstajas%2Fsvelte-stepper/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/efstajas%2Fsvelte-stepper/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/efstajas","download_url":"https://codeload.github.com/efstajas/svelte-stepper/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247280272,"owners_count":20912967,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["animations","component","stepper","svelte","sveltekit"],"created_at":"2024-08-04T01:01:11.387Z","updated_at":"2025-04-05T03:12:01.449Z","avatar_url":"https://github.com/efstajas.png","language":"Svelte","funding_links":[],"categories":["UI Components"],"sub_categories":["Miscellaneous"],"readme":"# 🚶 Svelte Stepper\n\n![GIF of Svelte Stepper in action](https://github.com/efstajas/svelte-stepper/raw/main/docs/demo.gif)\n\nA simple library for building delightfully animated stepped flows with Svelte. Svelte Stepper is completely \"headless\", meaning it steps through whatever components you give it, putting you in full control of container- and step layout, styles and transitions.\n\n## 🌍 Interactive demo \u0026 docs\n\nCheck out an simple demo implementation at [svelte-stepper.jason-e.dev](https://svelte-stepper.jason-e.dev/).\n\nYou can find the code for the above at `/src/routes` in this repo as a usage example.\n\n## ✨ Features\n\nSvelte Stepper comes with a lot of built-in functionality, while still remaining easy-to-use at its core.\n\n### Simple \u0026 type-safe\n\nSvelte Stepper is written entirely in TypeScript, and all its interfaces are fully type-safe out of the box. To get started, all you need to do is provide a sequence of Svelte components as steps. Every step can receive custom props.\n\n### Delightful animations\n\nSvelte Stepper automatically transitions steps in a delightful way, and even smoothly adjusts its height to match each new step component. Of course, you can fully customize all animations.\n\n### Context \u0026 multi-step forms\n\nSvelte Stepper includes a full context API, which allows you to share data between steps. This enables advanced usecases like building up form data over several steps, and submitting it at the end.\n\n## 💾 Installation\n\nInstall with NPM or yarn:\n\n```bash\nnpm install @efstajas/svelte-stepper\n```\n\n```bash\nyarn add @efstajas/svelte-stepper\n```\n\n## 👋 Getting started\n\nGetting a simple flow going is easy. First, let's create a few Step components.\n\n### Creating Steps\n\nA step is simply a normal Svelte component, which can dispatch a number of special events in order to communicate with the stepper. Here's a very simple step with some text and a button that advances the flow to the next step:\n\n```ts\n\u003cscript lang=\"ts\"\u003e\n  import { createStepController } from '@efstajas/svelte-stepper';\n\n  const stepController = createStepController();\n\u003c/script\u003e\n\n\u003ch1\u003eMy first step\u003c/h1\u003e\n\n\u003cbutton on:click={stepController.nextStep}\u003eNext\u003c/button\u003e\n```\n\nAs you can see, Svelte Stepper exposes a `createStepController` function, which you can use to create a `stepController`. This object contains a number of functions for communicating with the stepper, such as `nextStep` and `previousStep`.\n\nGo ahead and create two simple step components so that we can move on to creating our first flow.\n\n### Initializing the Stepper\n\nGetting a simple flow going is easy. The core of Svelte Stepper is the `Stepper` component. Simply import it into your page, and provide an array of your steps using the `makeStep` utility.\n\n```ts\n\u003cscript lang=\"ts\"\u003e\n  import { Stepper, makeStep } from '@efstajas/svelte-stepper';\n\n  /* ... import your step components here ... */\n\n  const exampleSteps = [\n    makeStep({\n      component: MyFirstStep,\n      props: undefined\n    }),\n    makeStep({\n      component: MySecondStepWithProps,\n      props: {\n        foo: 'bar',\n      },\n    }),\n    makeStep({\n      component: MyFinalStep,\n      props: undefined\n    })\n  ];\n\u003c/script\u003e\n\n\u003cStepper steps={exampleSteps} /\u003e\n```\n\nAs you can see, you can pass props to your step components using the `props` property. The type of this property is automatically inferred from the provided step component.\n\nCongratulations! This is everything you need to build a simple flow. Let's have a look at some more advanced features.\n\n### A note on padding\n\nThe stepper component automatically hides step overflow during transitions in order to prevent steps from overflowing the container during transition, which doesn't look very nice. If you want to add padding around your steps, please pass a `padding` prop to the Stepper component, instead of wrapping the container in a padded element. This ensures that transitions aren't visually cut off by the step container.\n\n## 🎥 Animations\n\nSvelte Stepper automatically transitions between your steps with a sleek animation by default. Of course, you can fully customize the entry- and exit transitions for steps.\n\n### Customizing the transition duration\n\nIf all you want to do is change the duration of the default transition, you can pass a `defaultTransitionDuration` prop to the stepper. Out of the box, it's set to 300 milliseconds. This prop controls the speed of the stepper container height transition, as well as the step's entry- and exit transitions.\n\n```ts\n\u003cStepper\n  steps={exampleSteps}\n  defaultTransitionDuration={1000}\n/\u003e\n```\n\n### Using custom transition functions and -parameters\n\nIf you want to set fully custom transitions, you can set the `stepIntroTransition` and `stepOutroTransition` props on the stepper.\n\n```ts\n\u003cStepper\n  steps={exampleSteps}\n  defaultTransitionDuration={600}\n  stepOutroTransition={{\n    transitionFn: scale,\n    params: () =\u003e ({\n      duration: 600,\n      delay: 0,\n      scale: 1,\n    }),\n  }}\n  stepIntroTransition={{\n    transitionFn: fly,\n    params: (direction) =\u003e ({\n      duration: 600,\n      delay: 0,\n      x: direction === 'forward' ? 100 : -100,\n    }),\n  }}\n/\u003e\n```\n\nThese props accept an object with `transitionFn` and `params` properties. Pass any standard Svelte transition function, and set any custom parameters for it. The `params` property accepts a function with an optional `direction` parameter, allowing you to alter the transition parameters based on whether the user is currently navigating forward or backward within the flow.\n\n## 💽 Context API\n\nStepped flows frequently collect a bunch of data from the user over multiple steps, and submit it at the end. For exactly this use-case, Svelte Stepper comes with a context system. It allows you to conveniently share a single Svelte `writable` store between all steps.\n\nTo define context, simply write a function that returns a Svelte `writable` store, and pass it to the Stepper component:\n\n```ts\n\u003cscript lang=\"ts\" context=\"module\"\u003e\n  export interface MyExampleStepperContext {\n    foo: string;\n    bar: number;\n  }\n\u003c/script\u003e\n\n\u003cscript lang=\"ts\"\u003e\n  import { Stepper, makeStep } from '@efstajas/svelte-stepper';\n\n  /* ... import your step components here ... */\n\n  const exampleSteps = [\n    makeStep({\n      component: MyFirstStep,\n      props: undefined\n    }),\n  ];\n\n  const exampleContext: () =\u003e Writable\u003cMyExampleStepperContext\u003e = () =\u003e writable({\n    foo: 'bar',\n    bar: 42,\n  });\n\u003c/script\u003e\n\n\u003cStepper steps={exampleSteps} context={exampleContext} /\u003e\n```\n\nIn this particular example, we're exporting the type of our context writable from a module, so that we can properly type the context writable in our step components later.\n\nPassing `context` to the Stepper will make it automatically available to all steps as a `context` prop:\n\n```ts\n\u003cscript lang=\"ts\"\u003e\n  import { Writable } from 'svelte/store';\n  import { MyExampleStepperContext } from './my-stepper-page.svelte';\n  import { createStepController } from '@efstajas/svelte-stepper';\n\n  const stepController = createStepController();\n\n  export let context: Writable\u003cMyExampleStepperContext\u003e;\n\u003c/script\u003e\n\n\u003ch1\u003eMy first step\u003c/h1\u003e\n\n\u003cp\u003e\n  Foo is {$context.foo} and bar is {$context.bar}.\n\u003c/p\u003e\n\n\u003cbutton on:click={context.update((v) =\u003e ({ ...v, bar: v.bar + 1}))}\u003eIncrement bar\u003c/button\u003e\n\n\u003cbutton on:click={stepController.nextStep}\u003eNext\u003c/button\u003e\n```\n\nUsing this method, you can incrementally populate a store of data throughout multiple steps.\n\n## 📬 Stepper Events\n\nThe Stepper component emits events allowing you to react to a step change or conclusion of the flow.\n\n```ts\n\n\u003cStepper\n  steps={exampleSteps}\n  on:conclusion={() =\u003e {\n    alert('The last step in the flow has called stepController.nextStep()!');\n  }}\n  on:stepChange={(e) =\u003e {\n    const { newIndex, of, direction } = e.detail;\n\n    console.log(\\`Changed to step \\${newIndex + 1} of \\${of} going \\${direction}\\`);\n  }}\n/\u003e\n```\n\nThe `stepChange` event is emitted when the stepper moves to a new step. It includes metadata on the current step index, the total amount of steps, as well as the direction of the change.\n\nThe `conclusion` event is emitted when the stepper has reached the last step and `nextStep` is called.\n\n## 🕺 Side-Steps\n\nSometimes, you may need to temporarily switch to a different set of steps within a flow. Svelte Stepper includes `sidestep` functionality for this purpose. Using a side-step, you can easily temporarily launch a different flow, and come back to the original flow at the end.\n\nTo trigger a side-step, simply call `stepController.sidestep(steps)` within a step component, where `steps` is an array of new steps:\n\n```ts\n\u003cscript lang=\"ts\"\u003e\n  import { createStepController } from '@efstajas/svelte-stepper';\n\n  import MyFirstSidestepStep from './my-first-sidestep-step.svelte';\n\n  const stepController = createStepController();\n\u003c/script\u003e\n\n\u003ch1\u003eLaunching a sidestep\u003c/h1\u003e\n\n\u003cbutton on:click={() =\u003e stepController.sidestep([\n  makeStep({\n    component: MyFirstSidestepStep,\n    props: undefined\n  }),\n])}\u003eStart sidestep\u003c/button\u003e\n```\n\nWithin a sidestep, you can use the usual `nextStep` and `previousStep` methods to navigate between steps. Once you reach the end of the sidestep flow, the stepper will automatically navigate back to the original flow.\n\nYou can also cancel a sidestep anywhere within the sidestep flow by calling `stepController.cancelSidestep()`. This will end the sidestep flow immediately, and navigate back to where the sidestep was triggered from within the original flow.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fefstajas%2Fsvelte-stepper","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fefstajas%2Fsvelte-stepper","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fefstajas%2Fsvelte-stepper/lists"}