@reformer/cdk 1.0.0-beta.1
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 -0
- package/README.md +96 -0
- package/dist/FormArray-CBT-1kKN.js +120 -0
- package/dist/FormWizard-DLDm4FJM.js +311 -0
- package/dist/Slot-YDt2BEtP.js +27 -0
- package/dist/components/form-array/FormArray.d.ts +223 -0
- package/dist/components/form-array/FormArrayAddButton.d.ts +6 -0
- package/dist/components/form-array/FormArrayContext.d.ts +137 -0
- package/dist/components/form-array/FormArrayCount.d.ts +17 -0
- package/dist/components/form-array/FormArrayEmpty.d.ts +22 -0
- package/dist/components/form-array/FormArrayItemIndex.d.ts +24 -0
- package/dist/components/form-array/FormArrayList.d.ts +26 -0
- package/dist/components/form-array/FormArrayRemoveButton.d.ts +26 -0
- package/dist/components/form-array/index.d.ts +13 -0
- package/dist/components/form-array/types.d.ts +77 -0
- package/dist/components/form-array/useFormArray.d.ts +95 -0
- package/dist/components/form-field/FormField.d.ts +107 -0
- package/dist/components/form-field/FormFieldContext.d.ts +56 -0
- package/dist/components/form-field/FormFieldControl.d.ts +35 -0
- package/dist/components/form-field/FormFieldDescription.d.ts +30 -0
- package/dist/components/form-field/FormFieldError.d.ts +36 -0
- package/dist/components/form-field/FormFieldLabel.d.ts +35 -0
- package/dist/components/form-field/FormFieldRoot.d.ts +32 -0
- package/dist/components/form-field/index.d.ts +10 -0
- package/dist/components/form-field/types.d.ts +114 -0
- package/dist/components/form-field/useFormField.d.ts +111 -0
- package/dist/components/form-wizard/FormWizard.d.ts +47 -0
- package/dist/components/form-wizard/FormWizardActions.d.ts +98 -0
- package/dist/components/form-wizard/FormWizardContext.d.ts +84 -0
- package/dist/components/form-wizard/FormWizardIndicator.d.ts +118 -0
- package/dist/components/form-wizard/FormWizardNext.d.ts +35 -0
- package/dist/components/form-wizard/FormWizardPrev.d.ts +35 -0
- package/dist/components/form-wizard/FormWizardProgress.d.ts +83 -0
- package/dist/components/form-wizard/FormWizardStep.d.ts +55 -0
- package/dist/components/form-wizard/FormWizardSubmit.d.ts +43 -0
- package/dist/components/form-wizard/Slot.d.ts +20 -0
- package/dist/components/form-wizard/Step.d.ts +24 -0
- package/dist/components/form-wizard/index.d.ts +21 -0
- package/dist/components/form-wizard/types.d.ts +108 -0
- package/dist/form-array.d.ts +2 -0
- package/dist/form-array.js +15 -0
- package/dist/form-field.d.ts +2 -0
- package/dist/form-field.js +12 -0
- package/dist/form-wizard.d.ts +2 -0
- package/dist/form-wizard.js +22 -0
- package/dist/index.d.ts +6 -0
- package/dist/index.js +33 -0
- package/dist/useFormField-DV396Bxa.js +232 -0
- package/llms.txt +3294 -0
- package/package.json +90 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2024 Alexandr Bukhtatyy
|
|
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,96 @@
|
|
|
1
|
+
# @reformer/cdk
|
|
2
|
+
|
|
3
|
+
Headless UI components for `@reformer/core` - build accessible, fully customizable form interfaces.
|
|
4
|
+
|
|
5
|
+
## Features
|
|
6
|
+
|
|
7
|
+
- **Headless** - No default styles, complete design freedom
|
|
8
|
+
- **Compound Components** - Declarative, composable API
|
|
9
|
+
- **Render Props** - Full control over rendering
|
|
10
|
+
- **TypeScript** - Fully typed with generics support
|
|
11
|
+
- **Tree-shakable** - Import only what you need
|
|
12
|
+
|
|
13
|
+
## Installation
|
|
14
|
+
|
|
15
|
+
```bash
|
|
16
|
+
npm install @reformer/cdk @reformer/core
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
## Components
|
|
20
|
+
|
|
21
|
+
### FormArray
|
|
22
|
+
|
|
23
|
+
Manage dynamic form arrays with add/remove functionality.
|
|
24
|
+
|
|
25
|
+
```tsx
|
|
26
|
+
import { FormArray } from '@reformer/cdk/form-array';
|
|
27
|
+
|
|
28
|
+
<FormArray.Root control={form.items}>
|
|
29
|
+
<FormArray.Empty>
|
|
30
|
+
<p>No items yet</p>
|
|
31
|
+
</FormArray.Empty>
|
|
32
|
+
|
|
33
|
+
<FormArray.List>
|
|
34
|
+
{({ control, index, remove }) => (
|
|
35
|
+
<div>
|
|
36
|
+
<span>Item #{index + 1}</span>
|
|
37
|
+
<ItemForm control={control} />
|
|
38
|
+
<button onClick={remove}>Remove</button>
|
|
39
|
+
</div>
|
|
40
|
+
)}
|
|
41
|
+
</FormArray.List>
|
|
42
|
+
|
|
43
|
+
<FormArray.AddButton>Add Item</FormArray.AddButton>
|
|
44
|
+
</FormArray.Root>;
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
### FormWizard
|
|
48
|
+
|
|
49
|
+
Build multi-step form wizards with validation.
|
|
50
|
+
|
|
51
|
+
```tsx
|
|
52
|
+
import { FormWizard } from '@reformer/cdk/form-wizard';
|
|
53
|
+
|
|
54
|
+
<FormWizard form={form} config={config}>
|
|
55
|
+
<FormWizard.Indicator steps={STEPS}>
|
|
56
|
+
{({ steps, goToStep }) => (
|
|
57
|
+
<nav>
|
|
58
|
+
{steps.map((step) => (
|
|
59
|
+
<button
|
|
60
|
+
key={step.number}
|
|
61
|
+
onClick={() => goToStep(step.number)}
|
|
62
|
+
disabled={!step.canNavigate}
|
|
63
|
+
>
|
|
64
|
+
{step.title}
|
|
65
|
+
</button>
|
|
66
|
+
))}
|
|
67
|
+
</nav>
|
|
68
|
+
)}
|
|
69
|
+
</FormWizard.Indicator>
|
|
70
|
+
|
|
71
|
+
<FormWizard.Step component={Step1} control={form} />
|
|
72
|
+
<FormWizard.Step component={Step2} control={form} />
|
|
73
|
+
|
|
74
|
+
<FormWizard.Actions onSubmit={handleSubmit}>
|
|
75
|
+
{({ prev, next, submit, isFirstStep, isLastStep }) => (
|
|
76
|
+
<div>
|
|
77
|
+
{!isFirstStep && <button {...prev}>Back</button>}
|
|
78
|
+
{!isLastStep ? <button {...next}>Next</button> : <button {...submit}>Submit</button>}
|
|
79
|
+
</div>
|
|
80
|
+
)}
|
|
81
|
+
</FormWizard.Actions>
|
|
82
|
+
</FormWizard>;
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
## Hooks
|
|
86
|
+
|
|
87
|
+
For full customization, use the hooks directly:
|
|
88
|
+
|
|
89
|
+
```tsx
|
|
90
|
+
import { useFormArray } from '@reformer/cdk/form-array';
|
|
91
|
+
import { useFormWizard } from '@reformer/cdk/form-wizard';
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
## License
|
|
95
|
+
|
|
96
|
+
MIT
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
import { jsx as n, Fragment as u } from "react/jsx-runtime";
|
|
2
|
+
import { useMemo as C, createContext as d, useContext as y, createElement as x, forwardRef as c, useImperativeHandle as I } from "react";
|
|
3
|
+
import { useFormControl as E } from "@reformer/core";
|
|
4
|
+
import { S as A } from "./Slot-YDt2BEtP.js";
|
|
5
|
+
function R(r) {
|
|
6
|
+
const { length: t } = E(r);
|
|
7
|
+
return {
|
|
8
|
+
items: C(
|
|
9
|
+
() => r.map((o, e) => ({
|
|
10
|
+
control: o,
|
|
11
|
+
index: e,
|
|
12
|
+
id: o.id ?? e,
|
|
13
|
+
remove: () => r.removeAt(e)
|
|
14
|
+
})),
|
|
15
|
+
[r, t]
|
|
16
|
+
),
|
|
17
|
+
length: t,
|
|
18
|
+
isEmpty: t === 0,
|
|
19
|
+
add: (o) => r.push(o),
|
|
20
|
+
clear: () => r.clear(),
|
|
21
|
+
insert: (o, e) => r.insert(o, e)
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
const F = d(null), p = d(null);
|
|
25
|
+
function i() {
|
|
26
|
+
const r = y(F);
|
|
27
|
+
if (!r)
|
|
28
|
+
throw new Error(
|
|
29
|
+
"FormArray.* components must be used within FormArray.Root or RenderSchema FormArray"
|
|
30
|
+
);
|
|
31
|
+
return r;
|
|
32
|
+
}
|
|
33
|
+
function f() {
|
|
34
|
+
const r = y(p);
|
|
35
|
+
if (!r)
|
|
36
|
+
throw new Error(
|
|
37
|
+
"FormArray.Item* components must be used within FormArray.List or item template"
|
|
38
|
+
);
|
|
39
|
+
return r;
|
|
40
|
+
}
|
|
41
|
+
function w({
|
|
42
|
+
children: r,
|
|
43
|
+
className: t,
|
|
44
|
+
as: m = "div"
|
|
45
|
+
}) {
|
|
46
|
+
const { items: o } = i(), e = o.map((s) => /* @__PURE__ */ n(p.Provider, { value: s, children: r(s) }, s.id));
|
|
47
|
+
return t ? x(m, { className: t }, e) : /* @__PURE__ */ n(u, { children: e });
|
|
48
|
+
}
|
|
49
|
+
function B({ children: r, initialValue: t, asChild: m = !1, ...o }, e) {
|
|
50
|
+
const { add: s } = i();
|
|
51
|
+
return /* @__PURE__ */ n(
|
|
52
|
+
m ? A : "button",
|
|
53
|
+
{
|
|
54
|
+
ref: e,
|
|
55
|
+
type: m ? void 0 : "button",
|
|
56
|
+
onClick: () => s(t),
|
|
57
|
+
...o,
|
|
58
|
+
children: r
|
|
59
|
+
}
|
|
60
|
+
);
|
|
61
|
+
}
|
|
62
|
+
const l = c(B);
|
|
63
|
+
l.displayName = "FormArray.AddButton";
|
|
64
|
+
const b = l, v = c(
|
|
65
|
+
({ children: r, asChild: t = !1, ...m }, o) => {
|
|
66
|
+
const { remove: e } = f();
|
|
67
|
+
return /* @__PURE__ */ n(t ? A : "button", { ref: o, type: t ? void 0 : "button", onClick: e, ...m, children: r });
|
|
68
|
+
}
|
|
69
|
+
);
|
|
70
|
+
v.displayName = "FormArray.RemoveButton";
|
|
71
|
+
function g({ children: r }) {
|
|
72
|
+
const { isEmpty: t } = i();
|
|
73
|
+
return t ? /* @__PURE__ */ n(u, { children: r }) : null;
|
|
74
|
+
}
|
|
75
|
+
function S({ render: r }) {
|
|
76
|
+
const { length: t } = i();
|
|
77
|
+
return r ? /* @__PURE__ */ n(u, { children: r(t) }) : /* @__PURE__ */ n(u, { children: t });
|
|
78
|
+
}
|
|
79
|
+
function L({ render: r }) {
|
|
80
|
+
const { index: t } = f();
|
|
81
|
+
return r ? /* @__PURE__ */ n(u, { children: r(t) }) : /* @__PURE__ */ n(u, { children: t + 1 });
|
|
82
|
+
}
|
|
83
|
+
function j({ control: r, children: t }, m) {
|
|
84
|
+
const o = R(r);
|
|
85
|
+
return I(
|
|
86
|
+
m,
|
|
87
|
+
() => ({
|
|
88
|
+
add: o.add,
|
|
89
|
+
clear: o.clear,
|
|
90
|
+
insert: o.insert,
|
|
91
|
+
removeAt: (e) => r.removeAt(e),
|
|
92
|
+
length: o.length,
|
|
93
|
+
isEmpty: o.isEmpty,
|
|
94
|
+
at: (e) => r.at(e)
|
|
95
|
+
}),
|
|
96
|
+
[o, r]
|
|
97
|
+
), /* @__PURE__ */ n(F.Provider, { value: { ...o, control: r }, children: t });
|
|
98
|
+
}
|
|
99
|
+
const h = c(j), a = h;
|
|
100
|
+
a.Root = h;
|
|
101
|
+
a.List = w;
|
|
102
|
+
a.AddButton = b;
|
|
103
|
+
a.RemoveButton = v;
|
|
104
|
+
a.Empty = g;
|
|
105
|
+
a.Count = S;
|
|
106
|
+
a.ItemIndex = L;
|
|
107
|
+
export {
|
|
108
|
+
a as F,
|
|
109
|
+
w as a,
|
|
110
|
+
b,
|
|
111
|
+
v as c,
|
|
112
|
+
g as d,
|
|
113
|
+
S as e,
|
|
114
|
+
L as f,
|
|
115
|
+
F as g,
|
|
116
|
+
p as h,
|
|
117
|
+
i,
|
|
118
|
+
f as j,
|
|
119
|
+
R as u
|
|
120
|
+
};
|
|
@@ -0,0 +1,311 @@
|
|
|
1
|
+
import { jsx as p, Fragment as y } from "react/jsx-runtime";
|
|
2
|
+
import { createContext as U, useContext as Y, useMemo as j, forwardRef as N, isValidElement as k, cloneElement as E, useState as I, useCallback as w, useImperativeHandle as tt, Children as M } from "react";
|
|
3
|
+
import { validateForm as R } from "@reformer/core/validators";
|
|
4
|
+
import { S as D } from "./Slot-YDt2BEtP.js";
|
|
5
|
+
const B = U(null);
|
|
6
|
+
function W() {
|
|
7
|
+
const t = Y(B);
|
|
8
|
+
if (!t)
|
|
9
|
+
throw new Error("useFormWizard must be used within FormWizard");
|
|
10
|
+
return t;
|
|
11
|
+
}
|
|
12
|
+
function A({
|
|
13
|
+
component: t,
|
|
14
|
+
control: r,
|
|
15
|
+
children: s,
|
|
16
|
+
_stepIndex: i,
|
|
17
|
+
...o
|
|
18
|
+
}) {
|
|
19
|
+
const { currentStep: c } = W();
|
|
20
|
+
return i === void 0 || c !== i ? null : s !== void 0 ? /* @__PURE__ */ p(y, { children: s }) : t && r ? /* @__PURE__ */ p(t, { control: r, ...o }) : null;
|
|
21
|
+
}
|
|
22
|
+
A.displayName = "FormWizard.Step";
|
|
23
|
+
function H({ steps: t, children: r }) {
|
|
24
|
+
if (typeof r != "function")
|
|
25
|
+
throw new Error(
|
|
26
|
+
"FormWizard.Indicator requires children as a render function. Example: <FormWizard.Indicator steps={STEPS}>{({ steps }) => <YourUI />}</FormWizard.Indicator>"
|
|
27
|
+
);
|
|
28
|
+
const { currentStep: s, totalSteps: i, completedSteps: o, goToStep: c } = W(), n = {
|
|
29
|
+
steps: t.map((e) => ({
|
|
30
|
+
...e,
|
|
31
|
+
isCurrent: s === e.number,
|
|
32
|
+
isCompleted: o.includes(e.number),
|
|
33
|
+
canNavigate: e.number === 1 || o.includes(e.number - 1)
|
|
34
|
+
})),
|
|
35
|
+
goToStep: c,
|
|
36
|
+
currentStep: s,
|
|
37
|
+
totalSteps: i,
|
|
38
|
+
completedSteps: o
|
|
39
|
+
};
|
|
40
|
+
return /* @__PURE__ */ p(y, { children: r(n) });
|
|
41
|
+
}
|
|
42
|
+
H.displayName = "FormWizard.Indicator";
|
|
43
|
+
const $ = U(null);
|
|
44
|
+
function et() {
|
|
45
|
+
const t = Y($);
|
|
46
|
+
if (!t)
|
|
47
|
+
throw new Error(
|
|
48
|
+
"FormWizard.Prev/Next/Submit must be used within FormWizard.Actions. Wrap your navigation buttons with <FormWizard.Actions>."
|
|
49
|
+
);
|
|
50
|
+
return t;
|
|
51
|
+
}
|
|
52
|
+
function rt(t) {
|
|
53
|
+
return typeof t == "function";
|
|
54
|
+
}
|
|
55
|
+
function J({
|
|
56
|
+
onSubmit: t,
|
|
57
|
+
children: r,
|
|
58
|
+
className: s,
|
|
59
|
+
style: i
|
|
60
|
+
}) {
|
|
61
|
+
const { isFirstStep: o, isLastStep: c, isValidating: d, isSubmitting: n, goToNextStep: e, goToPreviousStep: m } = W(), l = j(() => ({ onSubmit: t }), [t]);
|
|
62
|
+
if (rt(r)) {
|
|
63
|
+
const f = d || n;
|
|
64
|
+
return /* @__PURE__ */ p(y, { children: r({
|
|
65
|
+
prev: {
|
|
66
|
+
onClick: m,
|
|
67
|
+
disabled: f
|
|
68
|
+
},
|
|
69
|
+
next: {
|
|
70
|
+
onClick: () => e(),
|
|
71
|
+
disabled: f
|
|
72
|
+
},
|
|
73
|
+
submit: {
|
|
74
|
+
onClick: () => t?.(),
|
|
75
|
+
disabled: f,
|
|
76
|
+
isSubmitting: n
|
|
77
|
+
},
|
|
78
|
+
isFirstStep: o,
|
|
79
|
+
isLastStep: c,
|
|
80
|
+
isValidating: d,
|
|
81
|
+
isSubmitting: n
|
|
82
|
+
}) });
|
|
83
|
+
}
|
|
84
|
+
return /* @__PURE__ */ p($.Provider, { value: l, children: s || i ? /* @__PURE__ */ p("div", { className: s, style: i, children: r }) : /* @__PURE__ */ p(y, { children: r }) });
|
|
85
|
+
}
|
|
86
|
+
J.displayName = "FormWizard.Actions";
|
|
87
|
+
function K({ children: t }) {
|
|
88
|
+
if (typeof t != "function")
|
|
89
|
+
throw new Error(
|
|
90
|
+
"FormWizard.Progress requires children as a render function. Example: <FormWizard.Progress>{({ current, total }) => <YourUI />}</FormWizard.Progress>"
|
|
91
|
+
);
|
|
92
|
+
const { currentStep: r, totalSteps: s, completedSteps: i, isFirstStep: o, isLastStep: c } = W(), d = {
|
|
93
|
+
current: r,
|
|
94
|
+
total: s,
|
|
95
|
+
percent: Math.round(r / s * 100),
|
|
96
|
+
completedCount: i.length,
|
|
97
|
+
isFirstStep: o,
|
|
98
|
+
isLastStep: c
|
|
99
|
+
};
|
|
100
|
+
return /* @__PURE__ */ p(y, { children: t(d) });
|
|
101
|
+
}
|
|
102
|
+
K.displayName = "FormWizard.Progress";
|
|
103
|
+
const O = N(
|
|
104
|
+
({ children: t, asChild: r = !1, disabled: s, ...i }, o) => {
|
|
105
|
+
const { goToPreviousStep: c, isFirstStep: d, isValidating: n, isSubmitting: e } = W();
|
|
106
|
+
return /* @__PURE__ */ p(
|
|
107
|
+
r ? D : "button",
|
|
108
|
+
{
|
|
109
|
+
ref: o,
|
|
110
|
+
type: r ? void 0 : "button",
|
|
111
|
+
onClick: c,
|
|
112
|
+
disabled: s || (d || n || e),
|
|
113
|
+
"data-first-step": d || void 0,
|
|
114
|
+
...i,
|
|
115
|
+
children: t
|
|
116
|
+
}
|
|
117
|
+
);
|
|
118
|
+
}
|
|
119
|
+
);
|
|
120
|
+
O.displayName = "FormWizard.Prev";
|
|
121
|
+
const Q = N(
|
|
122
|
+
({ children: t, asChild: r = !1, disabled: s, ...i }, o) => {
|
|
123
|
+
const { goToNextStep: c, isLastStep: d, isValidating: n, isSubmitting: e } = W();
|
|
124
|
+
return /* @__PURE__ */ p(
|
|
125
|
+
r ? D : "button",
|
|
126
|
+
{
|
|
127
|
+
ref: o,
|
|
128
|
+
type: r ? void 0 : "button",
|
|
129
|
+
onClick: () => c(),
|
|
130
|
+
disabled: s || (d || n || e),
|
|
131
|
+
"data-last-step": d || void 0,
|
|
132
|
+
...i,
|
|
133
|
+
children: t
|
|
134
|
+
}
|
|
135
|
+
);
|
|
136
|
+
}
|
|
137
|
+
);
|
|
138
|
+
Q.displayName = "FormWizard.Next";
|
|
139
|
+
const X = N(
|
|
140
|
+
({ children: t, asChild: r = !1, disabled: s, loadingText: i, ...o }, c) => {
|
|
141
|
+
const { isLastStep: d, isValidating: n, isSubmitting: e } = W(), { onSubmit: m } = et(), f = s || (!d || n || e), S = r ? D : "button", F = e && i;
|
|
142
|
+
let z = t;
|
|
143
|
+
return r && F && k(t) && (z = E(t, {}, i)), /* @__PURE__ */ p(
|
|
144
|
+
S,
|
|
145
|
+
{
|
|
146
|
+
ref: c,
|
|
147
|
+
type: r ? void 0 : "submit",
|
|
148
|
+
onClick: () => m?.(),
|
|
149
|
+
disabled: f,
|
|
150
|
+
"data-submitting": e || void 0,
|
|
151
|
+
"data-not-last-step": !d || void 0,
|
|
152
|
+
...o,
|
|
153
|
+
children: r ? z : F ? i : t
|
|
154
|
+
}
|
|
155
|
+
);
|
|
156
|
+
}
|
|
157
|
+
);
|
|
158
|
+
X.displayName = "FormWizard.Submit";
|
|
159
|
+
function it({ form: t, config: r, children: s, onStepChange: i, scrollToTop: o = !0 }, c) {
|
|
160
|
+
const d = (a) => {
|
|
161
|
+
let u = 0;
|
|
162
|
+
return M.forEach(a, (b) => {
|
|
163
|
+
if (k(b))
|
|
164
|
+
if (b.type === A)
|
|
165
|
+
u += 1;
|
|
166
|
+
else {
|
|
167
|
+
const G = b.props;
|
|
168
|
+
G.children && (u += d(G.children));
|
|
169
|
+
}
|
|
170
|
+
}), u;
|
|
171
|
+
}, n = d(s), [e, m] = I(1), [l, f] = I([]), [S, F] = I(!1), z = t.submitting.value, g = w(async () => {
|
|
172
|
+
const a = r.stepValidations[e];
|
|
173
|
+
if (!a)
|
|
174
|
+
return console.warn(`No validation schema for step ${e}`), !0;
|
|
175
|
+
F(!0);
|
|
176
|
+
try {
|
|
177
|
+
return await R(t, a);
|
|
178
|
+
} finally {
|
|
179
|
+
F(!1);
|
|
180
|
+
}
|
|
181
|
+
}, [t, e, r.stepValidations]), P = w(async () => {
|
|
182
|
+
if (!await g())
|
|
183
|
+
return t.markAsTouched(), !1;
|
|
184
|
+
if (l.includes(e) || f((u) => [...u, e]), e < n) {
|
|
185
|
+
const u = e + 1;
|
|
186
|
+
m(u), i?.(u), o && window.scrollTo({ top: 0, behavior: "smooth" });
|
|
187
|
+
}
|
|
188
|
+
return !0;
|
|
189
|
+
}, [
|
|
190
|
+
g,
|
|
191
|
+
e,
|
|
192
|
+
l,
|
|
193
|
+
n,
|
|
194
|
+
t,
|
|
195
|
+
i,
|
|
196
|
+
o
|
|
197
|
+
]), x = w(() => {
|
|
198
|
+
if (e > 1) {
|
|
199
|
+
const a = e - 1;
|
|
200
|
+
m(a), i?.(a), o && window.scrollTo({ top: 0, behavior: "smooth" });
|
|
201
|
+
}
|
|
202
|
+
}, [e, i, o]), V = w(
|
|
203
|
+
(a) => (a === 1 || l.includes(a - 1)) && a >= 1 && a <= n ? (m(a), i?.(a), o && window.scrollTo({ top: 0, behavior: "smooth" }), !0) : !1,
|
|
204
|
+
[l, n, i, o]
|
|
205
|
+
), L = w(
|
|
206
|
+
async (a) => {
|
|
207
|
+
F(!0);
|
|
208
|
+
try {
|
|
209
|
+
return await R(t, r.fullValidation) ? t.submit(a, { skipValidation: !0 }) : (t.markAsTouched(), null);
|
|
210
|
+
} finally {
|
|
211
|
+
F(!1);
|
|
212
|
+
}
|
|
213
|
+
},
|
|
214
|
+
[t, r.fullValidation]
|
|
215
|
+
), h = e === 1, C = e === n;
|
|
216
|
+
tt(
|
|
217
|
+
c,
|
|
218
|
+
() => ({
|
|
219
|
+
form: t,
|
|
220
|
+
currentStep: e,
|
|
221
|
+
completedSteps: l,
|
|
222
|
+
validateCurrentStep: g,
|
|
223
|
+
goToNextStep: P,
|
|
224
|
+
goToPreviousStep: x,
|
|
225
|
+
goToStep: V,
|
|
226
|
+
submit: L,
|
|
227
|
+
isFirstStep: h,
|
|
228
|
+
isLastStep: C,
|
|
229
|
+
isValidating: S
|
|
230
|
+
}),
|
|
231
|
+
[
|
|
232
|
+
t,
|
|
233
|
+
e,
|
|
234
|
+
l,
|
|
235
|
+
g,
|
|
236
|
+
P,
|
|
237
|
+
x,
|
|
238
|
+
V,
|
|
239
|
+
L,
|
|
240
|
+
h,
|
|
241
|
+
C,
|
|
242
|
+
S
|
|
243
|
+
]
|
|
244
|
+
);
|
|
245
|
+
const Z = j(
|
|
246
|
+
() => ({
|
|
247
|
+
// State
|
|
248
|
+
currentStep: e,
|
|
249
|
+
totalSteps: n,
|
|
250
|
+
completedSteps: l,
|
|
251
|
+
isFirstStep: h,
|
|
252
|
+
isLastStep: C,
|
|
253
|
+
isValidating: S,
|
|
254
|
+
isSubmitting: z,
|
|
255
|
+
form: t,
|
|
256
|
+
// Navigation methods
|
|
257
|
+
goToNextStep: P,
|
|
258
|
+
goToPreviousStep: x,
|
|
259
|
+
goToStep: V
|
|
260
|
+
}),
|
|
261
|
+
[
|
|
262
|
+
e,
|
|
263
|
+
n,
|
|
264
|
+
l,
|
|
265
|
+
h,
|
|
266
|
+
C,
|
|
267
|
+
S,
|
|
268
|
+
z,
|
|
269
|
+
t,
|
|
270
|
+
P,
|
|
271
|
+
x,
|
|
272
|
+
V
|
|
273
|
+
]
|
|
274
|
+
);
|
|
275
|
+
let T = 0;
|
|
276
|
+
const q = (a) => M.map(a, (u) => {
|
|
277
|
+
if (!k(u))
|
|
278
|
+
return u;
|
|
279
|
+
const b = u.props;
|
|
280
|
+
return u.type === A ? (T += 1, E(u, {
|
|
281
|
+
...b,
|
|
282
|
+
_stepIndex: T
|
|
283
|
+
// 1-based indexing
|
|
284
|
+
})) : typeof b.children == "function" ? u : b.children ? E(u, {
|
|
285
|
+
...b,
|
|
286
|
+
children: q(b.children)
|
|
287
|
+
}) : u;
|
|
288
|
+
}), _ = q(s);
|
|
289
|
+
return /* @__PURE__ */ p(B.Provider, { value: Z, children: _ });
|
|
290
|
+
}
|
|
291
|
+
const ot = N(it), v = ot;
|
|
292
|
+
v.Step = A;
|
|
293
|
+
v.Indicator = H;
|
|
294
|
+
v.Actions = J;
|
|
295
|
+
v.Progress = K;
|
|
296
|
+
v.Prev = O;
|
|
297
|
+
v.Next = Q;
|
|
298
|
+
v.Submit = X;
|
|
299
|
+
export {
|
|
300
|
+
v as F,
|
|
301
|
+
A as a,
|
|
302
|
+
H as b,
|
|
303
|
+
J as c,
|
|
304
|
+
K as d,
|
|
305
|
+
B as e,
|
|
306
|
+
et as f,
|
|
307
|
+
O as g,
|
|
308
|
+
Q as h,
|
|
309
|
+
X as i,
|
|
310
|
+
W as u
|
|
311
|
+
};
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { forwardRef as r, Children as i, isValidElement as c, cloneElement as d } from "react";
|
|
2
|
+
function a(l, s) {
|
|
3
|
+
const n = { ...l };
|
|
4
|
+
for (const e of Object.keys(s)) {
|
|
5
|
+
const t = l[e], o = s[e];
|
|
6
|
+
e.startsWith("on") && typeof t == "function" && typeof o == "function" ? n[e] = (...f) => {
|
|
7
|
+
o(...f), t(...f);
|
|
8
|
+
} : e === "className" && typeof t == "string" && typeof o == "string" ? n[e] = [o, t].filter(Boolean).join(" ") : e === "style" && typeof t == "object" && typeof o == "object" ? n[e] = { ...o, ...t } : e === "disabled" ? n[e] = !!t || !!o : o !== void 0 && (n[e] = o);
|
|
9
|
+
}
|
|
10
|
+
return n;
|
|
11
|
+
}
|
|
12
|
+
const p = r(
|
|
13
|
+
({ children: l, ...s }, n) => {
|
|
14
|
+
const e = i.only(l);
|
|
15
|
+
if (!c(e))
|
|
16
|
+
return null;
|
|
17
|
+
const t = e.props, o = a(s, t), f = e.ref;
|
|
18
|
+
return d(e, {
|
|
19
|
+
...o,
|
|
20
|
+
ref: n || f
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
);
|
|
24
|
+
p.displayName = "Slot";
|
|
25
|
+
export {
|
|
26
|
+
p as S
|
|
27
|
+
};
|