An open API service indexing awesome lists of open source software.

https://github.com/uduma-sonia/svelte-wizard

A flexible and customizable stepper component for Svelte, perfect for building multi-step forms with progress indicators.
https://github.com/uduma-sonia/svelte-wizard

stepper svelte svelte-library svelte-stepper wizard

Last synced: 5 months ago
JSON representation

A flexible and customizable stepper component for Svelte, perfect for building multi-step forms with progress indicators.

Awesome Lists containing this project

README

          

# Svelte Wizard


A flexible, customizable stepper component for Svelte โ€” perfect for building multi-step forms with progress indicators.


Style each step, control navigation, and manage form state your way.


npm version
Pull requests welcome


> โš ๏ธ Minimum supported Svelte version: **v5**

---

![Svelte Wizard in action](https://res.cloudinary.com/dbqgv8zl7/image/upload/v1731450316/record_jrxr2b.gif)

### ๐Ÿ“บ [Live Demo](https://svelte-wizard.netlify.app) | ๐Ÿงช [Playground](https://svelte.dev/playground/740a81ce5023497eba5c4ebd7f8ec6ad?version=5.1.16)

---

## โšก Features

- Custom styling for steps, titles, and progress
- Step navigation and state tracking
- Built-in progress bar
- Animated transitions
- Event dispatching
- Centralized form state

# Installation

```
$ npm i svelte-wizard
```


# ๐Ÿงฉ Basic Usage

```

import { WizardComponent } from 'svelte-wizard';
import StepOne from './StepOne.svelte';
import StepTwo from './StepTwo.svelte';
import StepThree from './StepThree.svelte';

let stepsList = [
{ step: StepOne, title: 'Step One' },
{ step: StepTwo, title: 'Step Two' },
{ step: StepThree, title: 'Step Three' }
];

```


# โš™๏ธ With Options

```

import { WizardComponent } from 'svelte-wizard';

let stepsList = [...];

let options = $state({
showTitles: true,
showCheckIcon: false
});

```


# ๐ŸŽจ With Custom Class Names

```

import { WizardComponent } from 'svelte-wizard';

let stepsList = [...];

let customClassnames = $state({
activeTitleClass: 'activeTitleClass'
});

```



# ๐Ÿงช Props Reference

### Bindable

| Props | Type | Description |
| --------------- | -------- | ---------------------------------- |
| currentIndex | `number` | Index of the current step |
| wizardFormState | `object` | Shared form state across all steps |


### `stepsList`

| Prop | Type | Description |
| ----- | ----------------- | ---------------------------- |
| step | `SvelteComponent` | The step component to render |
| title | `string` | Title of the step |
| icon | `SvelteComponent` | Optional icon for the step |


### `options`

| Prop | Type | Default | Description |
| ------------------- | ------- | ------- | ----------------------------------------------------------------------------- |
| showTitles | boolean | `true` | Show titles for each step |
| showOneTitle | boolean | `false` | Show only the active step title (requires `showTitles` and `showProgressBar`) |
| showCheckIcon | boolean | `false` | Show check icon on completed steps |
| showStepCount | boolean | `true` | Show step numbers |
| clickableNavigation | boolean | `false` | Allow users to click step indicators to navigate |
| shouldAnimate | boolean | `true` | Animate transitions between steps |
| showProgressBar | boolean | `true` | Display progress bar |
| defaultStep | number | `0` | Index of the initial step |


### `customClassnames`

| Prop | Type | Description |
| ----------------------- | ------ | ---------------------------------------------- |
| activeTitleClass | string | CSS class for active/completed step titles |
| inactiveTitleClass | string | CSS class for inactive step titles |
| activeBarItemClass | string | CSS class for active progress items (dot/line) |
| inactiveBarItemClass | string | CSS class for inactive progress items |
| activeStepNumberClass | string | CSS class for active/current step number |
| inactiveStepNumberClass | string | CSS class for inactive step numbers |



# ๐Ÿ“ฃ Events

Svelte wizard provides custom events to the parent and child components giving control over navigation and form state management.

### Examples

Parent Component

```

console.log(e)} />
```


Child Component

```

let { handleBack, handleSkipTo, handleNext, handleSkipToEnd,handleReset } = $props();

Next
Skip

```

| Event/Prop | Triggered by | Description |
| --------------------- | ------------ | ----------------------------------------------- |
| `onStepChange` | Parent | Fires when current step changes |
| `handleNext` | Child | Goes to the next step |
| `handleBack` | Child | Goes to the previous step |
| `handleSkipTo(index)` | Child | Skips to a specific step |
| `handleSkipToEnd` | Child | Skips to the final step |
| `handleSkipToStart` | Child | Skips to the first step |
| `handleReset` | Child | Resets form state and returns to the first step |
| `handleStateUpdate` | Child | Updates shared `wizardFormState` |



# ๐Ÿง  State Management

Svelte Wizard provides a centralized wizardFormState shared across all steps. You can update it using handleStateUpdate


### Accessing `wizardFormState`

```

let { wizardFormState } = $props();
let firstName = $state(wizardFormState?.firstName);

```

### Using `handleStateUpdate`

```

let { handleStateUpdate, wizardFormState } = $props();

const submit = () => {
handleStateUpdate('firstName', 'Jane'); // Set a single key
handleStateUpdate({ lastName: 'Doe' }); // Merge object
handleStateUpdate({ firstName: 'Jane', lastName: 'Doe' }, { replaceAll: true }); // Replace state
};

```

### `handleStateUpdate` Argument Types

| Argument | Type | Description |
| --------------- | ------------------------------- | ------------------------------------- |
| key + value | string, any | Updates a specific field in the state |
| object | object | Merges into `wizardFormState` |
| object + config | object, { replaceAll: boolean } | Optionally replaces the entire state |

## defaultFormState

Svelte wizard also accepts the `defaultFormState` props used to define default data for `wizardFormState`

```

```



# ๐ŸŽจ Using Custom CSS Classes

To scope styles locally, use :global:

```
:global(.activeTitleClass) { /* styles */ }
:global(.inactiveTitleClass) { /* styles */ }
:global(.activeBarItemClass) { /* styles */ }
:global(.inactiveBarItemClass) { /* styles */ }
:global(.activeStepNumberClass) { /* styles */ }
:global(.inactiveStepNumberClass) { /* styles */ }
```

## ๐Ÿค Contributing

Pull requests are welcome! If you'd like to add features or fix bugs, feel free to fork and submit a PR.


## โš–๏ธ Licence

MIT (c) [Sonia Uduma](https://sohnya.dev)