react-wizard-engine 0.1.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/CHANGELOG.md +12 -0
- package/LICENSE +21 -0
- package/README.md +100 -0
- package/dist/components-provider-bC3_zfyb.d.cts +29 -0
- package/dist/components-provider-bC3_zfyb.d.ts +29 -0
- package/dist/index.cjs +2349 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +1083 -0
- package/dist/index.d.ts +1083 -0
- package/dist/index.js +2242 -0
- package/dist/index.js.map +1 -0
- package/dist/shadcn/index.cjs +311 -0
- package/dist/shadcn/index.cjs.map +1 -0
- package/dist/shadcn/index.d.cts +78 -0
- package/dist/shadcn/index.d.ts +78 -0
- package/dist/shadcn/index.js +270 -0
- package/dist/shadcn/index.js.map +1 -0
- package/package.json +101 -0
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
# react-wizard-engine
|
|
2
|
+
|
|
3
|
+
## 0.1.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- f824dd0: Initial release. Extracted from the perks.loca.us monorepo as a standalone package.
|
|
8
|
+
|
|
9
|
+
- Framework-agnostic engine (`core/`): steps, categories, branches, pluggable strategies, listeners, initializers, async navigation with cancellation.
|
|
10
|
+
- Headless React adapter (`react-wizard-engine`): `WizardProvider`, hooks (`useWizard`, `useWizardStep`, `useWizardEvent`), structural components.
|
|
11
|
+
- Styled adapter (`react-wizard-engine/shadcn`): `WizardTopBar`, `WizardLayout`, opinionated Radix + Tailwind that match shadcn defaults.
|
|
12
|
+
- Dual ESM + CJS builds, full `.d.ts` types, `"use client"` preserved.
|
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Nazarii Kovtun
|
|
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,100 @@
|
|
|
1
|
+
# react-wizard-engine
|
|
2
|
+
|
|
3
|
+
[](https://www.npmjs.com/package/react-wizard-engine)
|
|
4
|
+
[](https://github.com/knazark/react-wizard-engine/blob/main/LICENSE)
|
|
5
|
+
|
|
6
|
+
Multi-step flow engine for React. Steps, categories, branches. Pluggable strategies, listeners, initializers. Resolver hooks. Async navigation with cancellation. Headless core plus an opinionated Radix + Tailwind styled adapter.
|
|
7
|
+
|
|
8
|
+
## Install
|
|
9
|
+
|
|
10
|
+
```sh
|
|
11
|
+
pnpm add react-wizard-engine lucide-react
|
|
12
|
+
# only if you also use the styled /shadcn adapter:
|
|
13
|
+
pnpm add @radix-ui/react-dialog @radix-ui/react-slot
|
|
14
|
+
```
|
|
15
|
+
|
|
16
|
+
## Quickstart
|
|
17
|
+
|
|
18
|
+
```tsx
|
|
19
|
+
import {
|
|
20
|
+
WizardProvider,
|
|
21
|
+
WizardCategory,
|
|
22
|
+
WizardStep,
|
|
23
|
+
WizardBack,
|
|
24
|
+
WizardNext,
|
|
25
|
+
} from 'react-wizard-engine';
|
|
26
|
+
|
|
27
|
+
const initial = [
|
|
28
|
+
{ id: 'name', categoryId: 'profile', htmlIndex: 0, branches: ['main'], isActive: true, isShow: true, isCompleted: false, isSkipped: false },
|
|
29
|
+
{ id: 'email', categoryId: 'profile', htmlIndex: 1, branches: ['main'], isActive: false, isShow: true, isCompleted: false, isSkipped: false },
|
|
30
|
+
{ id: 'done', categoryId: 'confirm', htmlIndex: 2, branches: ['main'], isActive: false, isShow: true, isCompleted: false, isSkipped: false },
|
|
31
|
+
];
|
|
32
|
+
|
|
33
|
+
export function SignupWizard() {
|
|
34
|
+
return (
|
|
35
|
+
<WizardProvider state={initial}>
|
|
36
|
+
<WizardCategory categoryId="profile">
|
|
37
|
+
<WizardStep id="name">...name form...</WizardStep>
|
|
38
|
+
<WizardStep id="email">...email form...</WizardStep>
|
|
39
|
+
</WizardCategory>
|
|
40
|
+
<WizardCategory categoryId="confirm">
|
|
41
|
+
<WizardStep id="done">...review...</WizardStep>
|
|
42
|
+
</WizardCategory>
|
|
43
|
+
<WizardBack />
|
|
44
|
+
<WizardNext />
|
|
45
|
+
</WizardProvider>
|
|
46
|
+
);
|
|
47
|
+
}
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
## Styled adapter
|
|
51
|
+
|
|
52
|
+
The `/shadcn` subpath ships an opinionated styled `WizardTopBar` and `WizardLayout` built on Radix + Tailwind utility classes that match shadcn defaults.
|
|
53
|
+
|
|
54
|
+
```tsx
|
|
55
|
+
import { WizardLayout, WizardTopBar, WizardComponentsProviderWithDefaults } from 'react-wizard-engine/shadcn';
|
|
56
|
+
|
|
57
|
+
<WizardComponentsProviderWithDefaults>
|
|
58
|
+
<WizardProvider state={initial}>
|
|
59
|
+
<WizardLayout
|
|
60
|
+
topBar={<WizardTopBar onClose={onClose} />}
|
|
61
|
+
rail={<MyRail />}
|
|
62
|
+
>
|
|
63
|
+
{/* steps */}
|
|
64
|
+
</WizardLayout>
|
|
65
|
+
</WizardProvider>
|
|
66
|
+
</WizardComponentsProviderWithDefaults>
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
To use your own button:
|
|
70
|
+
|
|
71
|
+
```tsx
|
|
72
|
+
import { WizardComponentsProvider } from 'react-wizard-engine';
|
|
73
|
+
import { Button } from '@/components/ui/button';
|
|
74
|
+
|
|
75
|
+
<WizardComponentsProvider Button={Button}>
|
|
76
|
+
<WizardProvider state={initial}>{}</WizardProvider>
|
|
77
|
+
</WizardComponentsProvider>
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
## Concepts
|
|
81
|
+
|
|
82
|
+
- **Step** — one screen the user sees. `id`, `categoryId`, `htmlIndex` (declaration order), `branches[]`, plus four flags (`isActive`/`isShow`/`isCompleted`/`isSkipped`).
|
|
83
|
+
- **Category** — a group of steps sharing a header tab.
|
|
84
|
+
- **Branch** — a named path through categories.
|
|
85
|
+
|
|
86
|
+
See `src/core/` for full type definitions.
|
|
87
|
+
|
|
88
|
+
## Hooks
|
|
89
|
+
|
|
90
|
+
- `useWizard()` — engine: `next`, `back`, `go`, `showStep`, `hideStep`, `goToCategory`, `nextCategory`, `backCategory`, `skipCategory`, `resetWizard`, `exitWizard`, `completeWizard`, snapshot fields `tree` / `steps` / `lastActiveStep` / `shapeId`. All control methods return `Promise<boolean>`.
|
|
91
|
+
- `useWizardStep(id)` — subscribes to one step's slice; re-renders only when its flags flip.
|
|
92
|
+
- `useWizardEvent('*' | type, handler)` — subscribes to engine events.
|
|
93
|
+
|
|
94
|
+
## Strategies (pluggable)
|
|
95
|
+
|
|
96
|
+
`composeWizardProviders(withBackStrategy(...), withScrollStrategy(...), ...)`. Back, visibility, progress, and scroll strategies all overridable. See `src/core/strategies/`.
|
|
97
|
+
|
|
98
|
+
## License
|
|
99
|
+
|
|
100
|
+
MIT (c) Nazarii Kovtun
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
2
|
+
import { ReactNode, ComponentType } from 'react';
|
|
3
|
+
|
|
4
|
+
interface IWizardButtonProps {
|
|
5
|
+
asChild?: boolean;
|
|
6
|
+
children?: ReactNode;
|
|
7
|
+
className?: string;
|
|
8
|
+
disabled?: boolean;
|
|
9
|
+
onClick?: () => void;
|
|
10
|
+
type?: 'button' | 'submit';
|
|
11
|
+
variant?: 'default' | 'ghost';
|
|
12
|
+
size?: 'default' | 'icon-sm';
|
|
13
|
+
'aria-label'?: string;
|
|
14
|
+
}
|
|
15
|
+
interface IWizardBackArrowIconProps {
|
|
16
|
+
className?: string;
|
|
17
|
+
}
|
|
18
|
+
interface IWizardComponents {
|
|
19
|
+
Button: ComponentType<IWizardButtonProps>;
|
|
20
|
+
BackArrowIcon: ComponentType<IWizardBackArrowIconProps>;
|
|
21
|
+
}
|
|
22
|
+
declare function WizardComponentsProvider(props: {
|
|
23
|
+
Button?: ComponentType<IWizardButtonProps>;
|
|
24
|
+
BackArrowIcon?: ComponentType<IWizardBackArrowIconProps>;
|
|
25
|
+
children: ReactNode;
|
|
26
|
+
}): react_jsx_runtime.JSX.Element;
|
|
27
|
+
declare function useWizardComponents(): IWizardComponents;
|
|
28
|
+
|
|
29
|
+
export { type IWizardBackArrowIconProps as I, WizardComponentsProvider as W, type IWizardButtonProps as a, type IWizardComponents as b, useWizardComponents as u };
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
2
|
+
import { ReactNode, ComponentType } from 'react';
|
|
3
|
+
|
|
4
|
+
interface IWizardButtonProps {
|
|
5
|
+
asChild?: boolean;
|
|
6
|
+
children?: ReactNode;
|
|
7
|
+
className?: string;
|
|
8
|
+
disabled?: boolean;
|
|
9
|
+
onClick?: () => void;
|
|
10
|
+
type?: 'button' | 'submit';
|
|
11
|
+
variant?: 'default' | 'ghost';
|
|
12
|
+
size?: 'default' | 'icon-sm';
|
|
13
|
+
'aria-label'?: string;
|
|
14
|
+
}
|
|
15
|
+
interface IWizardBackArrowIconProps {
|
|
16
|
+
className?: string;
|
|
17
|
+
}
|
|
18
|
+
interface IWizardComponents {
|
|
19
|
+
Button: ComponentType<IWizardButtonProps>;
|
|
20
|
+
BackArrowIcon: ComponentType<IWizardBackArrowIconProps>;
|
|
21
|
+
}
|
|
22
|
+
declare function WizardComponentsProvider(props: {
|
|
23
|
+
Button?: ComponentType<IWizardButtonProps>;
|
|
24
|
+
BackArrowIcon?: ComponentType<IWizardBackArrowIconProps>;
|
|
25
|
+
children: ReactNode;
|
|
26
|
+
}): react_jsx_runtime.JSX.Element;
|
|
27
|
+
declare function useWizardComponents(): IWizardComponents;
|
|
28
|
+
|
|
29
|
+
export { type IWizardBackArrowIconProps as I, WizardComponentsProvider as W, type IWizardButtonProps as a, type IWizardComponents as b, useWizardComponents as u };
|