wizzard-stepper-react 1.7.1 โ 2.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 +21 -21
- package/README.md +158 -431
- package/dist/index.cjs +1 -954
- package/dist/index.d.cts +309 -63
- package/dist/index.d.ts +309 -63
- package/dist/index.js +1 -921
- package/package.json +98 -93
- package/dist/index.cjs.map +0 -1
- package/dist/index.js.map +0 -1
package/LICENSE
CHANGED
|
@@ -1,21 +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.
|
|
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
CHANGED
|
@@ -1,431 +1,158 @@
|
|
|
1
|
-
# wizzard-stepper-react ๐งโโ๏ธ
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
import {
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
```
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
return <input value={name} onChange={e => setData('users[0].name', e.target.value)} />;
|
|
161
|
-
}
|
|
162
|
-
|
|
163
|
-
// โ SLOW: Re-renders on ANY change in the form
|
|
164
|
-
const NameInputSlow = () => {
|
|
165
|
-
const { wizardData, setData } = useWizard();
|
|
166
|
-
return <input value={wizardData.users[0].name} ... />;
|
|
167
|
-
}
|
|
168
|
-
```
|
|
169
|
-
|
|
170
|
-
### 2. Use `useWizardSelector` for Lists
|
|
171
|
-
|
|
172
|
-
When rendering lists, avoid passing the whole `children` array to the parent component. Instead, select only IDs and let child components fetch their own data.
|
|
173
|
-
|
|
174
|
-
```tsx
|
|
175
|
-
const ChildrenList = () => {
|
|
176
|
-
// โ
Only re-renders when the list LENGTH changes or IDs change
|
|
177
|
-
const childIds = useWizardSelector(state => state.children.map(c => c.id));
|
|
178
|
-
|
|
179
|
-
return (
|
|
180
|
-
<div>
|
|
181
|
-
{childIds.map((id, index) => (
|
|
182
|
-
// Pass ID/Index, NOT the data object
|
|
183
|
-
<ChildRow key={id} index={index} />
|
|
184
|
-
))}
|
|
185
|
-
</div>
|
|
186
|
-
);
|
|
187
|
-
}
|
|
188
|
-
```
|
|
189
|
-
|
|
190
|
-
### 3. Debounced Validation
|
|
191
|
-
|
|
192
|
-
For heavy validation schemas, you can debounce validation to keep the UI responsive.
|
|
193
|
-
|
|
194
|
-
```tsx
|
|
195
|
-
setData('field.path', value, {
|
|
196
|
-
debounceValidation: 300 // Wait 300ms before running Zod/Yup validation
|
|
197
|
-
});
|
|
198
|
-
```
|
|
199
|
-
|
|
200
|
-
## Validation Logic ๐ก๏ธ
|
|
201
|
-
|
|
202
|
-
By default, validation runs on every change (`onChange`). You can optimize this for heavy forms.
|
|
203
|
-
|
|
204
|
-
### โก Performance & Validation
|
|
205
|
-
### granular Validation Control
|
|
206
|
-
- ๐งฉ **Flexible adapters** for any validation or persistence logic
|
|
207
|
-
- โก **High Performance**: Stateless Provider architecture and O(1) internal lookups
|
|
208
|
-
- ๐ฆ **Zero Dependencies** (excluding React as peer)
|
|
209
|
-
You can control when validation happens using `validationMode`. This is critical for performance in large forms or heavy validation schemas.
|
|
210
|
-
|
|
211
|
-
- **`onChange`** (Default): Validates fields as you type (debounced). Best for immediate feedback.
|
|
212
|
-
- **`onStepChange`**: Validates ONLY when trying to move to the next step.
|
|
213
|
-
- *Ux improvement*: If an error occurs, it appears. But as soon as the user starts typing to fix it, the error is **immediately cleared** locally (without triggering a full re-validation schema check), providing instant "clean" feedback.
|
|
214
|
-
- **`manual`**: No automatic validation. You manually call `validateStep()`.
|
|
215
|
-
|
|
216
|
-
```typescript
|
|
217
|
-
const config: IWizardConfig = {
|
|
218
|
-
steps: [
|
|
219
|
-
{
|
|
220
|
-
id: 'heavy-step',
|
|
221
|
-
label: 'Complex Data',
|
|
222
|
-
// Optimize: Only validate on "Next" click
|
|
223
|
-
validationMode: 'onStepChange',
|
|
224
|
-
validationAdapter: new ZodAdapter(heavySchema)
|
|
225
|
-
}
|
|
226
|
-
]
|
|
227
|
-
};
|
|
228
|
-
```
|
|
229
|
-
|
|
230
|
-
### Internal Optimizations
|
|
231
|
-
- **Hash Table Storage**: Errors are stored internally using `Map` (Hash Table) for **O(1)** access and deletion, ensuring UI stays snappy even with hundreds of errors.
|
|
232
|
-
- **Path Caching**: Data access paths (e.g., `users[0].name`) are cached to eliminate parsing overhead during frequent typing.
|
|
233
|
-
|
|
234
|
-
## Conditional Steps
|
|
235
|
-
|
|
236
|
-
Steps can be dynamically included based on the wizard's state.
|
|
237
|
-
|
|
238
|
-
```tsx
|
|
239
|
-
const config: IWizardConfig = {
|
|
240
|
-
steps: [
|
|
241
|
-
{ id: 'start', label: 'Start' },
|
|
242
|
-
{
|
|
243
|
-
id: 'bonus',
|
|
244
|
-
label: 'Bonus Step',
|
|
245
|
-
// Only show if 'wantBonus' is true
|
|
246
|
-
condition: (data) => !!data.wantBonus
|
|
247
|
-
}
|
|
248
|
-
]
|
|
249
|
-
}
|
|
250
|
-
```
|
|
251
|
-
|
|
252
|
-
## ๐พ Persistence
|
|
253
|
-
Automatically save wizard progress so users don't lose data on reload.
|
|
254
|
-
|
|
255
|
-
```typescript
|
|
256
|
-
import { LocalStorageAdapter } from 'wizzard-stepper-react';
|
|
257
|
-
|
|
258
|
-
const config: IWizardConfig = {
|
|
259
|
-
steps: [...],
|
|
260
|
-
persistence: {
|
|
261
|
-
adapter: new LocalStorageAdapter('my-wizard-key'),
|
|
262
|
-
mode: 'onStepChange' // or 'onChange' (heavier)
|
|
263
|
-
}
|
|
264
|
-
};
|
|
265
|
-
```
|
|
266
|
-
Everything (current step, data, visited state) is handled automatically! LocalStorage to survive page reloads.
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
## Advanced Features ๐
|
|
271
|
-
|
|
272
|
-
### 1. Step Renderer (Declarative UI)
|
|
273
|
-
|
|
274
|
-
Instead of manual switch statements with `currentStep.id`, trust the renderer!
|
|
275
|
-
|
|
276
|
-
```typescript
|
|
277
|
-
// Define component in config
|
|
278
|
-
const steps = [
|
|
279
|
-
{ id: 'step1', label: 'Start', component: Step1Component },
|
|
280
|
-
{ id: 'step2', label: 'End', component: Step2Component },
|
|
281
|
-
];
|
|
282
|
-
|
|
283
|
-
// Render
|
|
284
|
-
const App = () => (
|
|
285
|
-
<WizardProvider config={{ steps }}>
|
|
286
|
-
<WizardStepRenderer
|
|
287
|
-
wrapper={({ children }) => (
|
|
288
|
-
<motion.div initial={{ opacity: 0 }} animate={{ opacity: 1 }}>
|
|
289
|
-
{children}
|
|
290
|
-
</motion.div>
|
|
291
|
-
)}
|
|
292
|
-
/>
|
|
293
|
-
</WizardProvider>
|
|
294
|
-
);
|
|
295
|
-
```
|
|
296
|
-
|
|
297
|
-
### 2. Routing Integration
|
|
298
|
-
|
|
299
|
-
Sync wizard state with URL using `onStepChange`.
|
|
300
|
-
|
|
301
|
-
```tsx
|
|
302
|
-
const navigate = useNavigate();
|
|
303
|
-
|
|
304
|
-
const config: IWizardConfig = {
|
|
305
|
-
// 1. Sync State -> URL
|
|
306
|
-
onStepChange: (prev, next, data) => {
|
|
307
|
-
navigate(`/wizard/${next}`);
|
|
308
|
-
// Optional: Send event to Analytics
|
|
309
|
-
trackEvent('wizard_step', { step: next });
|
|
310
|
-
},
|
|
311
|
-
steps: [...]
|
|
312
|
-
};
|
|
313
|
-
|
|
314
|
-
// 2. Sync URL -> State (Initial Load)
|
|
315
|
-
const { stepId } = useParams();
|
|
316
|
-
|
|
317
|
-
return <WizardProvider config={config} initialStepId={stepId}>...</WizardProvider>;
|
|
318
|
-
```
|
|
319
|
-
|
|
320
|
-
### 3. Granular Persistence
|
|
321
|
-
|
|
322
|
-
By default, the wizard uses `MemoryAdapter` (RAM only). You can enable `LocalStorage` globally, but override it or its **behavior** (mode) for individual steps.
|
|
323
|
-
|
|
324
|
-
```tsx
|
|
325
|
-
const config: IWizardConfig = {
|
|
326
|
-
// Global: Persist everything to LocalStorage on every step change
|
|
327
|
-
persistence: {
|
|
328
|
-
adapter: new LocalStorageAdapter('wizard_'),
|
|
329
|
-
mode: 'onStepChange'
|
|
330
|
-
},
|
|
331
|
-
steps: [
|
|
332
|
-
{
|
|
333
|
-
id: 'public',
|
|
334
|
-
label: 'Public Info',
|
|
335
|
-
// Inherits global settings
|
|
336
|
-
},
|
|
337
|
-
{
|
|
338
|
-
id: 'realtime',
|
|
339
|
-
label: 'Active Draft',
|
|
340
|
-
// Override Mode: Save to local storage on every keystroke
|
|
341
|
-
persistenceMode: 'onChange'
|
|
342
|
-
},
|
|
343
|
-
{
|
|
344
|
-
id: 'sensitive',
|
|
345
|
-
label: 'Credit Card',
|
|
346
|
-
// Override Adapter: Store strictly in memory (cleared on refresh)
|
|
347
|
-
persistenceAdapter: new MemoryAdapter()
|
|
348
|
-
}
|
|
349
|
-
]
|
|
350
|
-
};
|
|
351
|
-
```
|
|
352
|
-
|
|
353
|
-
## API Reference
|
|
354
|
-
|
|
355
|
-
### `IWizardConfig<T>`
|
|
356
|
-
|
|
357
|
-
- `steps`: Array of step configurations.
|
|
358
|
-
- `persistence`: Configuration for state persistence.
|
|
359
|
-
- `autoValidate`: (obj) Global validation setting.
|
|
360
|
-
|
|
361
|
-
### `useWizard<T>()`
|
|
362
|
-
|
|
363
|
-
- `activeSteps`: Steps that match conditions.
|
|
364
|
-
- `currentStep`: The currently active step object.
|
|
365
|
-
- `wizardData`: The global state object (subscribe cautiously!).
|
|
366
|
-
- `setData(path, value, options?)`: Update state. Options: `{ debounceValidation: number }`.
|
|
367
|
-
- `getData(path, defaultValue?)`: Retrieve nested data.
|
|
368
|
-
- `handleStepChange(key, value)`: simple helper to update top-level state.
|
|
369
|
-
- `goToNextStep()`: Validates and moves next.
|
|
370
|
-
- `goToStep(id)`: Jumps to specific step.
|
|
371
|
-
- `allErrors`: Map of validation errors.
|
|
372
|
-
|
|
373
|
-
### New Performance Hooks
|
|
374
|
-
|
|
375
|
-
#### `useWizardValue<T>(path: string)`
|
|
376
|
-
|
|
377
|
-
Subscribes to a specific data path. Re-renders **only** when that value changes.
|
|
378
|
-
|
|
379
|
-
#### `useWizardError(path: string)`
|
|
380
|
-
|
|
381
|
-
Subscribes to validation errors for a specific path. Highly recommended for individual inputs.
|
|
382
|
-
|
|
383
|
-
#### `useWizardSelector<T>(selector: (state: T) => any)`
|
|
384
|
-
|
|
385
|
-
Create a custom subscription to the wizard state. Ideal for derived state or lists.
|
|
386
|
-
|
|
387
|
-
#### `useWizardActions()`
|
|
388
|
-
|
|
389
|
-
Returns object with actions (`setData`, `goToNextStep`, etc.) **without** subscribing to state changes. Use this in components that trigger updates but don't need to render data.
|
|
390
|
-
|
|
391
|
-
## Demos
|
|
392
|
-
|
|
393
|
-
Check out the [Live Demo](https://ZizzX.github.io/wizzard-stepper-react/), [NPM](https://www.npmjs.com/package/wizzard-stepper-react) or the [source code](https://github.com/ZizzX/wizzard-stepper-react-demo) for a complete implementation featuring:
|
|
394
|
-
|
|
395
|
-
- **Premium Documentation**: [Interactive Guides](https://ZizzX.github.io/wizzard-stepper-react/docs/introduction) and a dedicated [Type Reference](https://ZizzX.github.io/wizzard-stepper-react/docs/types).
|
|
396
|
-
- **Tailwind CSS v4** UI overhaul.
|
|
397
|
-
- **React Hook Form + Zod** integration.
|
|
398
|
-
- **Formik + Yup** integration.
|
|
399
|
-
- **Conditional Routing** logic.
|
|
400
|
-
- **Advanced Features Demo**: (`/advanced`) showcasing:
|
|
401
|
-
- **Autofill**: `updateData` global merge.
|
|
402
|
-
- **Declarative Rendering**: `<WizardStepRenderer />`.
|
|
403
|
-
- **Granular Persistence**: Hybrid Memory/LocalStorage.
|
|
404
|
-
|
|
405
|
-
## Advanced Demo Guide ๐งช
|
|
406
|
-
|
|
407
|
-
Visit `/advanced` in the demo to try:
|
|
408
|
-
|
|
409
|
-
1. **Autofill**: Click "Magic Autofill" to test `updateData()`. It instantly populates the form (merged with existing data).
|
|
410
|
-
2. **Hybrid Persistence**:
|
|
411
|
-
* **Step 1 (Identity)**: Refreshes persist (LocalStorage).
|
|
412
|
-
* **Step 2 (Security)**: Refreshes CLEAR data (MemoryAdapter).
|
|
413
|
-
3. **Declarative UI**: The steps are rendered using `<WizardStepRenderer />` with Framer Motion animations, defined in the config!
|
|
414
|
-
|
|
415
|
-
### โก Performance & Scalability
|
|
416
|
-
|
|
417
|
-
`wizzard-stepper-react` is architected for extreme scale.
|
|
418
|
-
|
|
419
|
-
- **Stateless Provider**: The main provider doesn't re-render when field values change. Only the specific components subscribed to those fields (via `useWizardValue`) re-render.
|
|
420
|
-
- **O(1) Engine**: Internal lookups for step configuration, active steps, and indices use Hash Maps to ensure instant response times even with hundreds of steps.
|
|
421
|
-
- **Deeply Nested Optimization**: Data access uses a memoized iterative path traversal, avoiding recursive overhead in deeply nested objects.
|
|
422
|
-
- **Loading State**: Built-in `isLoading` state to handle high-latency persistence restoration gracefully.
|
|
423
|
-
|
|
424
|
-
```tsx
|
|
425
|
-
const { isLoading } = useWizardState();
|
|
426
|
-
if (isLoading) return <SkeletonLoader />;
|
|
427
|
-
```
|
|
428
|
-
|
|
429
|
-
## License
|
|
430
|
-
|
|
431
|
-
MIT
|
|
1
|
+
# wizzard-stepper-react ๐งโโ๏ธ
|
|
2
|
+
|
|
3
|
+
[](https://www.npmjs.com/package/wizzard-stepper-react)
|
|
4
|
+
[](https://github.com/ZizzX/wizzard-stepper-react/blob/main/LICENSE)
|
|
5
|
+
[](https://bundlephobia.com/package/wizzard-stepper-react)
|
|
6
|
+
|
|
7
|
+
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).
|
|
8
|
+
|
|
9
|
+
---
|
|
10
|
+
|
|
11
|
+
## ๐ Quick Start (v2.0.0 Modern)
|
|
12
|
+
|
|
13
|
+
Version 2.0.0 introduces the **Factory Pattern**, providing 100% type safety and optimized performance out of the box.
|
|
14
|
+
|
|
15
|
+
### 1. Create your Wizard Kit
|
|
16
|
+
|
|
17
|
+
Define your data schema and generate typed hooks.
|
|
18
|
+
|
|
19
|
+
```typescript
|
|
20
|
+
// wizards/auth-wizard.ts
|
|
21
|
+
import { createWizardFactory } from 'wizzard-stepper-react';
|
|
22
|
+
|
|
23
|
+
interface AuthSchema {
|
|
24
|
+
email: string;
|
|
25
|
+
preferences: { theme: 'light' | 'dark' };
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export const {
|
|
29
|
+
WizardProvider,
|
|
30
|
+
useWizard,
|
|
31
|
+
useWizardValue,
|
|
32
|
+
useWizardActions
|
|
33
|
+
} = createWizardFactory<AuthSchema>();
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
### 2. Wrap your App
|
|
37
|
+
|
|
38
|
+
```tsx
|
|
39
|
+
import { WizardProvider } from './wizards/auth-wizard';
|
|
40
|
+
|
|
41
|
+
const App = () => (
|
|
42
|
+
<WizardProvider>
|
|
43
|
+
<MyWizardComponents />
|
|
44
|
+
</WizardProvider>
|
|
45
|
+
);
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
### 3. Use Granular Hooks
|
|
49
|
+
|
|
50
|
+
```tsx
|
|
51
|
+
import { useWizardValue, useWizardActions } from './wizards/auth-wizard';
|
|
52
|
+
|
|
53
|
+
const EmailInput = () => {
|
|
54
|
+
// โก Atomic re-render: component only updates if 'email' changes
|
|
55
|
+
const email = useWizardValue('email');
|
|
56
|
+
const { setData } = useWizardActions();
|
|
57
|
+
|
|
58
|
+
return <input value={email} onChange={e => setData('email', e.target.value)} />;
|
|
59
|
+
};
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
---
|
|
63
|
+
|
|
64
|
+
## โจ Key Features
|
|
65
|
+
|
|
66
|
+
- ๐ง **Headless Architecture**: Full control over UI. You bring the components, we provide the logic.
|
|
67
|
+
- ๐
**Modern First**: Optimized for React 18 with selective rendering and external state store.
|
|
68
|
+
- ๐ **Adapter Pattern**: Zero-dependency adapters for **Zod**, **Yup** validation.
|
|
69
|
+
- ๐๏ธ **Complex Data**: Built-in support for nested objects using dot notation (`user.address.zip`).
|
|
70
|
+
- ๐พ **Advanced Persistence**: Auto-save to LocalStorage, SessionStorage, or Custom API adapters.
|
|
71
|
+
- ๐ ๏ธ **Developer Tools**: High-performance debugging overlay and **Redux DevTools** integration.
|
|
72
|
+
|
|
73
|
+
---
|
|
74
|
+
|
|
75
|
+
## ๐๏ธ Core Concepts
|
|
76
|
+
|
|
77
|
+
### Validation Adapters
|
|
78
|
+
|
|
79
|
+
We are library-agnostic. Use our pre-built adapters or write your own.
|
|
80
|
+
|
|
81
|
+
```tsx
|
|
82
|
+
import { ZodAdapter } from 'wizzard-stepper-react';
|
|
83
|
+
import { z } from 'zod';
|
|
84
|
+
|
|
85
|
+
const schema = z.object({ age: z.number().min(18) });
|
|
86
|
+
const adapter = new ZodAdapter(schema);
|
|
87
|
+
|
|
88
|
+
// In your config:
|
|
89
|
+
const step = { id: 'age', validationAdapter: adapter };
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
### Navigation Lifecycle
|
|
93
|
+
|
|
94
|
+
1. **Validation**: Current step is checked. Navigation stops if invalid.
|
|
95
|
+
2. **Resolution**: Next step conditions (dynamic branching) are evaluated.
|
|
96
|
+
3. **Guards**: `beforeLeave` hooks run (e.g., for "Unsaved Changes" modals).
|
|
97
|
+
4. **Commit**: State updates and navigation completes.
|
|
98
|
+
|
|
99
|
+
---
|
|
100
|
+
|
|
101
|
+
## ๐พ State Persistence
|
|
102
|
+
|
|
103
|
+
Isolate your wizard data to prevent collisions when using multiple instances.
|
|
104
|
+
|
|
105
|
+
```typescript
|
|
106
|
+
import { LocalStorageAdapter } from 'wizzard-stepper-react';
|
|
107
|
+
|
|
108
|
+
const config = {
|
|
109
|
+
persistence: {
|
|
110
|
+
// ๐ก๏ธ Always use a unique prefix for isolation
|
|
111
|
+
adapter: new LocalStorageAdapter('auth_wizard_v2'),
|
|
112
|
+
mode: 'onStepChange'
|
|
113
|
+
}
|
|
114
|
+
};
|
|
115
|
+
```
|
|
116
|
+
|
|
117
|
+
---
|
|
118
|
+
|
|
119
|
+
## ๐ ๏ธ Performance Tuning
|
|
120
|
+
|
|
121
|
+
| Hook | Returns | Re-renders | Best For |
|
|
122
|
+
| :--- | :--- | :--- | :--- |
|
|
123
|
+
| `useWizardActions` | Navigation/Setters | **Zero** | Buttons, Handlers |
|
|
124
|
+
| `useWizardValue` | Specific Field | **Atomic** | Inputs, Labels |
|
|
125
|
+
| `useWizardState` | UI Meta (Progress) | **Minimal** | Progress Bars |
|
|
126
|
+
| `useWizard` | Everything | **Full** | Orchestration |
|
|
127
|
+
|
|
128
|
+
---
|
|
129
|
+
|
|
130
|
+
## โ ๏ธ Legacy Support (v1.x)
|
|
131
|
+
|
|
132
|
+
If you are maintaining an older project, you can still use the classic Context-based provider. Note that this mode does not support the new performance-optimized hooks.
|
|
133
|
+
|
|
134
|
+
```tsx
|
|
135
|
+
import { WizardProvider, useWizard } from 'wizzard-stepper-react';
|
|
136
|
+
|
|
137
|
+
const OldApp = () => (
|
|
138
|
+
<WizardProvider>
|
|
139
|
+
<MyComponents />
|
|
140
|
+
</WizardProvider>
|
|
141
|
+
);
|
|
142
|
+
```
|
|
143
|
+
|
|
144
|
+
For migration steps, see [MIGRATION.md](./MIGRATION.md).
|
|
145
|
+
|
|
146
|
+
---
|
|
147
|
+
|
|
148
|
+
## ๐ Documentation & Demos
|
|
149
|
+
|
|
150
|
+
- ๐ **Full Docs**: [Interactive Documentation Portal](https://ZizzX.github.io/wizzard-stepper-react/)
|
|
151
|
+
- ๐งช **Enterprise Demo**: [Google-quality complex wizard implementation](https://ZizzX.github.io/wizzard-stepper-react/docs/introduction)
|
|
152
|
+
- ๐ **NPMS**: [View on npm](https://www.npmjs.com/package/wizzard-stepper-react)
|
|
153
|
+
|
|
154
|
+
---
|
|
155
|
+
|
|
156
|
+
## License
|
|
157
|
+
|
|
158
|
+
MIT ยฉ [ZizzX](https://github.com/ZizzX)
|