wizzard-stepper-react 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 Aziz
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,163 @@
1
+ # wizzard-stepper-react 🧙‍♂️
2
+
3
+ A flexible, headless, and strictly typed multi-step wizard library for React. Built with adapter patterns in mind to support any form library (React Hook Form, Formik, etc.) and any validation schema (Zod, Yup).
4
+
5
+ ## Features
6
+
7
+ - 🧠 **Headless Architecture**: Full control over UI. You bring the components, we provide the logic.
8
+ - 🔌 **Adapter Pattern**: Built-in adapters for **Zod**, **Yup** validation, and **LocalStorage/URL/Memory** persistence.
9
+ - 🛡️ **Strictly Typed**: Built with TypeScript generics for type safety across steps.
10
+ - 🔀 **Conditional Steps**: Dynamic pipelines where steps can be skipped based on data.
11
+ - 💾 **Persistence**: Auto-save progress to LocalStorage or custom stores.
12
+ - ⚡ **Auto Validation**: Block navigation until the step is valid.
13
+
14
+ ## Installation
15
+
16
+ ```bash
17
+ npm install wizzard-stepper-react zod
18
+ # or
19
+ yarn add wizzard-stepper-react zod
20
+ ```
21
+
22
+ ## Quick Start (Native Forms)
23
+
24
+ ```tsx
25
+ import { WizardProvider, useWizard, IWizardConfig } from 'wizzard-stepper-react';
26
+
27
+ // 1. Define Config
28
+ const config: IWizardConfig = {
29
+ steps: [
30
+ { id: 'personal', label: 'Personal Info' },
31
+ { id: 'contact', label: 'Contact Details' },
32
+ ],
33
+ };
34
+
35
+ // 2. Create Steps
36
+ const Step1 = () => {
37
+ const { handleStepChange, wizardData } = useWizard<{ name: string }>();
38
+ return (
39
+ <input
40
+ value={wizardData.name || ''}
41
+ onChange={e => handleStepChange('name', e.target.value)}
42
+ />
43
+ );
44
+ };
45
+
46
+ // 3. Wrap in Provider
47
+ export default function App() {
48
+ return (
49
+ <WizardProvider config={config}>
50
+ <WizardContent />
51
+ </WizardProvider>
52
+ );
53
+ }
54
+
55
+ const WizardContent = () => {
56
+ const { currentStep, goToNextStep } = useWizard();
57
+ if(!currentStep) return null;
58
+ return (
59
+ <div>
60
+ {currentStep.id === 'personal' && <Step1 />}
61
+ <button onClick={goToNextStep}>Next</button>
62
+ </div>
63
+ )
64
+ }
65
+ ```
66
+
67
+ ## Integration with React Hook Form + Zod
68
+
69
+ ```tsx
70
+ import { useForm } from 'react-hook-form';
71
+ import { zodResolver } from '@hookform/resolvers/zod';
72
+ import { z } from 'zod';
73
+ import { ZodAdapter, useWizard } from 'wizzard-stepper-react';
74
+
75
+ const schema = z.object({ email: z.string().email() });
76
+
77
+ const MyStep = () => {
78
+ const { handleStepChange, wizardData } = useWizard();
79
+ const { register } = useForm({
80
+ defaultValues: wizardData,
81
+ resolver: zodResolver(schema),
82
+ mode: 'onChange' // Important: validate real-time or bind changes
83
+ });
84
+
85
+ return (
86
+ <input {...register('email', {
87
+ onChange: (e) => handleStepChange('email', e.target.value)
88
+ })} />
89
+ );
90
+ }
91
+
92
+ // In Config:
93
+ const config = {
94
+ steps: [
95
+ {
96
+ id: 'step1',
97
+ label: 'Email',
98
+ validationAdapter: new ZodAdapter(schema) // Blocks 'Next' if invalid
99
+ }
100
+ ]
101
+ }
102
+ ```
103
+
104
+ ## Conditional Steps
105
+
106
+ Steps can be dynamically included based on the wizard's state.
107
+
108
+ ```tsx
109
+ const config: IWizardConfig = {
110
+ steps: [
111
+ { id: 'start', label: 'Start' },
112
+ {
113
+ id: 'bonus',
114
+ label: 'Bonus Step',
115
+ // Only show if 'wantBonus' is true
116
+ condition: (data) => !!data.wantBonus
117
+ }
118
+ ]
119
+ }
120
+ ```
121
+
122
+ ## Persistence
123
+
124
+ Save progress automatically to LocalStorage to survive page reloads.
125
+
126
+ ```tsx
127
+ import { LocalStorageAdapter } from 'wizzard-stepper-react';
128
+
129
+ const config: IWizardConfig = {
130
+ persistence: {
131
+ mode: 'onChange', // Save on every keystroke
132
+ adapter: new LocalStorageAdapter('my_wizard_prefix_')
133
+ },
134
+ steps: [...]
135
+ }
136
+ ```
137
+
138
+ ## API Reference
139
+
140
+ ### `IWizardConfig<T>`
141
+ - `steps`: Array of step configurations.
142
+ - `persistence`: Configuration for state persistence.
143
+ - `autoValidate`: (obj) Global validation setting.
144
+
145
+ ### `useWizard<T>()`
146
+ - `activeSteps`: Steps that match conditions.
147
+ - `currentStep`: The currently active step object.
148
+ - `wizardData`: The global state object.
149
+ - `handleStepChange(key, value)`: Helper to update state.
150
+ - `goToNextStep()`: Validates and moves next.
151
+ - `goToStep(id)`: Jumps to specific step.
152
+ - `allErrors`: Map of validation errors.
153
+
154
+ ## Demos
155
+
156
+ Check out the [official demo repository](https://github.com/ZizzX/wizzard-stepper-react-demo) for a complete implementation featuring:
157
+ - **Tailwind CSS v4** UI overhaul.
158
+ - **React Hook Form + Zod** integration.
159
+ - **Formik + Yup** integration.
160
+ - **Conditional Routing** logic.
161
+
162
+ ## License
163
+ MIT