@saas-ui/forms 2.0.0-next.0 → 2.0.0-next.10
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 +95 -0
- package/README.md +53 -6
- package/dist/ajv/index.d.ts +359 -11
- package/dist/ajv/index.js +7 -9
- package/dist/ajv/index.js.map +1 -1
- package/dist/ajv/index.mjs +7 -10
- package/dist/ajv/index.mjs.map +1 -1
- package/dist/index.d.ts +448 -247
- package/dist/index.js +708 -682
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +688 -662
- package/dist/index.mjs.map +1 -1
- package/dist/yup/index.d.ts +581 -21
- package/dist/yup/index.js +6 -10
- package/dist/yup/index.js.map +1 -1
- package/dist/yup/index.mjs +4 -8
- package/dist/yup/index.mjs.map +1 -1
- package/dist/zod/index.d.ts +581 -11
- package/dist/zod/index.js +5 -0
- package/dist/zod/index.js.map +1 -1
- package/dist/zod/index.mjs +5 -1
- package/dist/zod/index.mjs.map +1 -1
- package/package.json +24 -15
- package/src/array-field.tsx +82 -45
- package/src/auto-form.tsx +7 -3
- package/src/base-field.tsx +54 -0
- package/src/create-field.tsx +144 -0
- package/src/create-form.tsx +54 -0
- package/src/default-fields.tsx +163 -0
- package/src/display-field.tsx +9 -11
- package/src/display-if.tsx +20 -13
- package/src/field-resolver.ts +10 -8
- package/src/field.tsx +18 -445
- package/src/fields-context.tsx +23 -0
- package/src/fields.tsx +34 -21
- package/src/form-context.tsx +84 -0
- package/src/form.tsx +72 -52
- package/src/index.ts +44 -4
- package/src/input-right-button/input-right-button.stories.tsx +2 -2
- package/src/input-right-button/input-right-button.tsx +0 -2
- package/src/layout.tsx +16 -11
- package/src/number-input/number-input.stories.tsx +3 -3
- package/src/number-input/number-input.tsx +9 -5
- package/src/object-field.tsx +13 -8
- package/src/password-input/password-input.stories.tsx +23 -2
- package/src/password-input/password-input.tsx +6 -6
- package/src/pin-input/pin-input.tsx +1 -5
- package/src/radio/radio-input.stories.tsx +1 -1
- package/src/radio/radio-input.tsx +12 -10
- package/src/select/native-select.tsx +1 -4
- package/src/select/select-context.tsx +130 -0
- package/src/select/select.stories.tsx +117 -86
- package/src/select/select.test.tsx +1 -1
- package/src/select/select.tsx +162 -146
- package/src/step-form.tsx +29 -11
- package/src/submit-button.tsx +5 -1
- package/src/types.ts +144 -0
- package/src/use-array-field.tsx +9 -3
- package/src/utils.ts +23 -1
- package/src/watch-field.tsx +2 -6
- /package/src/radio/{radio.test.tsx → radio-input.test.tsx} +0 -0
package/dist/index.js
CHANGED
@@ -1,14 +1,16 @@
|
|
1
1
|
'use strict';
|
2
2
|
|
3
|
-
var
|
4
|
-
var utils = require('@chakra-ui/utils');
|
3
|
+
var React13 = require('react');
|
5
4
|
var reactHookForm = require('react-hook-form');
|
5
|
+
var jsxRuntime = require('react/jsx-runtime');
|
6
6
|
var react = require('@chakra-ui/react');
|
7
|
-
var icons = require('@chakra-ui/icons');
|
8
|
-
var reactUtils = require('@chakra-ui/react-utils');
|
9
7
|
var core = require('@saas-ui/core');
|
8
|
+
var icons = require('@saas-ui/core/icons');
|
9
|
+
var utils = require('@chakra-ui/utils');
|
10
|
+
var reactUtils = require('@chakra-ui/react-utils');
|
10
11
|
|
11
|
-
function
|
12
|
+
function _interopNamespace(e) {
|
13
|
+
if (e && e.__esModule) return e;
|
12
14
|
var n = Object.create(null);
|
13
15
|
if (e) {
|
14
16
|
Object.keys(e).forEach(function (k) {
|
@@ -25,70 +27,74 @@ function _interopNamespaceDefault(e) {
|
|
25
27
|
return Object.freeze(n);
|
26
28
|
}
|
27
29
|
|
28
|
-
var
|
30
|
+
var React13__namespace = /*#__PURE__*/_interopNamespace(React13);
|
29
31
|
|
30
|
-
// src/
|
32
|
+
// src/form-context.tsx
|
33
|
+
var FormContext = React13__namespace.createContext(null);
|
34
|
+
var useFormContext = () => {
|
35
|
+
const context = React13__namespace.useContext(FormContext);
|
36
|
+
const hookContext = reactHookForm.useFormContext();
|
37
|
+
if (!context) {
|
38
|
+
throw new Error("FormProvider must be used within a Form component");
|
39
|
+
}
|
40
|
+
return {
|
41
|
+
...hookContext,
|
42
|
+
...context
|
43
|
+
};
|
44
|
+
};
|
45
|
+
var useFieldProps = (name) => {
|
46
|
+
var _a;
|
47
|
+
const parsedName = name == null ? void 0 : name.replace(/\.[0-9]/g, ".$");
|
48
|
+
const context = useFormContext();
|
49
|
+
return (_a = context == null ? void 0 : context.fields) == null ? void 0 : _a[parsedName];
|
50
|
+
};
|
51
|
+
var FormProvider = (props) => {
|
52
|
+
const { children, fieldResolver, schema, fields, ...rest } = props;
|
53
|
+
return /* @__PURE__ */ jsxRuntime.jsx(reactHookForm.FormProvider, { ...rest, children: /* @__PURE__ */ jsxRuntime.jsx(FormContext.Provider, { value: { fieldResolver, schema, fields }, children }) });
|
54
|
+
};
|
31
55
|
var DisplayField = ({
|
32
56
|
name,
|
33
57
|
label,
|
34
58
|
placeholder,
|
35
59
|
...props
|
36
60
|
}) => {
|
37
|
-
return /* @__PURE__ */
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
}, label) : null, /* @__PURE__ */ React8__namespace.createElement(react.Text, {
|
42
|
-
fontSize: "md"
|
43
|
-
}, /* @__PURE__ */ React8__namespace.createElement(FormValue, {
|
44
|
-
name
|
45
|
-
})));
|
61
|
+
return /* @__PURE__ */ jsxRuntime.jsxs(react.FormControl, { ...props, children: [
|
62
|
+
label ? /* @__PURE__ */ jsxRuntime.jsx(react.FormLabel, { htmlFor: name, children: label }) : null,
|
63
|
+
/* @__PURE__ */ jsxRuntime.jsx(react.Text, { fontSize: "md", children: /* @__PURE__ */ jsxRuntime.jsx(FormValue, { name }) })
|
64
|
+
] });
|
46
65
|
};
|
47
|
-
|
48
|
-
DisplayField.displayName = "DisplayField";
|
49
|
-
}
|
66
|
+
DisplayField.displayName = "DisplayField";
|
50
67
|
var FormValue = ({ name }) => {
|
51
|
-
const { getValues } =
|
68
|
+
const { getValues } = useFormContext();
|
52
69
|
return getValues(name) || null;
|
53
70
|
};
|
54
|
-
|
55
|
-
FormValue.displayName = "FormValue";
|
56
|
-
}
|
71
|
+
FormValue.displayName = "FormValue";
|
57
72
|
var NumberInput = react.forwardRef((props, ref) => {
|
58
|
-
const {
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
73
|
+
const {
|
74
|
+
hideStepper,
|
75
|
+
incrementIcon = /* @__PURE__ */ jsxRuntime.jsx(core.ChevronUpIcon, {}),
|
76
|
+
decrementIcon = /* @__PURE__ */ jsxRuntime.jsx(core.ChevronDownIcon, {}),
|
77
|
+
...rest
|
78
|
+
} = props;
|
79
|
+
return /* @__PURE__ */ jsxRuntime.jsxs(react.NumberInput, { ...rest, ref, children: [
|
80
|
+
/* @__PURE__ */ jsxRuntime.jsx(react.NumberInputField, {}),
|
81
|
+
!hideStepper && /* @__PURE__ */ jsxRuntime.jsxs(react.NumberInputStepper, { children: [
|
82
|
+
/* @__PURE__ */ jsxRuntime.jsx(react.NumberIncrementStepper, { children: incrementIcon }),
|
83
|
+
/* @__PURE__ */ jsxRuntime.jsx(react.NumberDecrementStepper, { children: decrementIcon })
|
84
|
+
] })
|
85
|
+
] });
|
67
86
|
});
|
68
87
|
NumberInput.defaultProps = {
|
69
88
|
hideStepper: false
|
70
89
|
};
|
71
|
-
|
72
|
-
NumberInput.displayName = "NumberInput";
|
73
|
-
}
|
90
|
+
NumberInput.displayName = "NumberInput";
|
74
91
|
var InputRightButton = react.forwardRef(
|
75
92
|
(props, ref) => {
|
76
|
-
return /* @__PURE__ */
|
77
|
-
w: "auto",
|
78
|
-
px: "1",
|
79
|
-
py: "1",
|
80
|
-
alignItems: "stretch"
|
81
|
-
}, /* @__PURE__ */ React8__namespace.createElement(react.Button, {
|
82
|
-
ref,
|
83
|
-
height: "auto",
|
84
|
-
...props
|
85
|
-
}));
|
93
|
+
return /* @__PURE__ */ jsxRuntime.jsx(react.InputRightElement, { w: "auto", px: "1", py: "1", alignItems: "stretch", children: /* @__PURE__ */ jsxRuntime.jsx(react.Button, { ref, height: "auto", ...props }) });
|
86
94
|
}
|
87
95
|
);
|
88
96
|
InputRightButton.id = "InputRightElement";
|
89
97
|
InputRightButton.displayName = "InputRightButton";
|
90
|
-
|
91
|
-
// src/password-input/password-input.tsx
|
92
98
|
var PasswordInput = react.forwardRef(
|
93
99
|
(props, ref) => {
|
94
100
|
const {
|
@@ -99,219 +105,286 @@ var PasswordInput = react.forwardRef(
|
|
99
105
|
width,
|
100
106
|
size,
|
101
107
|
variant,
|
108
|
+
leftAddon,
|
102
109
|
...inputProps
|
103
110
|
} = props;
|
104
|
-
const [show, setShow] =
|
111
|
+
const [show, setShow] = React13.useState(false);
|
105
112
|
const handleClick = () => setShow(!show);
|
106
113
|
const label = show ? "Hide password" : "Show password";
|
107
114
|
let icon;
|
108
115
|
if (show) {
|
109
|
-
icon = viewIcon || /* @__PURE__ */
|
116
|
+
icon = viewIcon || /* @__PURE__ */ jsxRuntime.jsx(icons.ViewIcon, {});
|
110
117
|
} else {
|
111
|
-
icon = viewOffIcon || /* @__PURE__ */
|
118
|
+
icon = viewOffIcon || /* @__PURE__ */ jsxRuntime.jsx(icons.ViewOffIcon, {});
|
112
119
|
}
|
113
120
|
const groupProps = {
|
114
121
|
width: w || width,
|
115
122
|
size,
|
116
123
|
variant
|
117
124
|
};
|
118
|
-
return /* @__PURE__ */
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
125
|
+
return /* @__PURE__ */ jsxRuntime.jsxs(react.InputGroup, { ...groupProps, children: [
|
126
|
+
leftAddon,
|
127
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
128
|
+
react.Input,
|
129
|
+
{
|
130
|
+
...inputProps,
|
131
|
+
ref,
|
132
|
+
type: show ? "text" : "password",
|
133
|
+
autoComplete: show ? "off" : autoComplete
|
134
|
+
}
|
135
|
+
),
|
136
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
137
|
+
InputRightButton,
|
138
|
+
{
|
139
|
+
onClick: handleClick,
|
140
|
+
"aria-label": label,
|
141
|
+
variant: "ghost",
|
142
|
+
children: icon
|
143
|
+
}
|
144
|
+
)
|
145
|
+
] });
|
130
146
|
}
|
131
147
|
);
|
132
|
-
|
133
|
-
|
134
|
-
|
148
|
+
PasswordInput.displayName = "PasswordInput";
|
149
|
+
var mapNestedFields = (name, children) => {
|
150
|
+
return React13__namespace.Children.map(children, (child) => {
|
151
|
+
if (React13__namespace.isValidElement(child) && child.props.name) {
|
152
|
+
let childName = child.props.name;
|
153
|
+
if (childName.includes(".")) {
|
154
|
+
childName = childName.replace(/^.*\.(.*)/, "$1");
|
155
|
+
} else if (childName.includes(".$")) {
|
156
|
+
childName = childName.replace(/^.*\.\$(.*)/, "$1");
|
157
|
+
}
|
158
|
+
return React13__namespace.cloneElement(child, {
|
159
|
+
...child.props,
|
160
|
+
name: `${name}.${childName}`
|
161
|
+
});
|
162
|
+
}
|
163
|
+
return child;
|
164
|
+
});
|
165
|
+
};
|
166
|
+
var mapOptions = (options) => {
|
167
|
+
return options.map((option) => {
|
168
|
+
if (typeof option === "string") {
|
169
|
+
return {
|
170
|
+
label: option,
|
171
|
+
value: option
|
172
|
+
};
|
173
|
+
}
|
174
|
+
return option;
|
175
|
+
});
|
176
|
+
};
|
135
177
|
var RadioInput = react.forwardRef(
|
136
|
-
({ options, spacing, direction, ...props }, ref) => {
|
178
|
+
({ options: optionsProp, spacing, direction, ...props }, ref) => {
|
137
179
|
const { onBlur, onChange, ...groupProps } = props;
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
})));
|
180
|
+
const options = mapOptions(optionsProp);
|
181
|
+
return /* @__PURE__ */ jsxRuntime.jsx(react.RadioGroup, { onChange, ...groupProps, children: /* @__PURE__ */ jsxRuntime.jsx(react.Stack, { spacing, direction, children: options.map(({ value, label, ...radioProps }, i) => {
|
182
|
+
return /* @__PURE__ */ jsxRuntime.jsx(
|
183
|
+
react.Radio,
|
184
|
+
{
|
185
|
+
onBlur,
|
186
|
+
value,
|
187
|
+
ref,
|
188
|
+
...radioProps,
|
189
|
+
children: label || value
|
190
|
+
},
|
191
|
+
i
|
192
|
+
);
|
193
|
+
}) }) });
|
153
194
|
}
|
154
195
|
);
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
var SelectButton = react.forwardRef((props, ref) => {
|
159
|
-
const styles = react.useMultiStyleConfig("Input", props);
|
160
|
-
const focusStyles = styles.field._focusVisible;
|
161
|
-
const height = styles.field.h || styles.field.height;
|
162
|
-
const buttonStyles = {
|
163
|
-
fontWeight: "normal",
|
164
|
-
textAlign: "left",
|
165
|
-
color: "inherit",
|
166
|
-
_active: {
|
167
|
-
bg: "transparent"
|
168
|
-
},
|
169
|
-
minH: height,
|
170
|
-
_focus: focusStyles,
|
171
|
-
_expanded: focusStyles,
|
172
|
-
...styles.field,
|
173
|
-
h: "auto"
|
174
|
-
};
|
175
|
-
return /* @__PURE__ */ React8__namespace.createElement(react.MenuButton, {
|
176
|
-
as: react.Button,
|
177
|
-
...props,
|
178
|
-
ref,
|
179
|
-
sx: buttonStyles
|
180
|
-
});
|
196
|
+
RadioInput.displayName = "RadioInput";
|
197
|
+
var [SelectProvider, useSelectContext] = reactUtils.createContext({
|
198
|
+
strict: true
|
181
199
|
});
|
182
|
-
|
183
|
-
SelectButton.displayName = "SelectButton";
|
184
|
-
}
|
185
|
-
var Select = react.forwardRef((props, ref) => {
|
200
|
+
var useSelect = (props) => {
|
186
201
|
const {
|
187
202
|
name,
|
188
|
-
options,
|
189
|
-
children,
|
190
|
-
onChange,
|
191
|
-
defaultValue,
|
192
203
|
value,
|
204
|
+
defaultValue,
|
205
|
+
onChange,
|
206
|
+
multiple,
|
193
207
|
placeholder,
|
208
|
+
options: optionsProp,
|
194
209
|
isDisabled,
|
195
|
-
|
196
|
-
rightIcon = /* @__PURE__ */ React8__namespace.createElement(icons.ChevronDownIcon, null),
|
197
|
-
multiple,
|
198
|
-
size,
|
199
|
-
variant,
|
200
|
-
menuListProps,
|
201
|
-
renderValue = (value2) => value2 == null ? void 0 : value2.join(", "),
|
202
|
-
...rest
|
210
|
+
renderValue = (value2) => typeof value2 === "string" ? value2 : value2 == null ? void 0 : value2.join(", ")
|
203
211
|
} = props;
|
204
|
-
const
|
205
|
-
|
212
|
+
const [currentValue, setCurrentValue] = react.useControllableState({
|
213
|
+
value,
|
214
|
+
defaultValue,
|
215
|
+
onChange
|
216
|
+
});
|
206
217
|
const controlProps = react.useFormControl({ name });
|
218
|
+
const options = React13__namespace.default.useMemo(
|
219
|
+
() => optionsProp && mapOptions(optionsProp),
|
220
|
+
[optionsProp]
|
221
|
+
);
|
207
222
|
const handleChange = (value2) => {
|
208
223
|
setCurrentValue(value2);
|
209
|
-
onChange == null ? void 0 : onChange(value2);
|
210
224
|
};
|
211
|
-
const
|
212
|
-
isDisabled,
|
213
|
-
leftIcon,
|
214
|
-
rightIcon,
|
215
|
-
size,
|
216
|
-
variant
|
217
|
-
};
|
218
|
-
const getDisplayValue = React8__namespace.useCallback(
|
225
|
+
const getDisplayValue = React13__namespace.default.useCallback(
|
219
226
|
(value2) => {
|
220
227
|
if (!options) {
|
221
228
|
return value2;
|
222
229
|
}
|
223
230
|
for (const option of options) {
|
224
|
-
if (option.
|
225
|
-
return option.label;
|
231
|
+
if (option.value === value2) {
|
232
|
+
return option.label || option.value;
|
226
233
|
}
|
227
234
|
}
|
228
235
|
return value2;
|
229
236
|
},
|
230
237
|
[options]
|
231
238
|
);
|
232
|
-
const displayValue =
|
233
|
-
|
234
|
-
|
235
|
-
|
236
|
-
|
237
|
-
|
238
|
-
|
239
|
-
|
240
|
-
}, /* @__PURE__ */ React8__namespace.createElement(SelectButton, {
|
241
|
-
ref,
|
242
|
-
...buttonProps
|
243
|
-
}, renderValue(displayValue) || placeholder), /* @__PURE__ */ React8__namespace.createElement(react.MenuList, {
|
244
|
-
maxH: "60vh",
|
245
|
-
overflowY: "auto",
|
246
|
-
...menuListProps
|
247
|
-
}, /* @__PURE__ */ React8__namespace.createElement(react.MenuOptionGroup, {
|
248
|
-
defaultValue: defaultValue || value,
|
249
|
-
onChange: handleChange,
|
250
|
-
type: multiple ? "checkbox" : "radio"
|
251
|
-
}, options ? options.map(({ value: value2, label, ...rest2 }, i) => /* @__PURE__ */ React8__namespace.createElement(react.MenuItemOption, {
|
252
|
-
key: i,
|
253
|
-
value: value2,
|
254
|
-
...rest2
|
255
|
-
}, label || value2)) : children)), /* @__PURE__ */ React8__namespace.createElement(react.chakra.input, {
|
256
|
-
...controlProps,
|
257
|
-
name,
|
258
|
-
type: "hidden",
|
239
|
+
const displayValue = React13__namespace.default.useMemo(
|
240
|
+
() => currentValue ? (Array.isArray(currentValue) ? currentValue : [currentValue]).map(
|
241
|
+
getDisplayValue
|
242
|
+
) : [],
|
243
|
+
[currentValue, getDisplayValue]
|
244
|
+
);
|
245
|
+
return {
|
246
|
+
defaultValue,
|
259
247
|
value: currentValue,
|
260
|
-
|
261
|
-
|
248
|
+
displayValue,
|
249
|
+
renderValue,
|
250
|
+
onChange: handleChange,
|
251
|
+
options,
|
252
|
+
multiple,
|
253
|
+
controlProps,
|
254
|
+
placeholder,
|
255
|
+
isDisabled
|
256
|
+
};
|
257
|
+
};
|
258
|
+
var SelectButton = react.forwardRef(
|
259
|
+
(props, ref) => {
|
260
|
+
var _a, _b, _c, _d, _e;
|
261
|
+
const styles = react.useMultiStyleConfig("SuiSelect", props);
|
262
|
+
const {
|
263
|
+
displayValue,
|
264
|
+
renderValue,
|
265
|
+
placeholder,
|
266
|
+
isDisabled: isSelectDisabled
|
267
|
+
} = useSelectContext();
|
268
|
+
const context = react.useFormControlContext();
|
269
|
+
const {
|
270
|
+
isInvalid,
|
271
|
+
isReadOnly,
|
272
|
+
isDisabled,
|
273
|
+
isFocused,
|
274
|
+
isRequired,
|
275
|
+
id,
|
276
|
+
onBlur,
|
277
|
+
onFocus
|
278
|
+
} = context || {};
|
279
|
+
const { rightIcon = /* @__PURE__ */ jsxRuntime.jsx(core.ChevronDownIcon, {}), ...rest } = props;
|
280
|
+
const focusStyles = (_a = styles.field) == null ? void 0 : _a._focusVisible;
|
281
|
+
const readOnlyStyles = (_b = styles.field) == null ? void 0 : _b._readOnly;
|
282
|
+
const invalid = (_c = styles.field) == null ? void 0 : _c._invalid;
|
283
|
+
const height = ((_d = styles.field) == null ? void 0 : _d.h) || ((_e = styles.field) == null ? void 0 : _e.height);
|
284
|
+
const buttonStyles = {
|
285
|
+
fontWeight: "normal",
|
286
|
+
textAlign: "left",
|
287
|
+
color: "inherit",
|
288
|
+
_active: {
|
289
|
+
bg: "transparent"
|
290
|
+
},
|
291
|
+
minH: height,
|
292
|
+
_focus: focusStyles,
|
293
|
+
_expanded: focusStyles,
|
294
|
+
_readOnly: readOnlyStyles,
|
295
|
+
_invalid: invalid,
|
296
|
+
...styles.field,
|
297
|
+
h: "auto"
|
298
|
+
};
|
299
|
+
return /* @__PURE__ */ jsxRuntime.jsx(
|
300
|
+
react.MenuButton,
|
301
|
+
{
|
302
|
+
as: react.Button,
|
303
|
+
id: id || React13__namespace.useId(),
|
304
|
+
...rest,
|
305
|
+
onFocus,
|
306
|
+
onBlur,
|
307
|
+
isDisabled: isDisabled || isSelectDisabled,
|
308
|
+
"data-invalid": utils.dataAttr(isInvalid),
|
309
|
+
"data-read-only": utils.dataAttr(isReadOnly),
|
310
|
+
"data-focus": utils.dataAttr(isFocused),
|
311
|
+
"data-required": utils.dataAttr(isRequired),
|
312
|
+
rightIcon,
|
313
|
+
ref,
|
314
|
+
sx: buttonStyles,
|
315
|
+
children: renderValue(displayValue) || placeholder
|
316
|
+
}
|
317
|
+
);
|
318
|
+
}
|
319
|
+
);
|
320
|
+
SelectButton.displayName = "SelectButton";
|
321
|
+
var Select = react.forwardRef((props, ref) => {
|
322
|
+
const { name, children, isDisabled, multiple, ...rest } = props;
|
323
|
+
const menuProps = react.omitThemingProps(rest);
|
324
|
+
const context = useSelect(props);
|
325
|
+
const { value, controlProps } = context;
|
326
|
+
return /* @__PURE__ */ jsxRuntime.jsx(SelectProvider, { value: context, children: /* @__PURE__ */ jsxRuntime.jsx(react.Menu, { ...menuProps, closeOnSelect: !multiple, children: /* @__PURE__ */ jsxRuntime.jsxs(react.chakra.div, { className: utils.cx("sui-select"), children: [
|
327
|
+
children,
|
328
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
329
|
+
react.chakra.input,
|
330
|
+
{
|
331
|
+
...controlProps,
|
332
|
+
ref,
|
333
|
+
name,
|
334
|
+
type: "hidden",
|
335
|
+
value: value || "",
|
336
|
+
className: "saas-select__input"
|
337
|
+
}
|
338
|
+
)
|
339
|
+
] }) }) });
|
262
340
|
});
|
263
|
-
|
264
|
-
|
265
|
-
|
341
|
+
var SelectList = (props) => {
|
342
|
+
const { defaultValue, value, options, multiple, onChange } = useSelectContext();
|
343
|
+
return /* @__PURE__ */ jsxRuntime.jsx(react.MenuList, { maxH: "100vh", overflowY: "auto", ...props, children: /* @__PURE__ */ jsxRuntime.jsx(
|
344
|
+
react.MenuOptionGroup,
|
345
|
+
{
|
346
|
+
defaultValue: defaultValue || value,
|
347
|
+
value,
|
348
|
+
onChange,
|
349
|
+
type: multiple ? "checkbox" : "radio",
|
350
|
+
children: options ? options.map(({ value: value2, label, ...rest }, i) => /* @__PURE__ */ jsxRuntime.jsx(SelectOption, { value: value2, ...rest, children: label || value2 }, i)) : props.children
|
351
|
+
}
|
352
|
+
) });
|
353
|
+
};
|
354
|
+
Select.displayName = "Select";
|
355
|
+
var SelectOption = react.forwardRef(
|
356
|
+
(props, ref) => {
|
357
|
+
return /* @__PURE__ */ jsxRuntime.jsx(react.MenuItemOption, { ref, ...props });
|
358
|
+
}
|
359
|
+
);
|
360
|
+
SelectOption.id = "MenuItemOption";
|
361
|
+
SelectOption.displayName = "SelectOption";
|
266
362
|
var NativeSelect = react.forwardRef(
|
267
363
|
({ options, children, ...props }, ref) => {
|
268
|
-
return /* @__PURE__ */
|
269
|
-
|
270
|
-
|
271
|
-
}, children || (options == null ? void 0 : options.map(({ value, label }) => {
|
272
|
-
return /* @__PURE__ */ React8__namespace.createElement("option", {
|
273
|
-
key: value,
|
274
|
-
value
|
275
|
-
}, label || value);
|
276
|
-
})));
|
364
|
+
return /* @__PURE__ */ jsxRuntime.jsx(react.Select, { ref, ...props, children: children || (options == null ? void 0 : options.map(({ value, label }) => {
|
365
|
+
return /* @__PURE__ */ jsxRuntime.jsx("option", { value, children: label || value }, value);
|
366
|
+
})) });
|
277
367
|
}
|
278
368
|
);
|
279
|
-
|
280
|
-
NativeSelect.displayName = "NativeSelect";
|
281
|
-
}
|
282
|
-
|
283
|
-
// src/field.tsx
|
284
|
-
var inputTypes = {};
|
285
|
-
var defaultInputType = "text";
|
286
|
-
var getInput = (type) => {
|
287
|
-
return inputTypes[type] || inputTypes[defaultInputType];
|
288
|
-
};
|
369
|
+
NativeSelect.displayName = "NativeSelect";
|
289
370
|
var getError = (name, formState) => {
|
290
371
|
return reactHookForm.get(formState.errors, name);
|
291
372
|
};
|
292
373
|
var BaseField = (props) => {
|
293
374
|
const { name, label, help, hideLabel, children, ...controlProps } = props;
|
294
|
-
const { formState } =
|
375
|
+
const { formState } = useFormContext();
|
295
376
|
const error = getError(name, formState);
|
296
|
-
return /* @__PURE__ */
|
297
|
-
|
298
|
-
|
299
|
-
|
377
|
+
return /* @__PURE__ */ jsxRuntime.jsxs(react.FormControl, { ...controlProps, isInvalid: !!error, children: [
|
378
|
+
label && !hideLabel ? /* @__PURE__ */ jsxRuntime.jsx(react.FormLabel, { children: label }) : null,
|
379
|
+
/* @__PURE__ */ jsxRuntime.jsxs(react.Box, { children: [
|
380
|
+
children,
|
381
|
+
help && !(error == null ? void 0 : error.message) ? /* @__PURE__ */ jsxRuntime.jsx(react.FormHelperText, { children: help }) : null,
|
382
|
+
(error == null ? void 0 : error.message) && /* @__PURE__ */ jsxRuntime.jsx(react.FormErrorMessage, { children: error == null ? void 0 : error.message })
|
383
|
+
] })
|
384
|
+
] });
|
300
385
|
};
|
301
|
-
|
302
|
-
|
303
|
-
}
|
304
|
-
var Field = React8__namespace.forwardRef(
|
305
|
-
(props, ref) => {
|
306
|
-
const { type = defaultInputType } = props;
|
307
|
-
const InputComponent = getInput(type);
|
308
|
-
return /* @__PURE__ */ React8__namespace.createElement(InputComponent, {
|
309
|
-
ref,
|
310
|
-
...props
|
311
|
-
});
|
312
|
-
}
|
313
|
-
);
|
314
|
-
var createField = (InputComponent, { displayName, hideLabel, BaseField: BaseField2 }) => {
|
386
|
+
BaseField.displayName = "BaseField";
|
387
|
+
var _createField = (InputComponent, { displayName, hideLabel, BaseField: BaseField2 }) => {
|
315
388
|
const Field2 = react.forwardRef((props, ref) => {
|
316
389
|
const {
|
317
390
|
id,
|
@@ -329,24 +402,31 @@ var createField = (InputComponent, { displayName, hideLabel, BaseField: BaseFiel
|
|
329
402
|
required: isRequired,
|
330
403
|
...rules
|
331
404
|
};
|
332
|
-
return /* @__PURE__ */
|
333
|
-
|
334
|
-
|
335
|
-
|
336
|
-
|
337
|
-
|
338
|
-
|
339
|
-
|
340
|
-
|
341
|
-
|
342
|
-
|
343
|
-
|
344
|
-
|
345
|
-
|
346
|
-
|
347
|
-
|
348
|
-
|
349
|
-
|
405
|
+
return /* @__PURE__ */ jsxRuntime.jsx(
|
406
|
+
BaseField2,
|
407
|
+
{
|
408
|
+
id,
|
409
|
+
name,
|
410
|
+
label,
|
411
|
+
help,
|
412
|
+
hideLabel,
|
413
|
+
isDisabled,
|
414
|
+
isInvalid,
|
415
|
+
isReadOnly,
|
416
|
+
isRequired,
|
417
|
+
children: /* @__PURE__ */ jsxRuntime.jsx(
|
418
|
+
InputComponent,
|
419
|
+
{
|
420
|
+
ref,
|
421
|
+
id,
|
422
|
+
name,
|
423
|
+
label: hideLabel ? label : void 0,
|
424
|
+
rules: inputRules,
|
425
|
+
...inputProps
|
426
|
+
}
|
427
|
+
)
|
428
|
+
}
|
429
|
+
);
|
350
430
|
});
|
351
431
|
Field2.displayName = displayName;
|
352
432
|
return Field2;
|
@@ -354,298 +434,194 @@ var createField = (InputComponent, { displayName, hideLabel, BaseField: BaseFiel
|
|
354
434
|
var withControlledInput = (InputComponent) => {
|
355
435
|
return react.forwardRef(
|
356
436
|
({ name, rules, ...inputProps }, ref) => {
|
357
|
-
const { control } =
|
358
|
-
return /* @__PURE__ */
|
359
|
-
|
360
|
-
|
361
|
-
|
362
|
-
|
363
|
-
|
364
|
-
...
|
365
|
-
|
366
|
-
|
367
|
-
|
368
|
-
|
369
|
-
|
437
|
+
const { control } = useFormContext();
|
438
|
+
return /* @__PURE__ */ jsxRuntime.jsx(
|
439
|
+
reactHookForm.Controller,
|
440
|
+
{
|
441
|
+
name,
|
442
|
+
control,
|
443
|
+
rules,
|
444
|
+
render: ({ field: { ref: _ref, ...field } }) => /* @__PURE__ */ jsxRuntime.jsx(
|
445
|
+
InputComponent,
|
446
|
+
{
|
447
|
+
...field,
|
448
|
+
...inputProps,
|
449
|
+
onChange: utils.callAllHandlers(inputProps.onChange, field.onChange),
|
450
|
+
onBlur: utils.callAllHandlers(inputProps.onBlur, field.onBlur),
|
451
|
+
ref: react.useMergeRefs(ref, _ref)
|
452
|
+
}
|
453
|
+
)
|
454
|
+
}
|
455
|
+
);
|
370
456
|
}
|
371
457
|
);
|
372
458
|
};
|
373
459
|
var withUncontrolledInput = (InputComponent) => {
|
374
460
|
return react.forwardRef(
|
375
461
|
({ name, rules, ...inputProps }, ref) => {
|
376
|
-
const { register } =
|
462
|
+
const { register } = useFormContext();
|
377
463
|
const { ref: _ref, ...field } = register(name, rules);
|
378
|
-
return /* @__PURE__ */
|
379
|
-
|
380
|
-
|
381
|
-
|
382
|
-
|
383
|
-
|
384
|
-
|
464
|
+
return /* @__PURE__ */ jsxRuntime.jsx(
|
465
|
+
InputComponent,
|
466
|
+
{
|
467
|
+
...field,
|
468
|
+
...inputProps,
|
469
|
+
onChange: utils.callAllHandlers(inputProps.onChange, field.onChange),
|
470
|
+
onBlur: utils.callAllHandlers(inputProps.onBlur, field.onBlur),
|
471
|
+
ref: react.useMergeRefs(ref, _ref)
|
472
|
+
}
|
473
|
+
);
|
385
474
|
}
|
386
475
|
);
|
387
476
|
};
|
388
|
-
var
|
477
|
+
var createField = (component, options) => {
|
478
|
+
var _a;
|
389
479
|
let InputComponent;
|
390
480
|
if (options == null ? void 0 : options.isControlled) {
|
391
481
|
InputComponent = withControlledInput(component);
|
392
482
|
} else {
|
393
483
|
InputComponent = withUncontrolledInput(component);
|
394
484
|
}
|
395
|
-
const Field2 =
|
396
|
-
displayName: `${
|
485
|
+
const Field2 = _createField(InputComponent, {
|
486
|
+
displayName: `${(_a = component.displayName) != null ? _a : "Custom"}Field`,
|
397
487
|
hideLabel: options == null ? void 0 : options.hideLabel,
|
398
488
|
BaseField: (options == null ? void 0 : options.BaseField) || BaseField
|
399
489
|
});
|
400
|
-
inputTypes[type] = Field2;
|
401
490
|
return Field2;
|
402
491
|
};
|
403
|
-
var InputField =
|
404
|
-
"text",
|
492
|
+
var InputField = createField(
|
405
493
|
react.forwardRef(({ type = "text", leftAddon, rightAddon, size, ...rest }, ref) => {
|
406
|
-
const input = /* @__PURE__ */
|
407
|
-
type,
|
408
|
-
size,
|
409
|
-
...rest,
|
410
|
-
ref
|
411
|
-
});
|
494
|
+
const input = /* @__PURE__ */ jsxRuntime.jsx(react.Input, { type, size, ...rest, ref });
|
412
495
|
if (leftAddon || rightAddon) {
|
413
|
-
return /* @__PURE__ */
|
414
|
-
|
415
|
-
|
496
|
+
return /* @__PURE__ */ jsxRuntime.jsxs(react.InputGroup, { size, children: [
|
497
|
+
leftAddon,
|
498
|
+
input,
|
499
|
+
rightAddon
|
500
|
+
] });
|
416
501
|
}
|
417
502
|
return input;
|
418
503
|
})
|
419
504
|
);
|
420
|
-
var NumberInputField2 =
|
421
|
-
"number",
|
505
|
+
var NumberInputField2 = createField(
|
422
506
|
NumberInput,
|
423
507
|
{
|
424
508
|
isControlled: true
|
425
509
|
}
|
426
510
|
);
|
427
|
-
var PasswordInputField =
|
428
|
-
|
429
|
-
react.forwardRef((props, ref) => /* @__PURE__ */ React8__namespace.createElement(PasswordInput, {
|
430
|
-
ref,
|
431
|
-
...props
|
432
|
-
}))
|
433
|
-
);
|
434
|
-
var TextareaField = registerFieldType(
|
435
|
-
"textarea",
|
436
|
-
react.Textarea
|
511
|
+
var PasswordInputField = createField(
|
512
|
+
react.forwardRef((props, ref) => /* @__PURE__ */ jsxRuntime.jsx(PasswordInput, { ref, ...props }))
|
437
513
|
);
|
438
|
-
var
|
439
|
-
|
514
|
+
var TextareaField = createField(react.Textarea);
|
515
|
+
var SwitchField = createField(
|
440
516
|
react.forwardRef(({ type, value, ...rest }, ref) => {
|
441
|
-
return /* @__PURE__ */
|
442
|
-
isChecked: !!value,
|
443
|
-
...rest,
|
444
|
-
ref
|
445
|
-
});
|
517
|
+
return /* @__PURE__ */ jsxRuntime.jsx(react.Switch, { isChecked: !!value, ...rest, ref });
|
446
518
|
}),
|
447
519
|
{
|
448
520
|
isControlled: true
|
449
521
|
}
|
450
522
|
);
|
451
|
-
var SelectField =
|
452
|
-
|
453
|
-
|
454
|
-
|
455
|
-
|
456
|
-
|
457
|
-
return /* @__PURE__ */ React8__namespace.createElement(react.Checkbox, {
|
458
|
-
ref,
|
459
|
-
...props
|
460
|
-
}, label);
|
523
|
+
var SelectField = createField(
|
524
|
+
react.forwardRef((props, ref) => {
|
525
|
+
return /* @__PURE__ */ jsxRuntime.jsxs(Select, { ref, ...props, children: [
|
526
|
+
/* @__PURE__ */ jsxRuntime.jsx(SelectButton, {}),
|
527
|
+
/* @__PURE__ */ jsxRuntime.jsx(SelectList, {})
|
528
|
+
] });
|
461
529
|
}),
|
462
530
|
{
|
463
|
-
|
531
|
+
isControlled: true
|
464
532
|
}
|
465
533
|
);
|
466
|
-
var
|
467
|
-
|
468
|
-
|
534
|
+
var CheckboxField = createField(
|
535
|
+
react.forwardRef(({ label, type, ...props }, ref) => {
|
536
|
+
return /* @__PURE__ */ jsxRuntime.jsx(react.Checkbox, { ref, ...props, children: label });
|
537
|
+
}),
|
469
538
|
{
|
470
|
-
|
539
|
+
hideLabel: true
|
471
540
|
}
|
472
541
|
);
|
473
|
-
var
|
474
|
-
|
475
|
-
|
476
|
-
|
477
|
-
|
478
|
-
|
479
|
-
|
542
|
+
var RadioField = createField(RadioInput, {
|
543
|
+
isControlled: true
|
544
|
+
});
|
545
|
+
var NativeSelectField = createField(NativeSelect, {
|
546
|
+
isControlled: true
|
547
|
+
});
|
548
|
+
var PinField = createField(
|
480
549
|
react.forwardRef((props, ref) => {
|
481
550
|
const { pinLength = 4, pinType, spacing, ...inputProps } = props;
|
482
551
|
const inputs = [];
|
483
552
|
for (let i = 0; i < pinLength; i++) {
|
484
|
-
inputs.push(/* @__PURE__ */
|
485
|
-
key: i,
|
486
|
-
ref
|
487
|
-
}));
|
553
|
+
inputs.push(/* @__PURE__ */ jsxRuntime.jsx(react.PinInputField, { ref }, i));
|
488
554
|
}
|
489
|
-
return /* @__PURE__ */
|
490
|
-
spacing
|
491
|
-
}, /* @__PURE__ */ React8__namespace.createElement(react.PinInput, {
|
492
|
-
...inputProps,
|
493
|
-
type: pinType
|
494
|
-
}, inputs));
|
555
|
+
return /* @__PURE__ */ jsxRuntime.jsx(react.HStack, { spacing, children: /* @__PURE__ */ jsxRuntime.jsx(react.PinInput, { ...inputProps, type: pinType, children: inputs }) });
|
495
556
|
}),
|
496
557
|
{
|
497
558
|
isControlled: true
|
498
559
|
}
|
499
560
|
);
|
500
|
-
var
|
501
|
-
|
502
|
-
|
503
|
-
|
504
|
-
|
505
|
-
|
506
|
-
|
507
|
-
|
508
|
-
|
509
|
-
|
510
|
-
|
511
|
-
|
512
|
-
|
513
|
-
|
514
|
-
if (!field)
|
515
|
-
return [];
|
516
|
-
if (((_a = field.items) == null ? void 0 : _a.type) === "object") {
|
517
|
-
return mapFields(field.items.properties);
|
518
|
-
} else if (field.type === "object") {
|
519
|
-
return mapFields(field.properties);
|
520
|
-
}
|
521
|
-
return [field.items];
|
522
|
-
};
|
523
|
-
return { getFields, getNestedFields };
|
561
|
+
var defaultFieldTypes = {
|
562
|
+
text: InputField,
|
563
|
+
email: InputField,
|
564
|
+
url: InputField,
|
565
|
+
phone: InputField,
|
566
|
+
number: NumberInputField2,
|
567
|
+
password: PasswordInputField,
|
568
|
+
textarea: TextareaField,
|
569
|
+
switch: SwitchField,
|
570
|
+
select: SelectField,
|
571
|
+
checkbox: CheckboxField,
|
572
|
+
radio: RadioField,
|
573
|
+
pin: PinField,
|
574
|
+
"native-select": NativeSelectField
|
524
575
|
};
|
525
|
-
|
526
|
-
|
527
|
-
|
576
|
+
var FieldsContext = React13__namespace.default.createContext(
|
577
|
+
null
|
578
|
+
);
|
579
|
+
var FieldsProvider = (props) => {
|
580
|
+
const fields = { ...defaultFieldTypes, ...props.value };
|
581
|
+
return /* @__PURE__ */ jsxRuntime.jsx(FieldsContext.Provider, { value: fields, children: props.children });
|
582
|
+
};
|
583
|
+
var useField = (type) => {
|
584
|
+
const context = React13__namespace.default.useContext(FieldsContext);
|
585
|
+
return (context == null ? void 0 : context[type]) || InputField;
|
586
|
+
};
|
587
|
+
var defaultInputType = "text";
|
588
|
+
var Field = React13__namespace.forwardRef(
|
528
589
|
(props, ref) => {
|
529
|
-
|
530
|
-
const
|
531
|
-
|
532
|
-
|
533
|
-
reValidateMode,
|
534
|
-
shouldFocusError,
|
535
|
-
shouldUnregister,
|
536
|
-
shouldUseNativeValidation,
|
537
|
-
criteriaMode,
|
538
|
-
delayError,
|
539
|
-
schema,
|
540
|
-
defaultValues,
|
541
|
-
values,
|
542
|
-
context,
|
543
|
-
resetOptions,
|
544
|
-
onChange,
|
545
|
-
onSubmit,
|
546
|
-
onError,
|
547
|
-
formRef,
|
548
|
-
children,
|
549
|
-
...rest
|
550
|
-
} = props;
|
551
|
-
const form = {
|
552
|
-
mode,
|
553
|
-
resolver,
|
554
|
-
defaultValues,
|
555
|
-
values,
|
556
|
-
reValidateMode,
|
557
|
-
shouldFocusError,
|
558
|
-
shouldUnregister,
|
559
|
-
shouldUseNativeValidation,
|
560
|
-
criteriaMode,
|
561
|
-
delayError,
|
562
|
-
context,
|
563
|
-
resetOptions
|
564
|
-
};
|
565
|
-
if (schema && !resolver) {
|
566
|
-
form.resolver = (_a = Form.getResolver) == null ? void 0 : _a.call(Form, schema);
|
567
|
-
}
|
568
|
-
const methods = reactHookForm.useForm(form);
|
569
|
-
const { handleSubmit } = methods;
|
570
|
-
React8__namespace.useImperativeHandle(formRef, () => methods, [formRef, methods]);
|
571
|
-
React8__namespace.useEffect(() => {
|
572
|
-
let subscription;
|
573
|
-
if (onChange) {
|
574
|
-
subscription = methods.watch(onChange);
|
575
|
-
}
|
576
|
-
return () => subscription == null ? void 0 : subscription.unsubscribe();
|
577
|
-
}, [methods, onChange]);
|
578
|
-
const Field2 = React8__namespace.useMemo(
|
579
|
-
() => (props2) => /* @__PURE__ */ React8__namespace.createElement(Field, {
|
580
|
-
...props2
|
581
|
-
}),
|
582
|
-
[]
|
583
|
-
);
|
584
|
-
return /* @__PURE__ */ React8__namespace.createElement(reactHookForm.FormProvider, {
|
585
|
-
...methods
|
586
|
-
}, /* @__PURE__ */ React8__namespace.createElement(react.chakra.form, {
|
587
|
-
ref,
|
588
|
-
onSubmit: handleSubmit(onSubmit, onError),
|
589
|
-
...rest,
|
590
|
-
className: utils.cx("sui-form", props.className)
|
591
|
-
}, utils.runIfFn(children, {
|
592
|
-
Field: Field2,
|
593
|
-
...methods
|
594
|
-
})));
|
590
|
+
const { type = defaultInputType, name } = props;
|
591
|
+
const overrides = useFieldProps(name);
|
592
|
+
const InputComponent = useField((overrides == null ? void 0 : overrides.type) || type);
|
593
|
+
return /* @__PURE__ */ jsxRuntime.jsx(InputComponent, { ref, ...props, ...overrides });
|
595
594
|
}
|
596
595
|
);
|
597
|
-
Form.getFieldResolver = objectFieldResolver;
|
598
|
-
Form.displayName = "Form";
|
599
|
-
function createForm({ resolver }) {
|
600
|
-
const CreateForm = (props) => {
|
601
|
-
const { schema, ...rest } = props;
|
602
|
-
return /* @__PURE__ */ React8__namespace.createElement(Form, {
|
603
|
-
resolver: resolver == null ? void 0 : resolver(props.schema),
|
604
|
-
...rest
|
605
|
-
});
|
606
|
-
};
|
607
|
-
return CreateForm;
|
608
|
-
}
|
609
596
|
var FormLayoutItem = ({ children }) => {
|
610
|
-
return /* @__PURE__ */
|
597
|
+
return /* @__PURE__ */ jsxRuntime.jsx(react.chakra.div, { children });
|
611
598
|
};
|
612
|
-
|
613
|
-
FormLayoutItem.displayName = "FormLayoutItem";
|
614
|
-
}
|
599
|
+
FormLayoutItem.displayName = "FormLayoutItem";
|
615
600
|
var FormLayout = ({ children, ...props }) => {
|
616
601
|
var _a, _b, _c;
|
617
602
|
const theme = react.useTheme();
|
618
|
-
const defaultProps = (_c = (_b = (_a = theme.components) == null ? void 0 : _a.
|
603
|
+
const defaultProps = (_c = (_b = (_a = theme.components) == null ? void 0 : _a.SuiFormLayout) == null ? void 0 : _b.defaultProps) != null ? _c : {
|
619
604
|
spacing: 4
|
620
605
|
};
|
621
606
|
const gridProps = {
|
622
607
|
...defaultProps,
|
623
608
|
...props
|
624
609
|
};
|
625
|
-
return /* @__PURE__ */
|
626
|
-
|
627
|
-
|
628
|
-
|
629
|
-
|
630
|
-
|
631
|
-
|
632
|
-
|
633
|
-
|
634
|
-
|
635
|
-
|
636
|
-
FormLayout.displayName = "FormLayout";
|
637
|
-
}
|
638
|
-
var mapNestedFields = (name, children) => {
|
639
|
-
return React8__namespace.Children.map(children, (child) => {
|
640
|
-
if (React8__namespace.isValidElement(child) && child.props.name) {
|
641
|
-
return React8__namespace.cloneElement(child, {
|
642
|
-
...child.props,
|
643
|
-
name: `${name}.${child.props.name}`
|
644
|
-
});
|
610
|
+
return /* @__PURE__ */ jsxRuntime.jsx(
|
611
|
+
react.SimpleGrid,
|
612
|
+
{
|
613
|
+
...gridProps,
|
614
|
+
className: utils.cx("sui-form__layout", props.className),
|
615
|
+
children: React13__namespace.Children.map(children, (child) => {
|
616
|
+
if (React13__namespace.isValidElement(child)) {
|
617
|
+
return /* @__PURE__ */ jsxRuntime.jsx(FormLayoutItem, { children: child });
|
618
|
+
}
|
619
|
+
return child;
|
620
|
+
})
|
645
621
|
}
|
646
|
-
|
647
|
-
});
|
622
|
+
);
|
648
623
|
};
|
624
|
+
FormLayout.displayName = "FormLayout";
|
649
625
|
var [ArrayFieldProvider, useArrayFieldContext] = reactUtils.createContext({
|
650
626
|
name: "ArrayFieldContext"
|
651
627
|
});
|
@@ -659,7 +635,7 @@ var useArrayField = ({
|
|
659
635
|
min,
|
660
636
|
max
|
661
637
|
}) => {
|
662
|
-
const { control } =
|
638
|
+
const { control } = useFormContext();
|
663
639
|
const context = reactHookForm.useFieldArray({
|
664
640
|
control,
|
665
641
|
name,
|
@@ -674,9 +650,9 @@ var useArrayField = ({
|
|
674
650
|
};
|
675
651
|
};
|
676
652
|
var useArrayFieldRow = ({ index }) => {
|
677
|
-
const { clearErrors } =
|
653
|
+
const { clearErrors } = useFormContext();
|
678
654
|
const { name, remove, fields } = useArrayFieldContext();
|
679
|
-
|
655
|
+
React13__namespace.useEffect(() => {
|
680
656
|
clearErrors(name);
|
681
657
|
}, []);
|
682
658
|
return {
|
@@ -684,7 +660,7 @@ var useArrayFieldRow = ({ index }) => {
|
|
684
660
|
isFirst: index === 0,
|
685
661
|
isLast: index === fields.length - 1,
|
686
662
|
name: `${name}.${index}`,
|
687
|
-
remove:
|
663
|
+
remove: React13__namespace.useCallback(() => {
|
688
664
|
clearErrors(name);
|
689
665
|
remove(index);
|
690
666
|
}, [index])
|
@@ -709,39 +685,29 @@ var useArrayFieldAddButton = () => {
|
|
709
685
|
isDisabled
|
710
686
|
};
|
711
687
|
};
|
712
|
-
|
713
|
-
// src/array-field.tsx
|
714
688
|
var ArrayFieldRow = ({
|
715
689
|
children,
|
716
690
|
index,
|
717
691
|
...rowFieldsProps
|
718
692
|
}) => {
|
719
|
-
return /* @__PURE__ */
|
720
|
-
|
721
|
-
|
722
|
-
|
723
|
-
}, children), /* @__PURE__ */ React8__namespace.createElement(ArrayFieldRemoveButton, null));
|
693
|
+
return /* @__PURE__ */ jsxRuntime.jsxs(ArrayFieldRowContainer, { index, children: [
|
694
|
+
/* @__PURE__ */ jsxRuntime.jsx(ArrayFieldRowFields, { ...rowFieldsProps, children }),
|
695
|
+
/* @__PURE__ */ jsxRuntime.jsx(ArrayFieldRemoveButton, {})
|
696
|
+
] });
|
724
697
|
};
|
725
|
-
|
726
|
-
ArrayFieldRow.displayName = "ArrayFieldRow";
|
727
|
-
}
|
698
|
+
ArrayFieldRow.displayName = "ArrayFieldRow";
|
728
699
|
var ArrayFieldRowFields = ({
|
729
700
|
children,
|
730
701
|
...layoutProps
|
731
702
|
}) => {
|
732
703
|
const { name } = useArrayFieldRowContext();
|
733
|
-
return /* @__PURE__ */
|
734
|
-
flex: "1",
|
735
|
-
mr: "2",
|
736
|
-
...layoutProps
|
737
|
-
}, mapNestedFields(name, children));
|
704
|
+
return /* @__PURE__ */ jsxRuntime.jsx(FormLayout, { flex: "1", mr: "2", ...layoutProps, children: mapNestedFields(name, children) });
|
738
705
|
};
|
739
|
-
|
740
|
-
ArrayFieldRowFields.displayName = "ArrayFieldRowFields";
|
741
|
-
}
|
706
|
+
ArrayFieldRowFields.displayName = "ArrayFieldRowFields";
|
742
707
|
var ArrayFieldRowContainer = ({
|
743
708
|
children,
|
744
|
-
index
|
709
|
+
index,
|
710
|
+
...rest
|
745
711
|
}) => {
|
746
712
|
const context = useArrayFieldRow({ index });
|
747
713
|
const styles = {
|
@@ -751,61 +717,45 @@ var ArrayFieldRowContainer = ({
|
|
751
717
|
width: "100%",
|
752
718
|
mb: 4
|
753
719
|
};
|
754
|
-
return /* @__PURE__ */
|
755
|
-
value: context
|
756
|
-
}, /* @__PURE__ */ React8__namespace.createElement(react.chakra.div, {
|
757
|
-
__css: styles
|
758
|
-
}, children));
|
720
|
+
return /* @__PURE__ */ jsxRuntime.jsx(ArrayFieldRowProvider, { value: context, children: /* @__PURE__ */ jsxRuntime.jsx(react.chakra.div, { ...rest, __css: styles, children }) });
|
759
721
|
};
|
760
|
-
|
761
|
-
ArrayFieldRowContainer.displayName = "ArrayFieldRowContainer";
|
762
|
-
}
|
722
|
+
ArrayFieldRowContainer.displayName = "ArrayFieldRowContainer";
|
763
723
|
var ArrayFieldRemoveButton = (props) => {
|
764
|
-
return /* @__PURE__ */
|
765
|
-
"aria-label": "Remove row",
|
766
|
-
...useArrayFieldRemoveButton(),
|
767
|
-
...props
|
768
|
-
}, props.children || /* @__PURE__ */ React8__namespace.createElement(icons.MinusIcon, null));
|
724
|
+
return /* @__PURE__ */ jsxRuntime.jsx(react.Button, { "aria-label": "Remove row", ...useArrayFieldRemoveButton(), ...props, children: props.children || /* @__PURE__ */ jsxRuntime.jsx(icons.MinusIcon, {}) });
|
769
725
|
};
|
770
|
-
|
771
|
-
ArrayFieldRemoveButton.displayName = "ArrayFieldRemoveButton";
|
772
|
-
}
|
726
|
+
ArrayFieldRemoveButton.displayName = "ArrayFieldRemoveButton";
|
773
727
|
var ArrayFieldAddButton = (props) => {
|
774
|
-
return /* @__PURE__ */
|
775
|
-
|
776
|
-
|
777
|
-
|
778
|
-
|
779
|
-
|
728
|
+
return /* @__PURE__ */ jsxRuntime.jsx(
|
729
|
+
react.Button,
|
730
|
+
{
|
731
|
+
"aria-label": "Add row",
|
732
|
+
float: "right",
|
733
|
+
...useArrayFieldAddButton(),
|
734
|
+
...props,
|
735
|
+
children: props.children || /* @__PURE__ */ jsxRuntime.jsx(icons.PlusIcon, {})
|
736
|
+
}
|
737
|
+
);
|
780
738
|
};
|
781
|
-
|
782
|
-
ArrayFieldAddButton.displayName = "ArrayFieldAddButton";
|
783
|
-
}
|
739
|
+
ArrayFieldAddButton.displayName = "ArrayFieldAddButton";
|
784
740
|
var ArrayField = react.forwardRef(
|
785
741
|
(props, ref) => {
|
786
742
|
const { children, ...containerProps } = props;
|
787
|
-
|
788
|
-
|
789
|
-
|
790
|
-
|
791
|
-
|
792
|
-
index
|
793
|
-
}, children)))), /* @__PURE__ */ React8__namespace.createElement(ArrayFieldAddButton, null));
|
743
|
+
const rowFn = utils.isFunction(children) ? children : (fields) => /* @__PURE__ */ jsxRuntime.jsx(jsxRuntime.Fragment, { children: fields.map(({ id }, index) => /* @__PURE__ */ jsxRuntime.jsx(ArrayFieldRow, { index, children }, id)) || null });
|
744
|
+
return /* @__PURE__ */ jsxRuntime.jsxs(ArrayFieldContainer, { ref, ...containerProps, children: [
|
745
|
+
/* @__PURE__ */ jsxRuntime.jsx(ArrayFieldRows, { children: rowFn }),
|
746
|
+
/* @__PURE__ */ jsxRuntime.jsx(ArrayFieldAddButton, {})
|
747
|
+
] });
|
794
748
|
}
|
795
749
|
);
|
796
|
-
|
797
|
-
ArrayField.displayName = "ArrayField";
|
798
|
-
}
|
750
|
+
ArrayField.displayName = "ArrayField";
|
799
751
|
var ArrayFieldRows = ({
|
800
752
|
children
|
801
753
|
}) => {
|
802
754
|
const { fields } = useArrayFieldContext();
|
803
755
|
return children(fields);
|
804
756
|
};
|
805
|
-
|
806
|
-
|
807
|
-
}
|
808
|
-
var ArrayFieldContainer = React8__namespace.forwardRef(
|
757
|
+
ArrayFieldRows.displayName = "ArrayFieldRows";
|
758
|
+
var ArrayFieldContainer = React13__namespace.forwardRef(
|
809
759
|
({
|
810
760
|
name,
|
811
761
|
defaultValue,
|
@@ -822,74 +772,59 @@ var ArrayFieldContainer = React8__namespace.forwardRef(
|
|
822
772
|
min,
|
823
773
|
max
|
824
774
|
});
|
825
|
-
|
826
|
-
return /* @__PURE__ */
|
827
|
-
value: context
|
828
|
-
}, /* @__PURE__ */ React8__namespace.createElement(BaseField, {
|
829
|
-
name,
|
830
|
-
...fieldProps
|
831
|
-
}, children));
|
775
|
+
React13__namespace.useImperativeHandle(ref, () => context, [ref, context]);
|
776
|
+
return /* @__PURE__ */ jsxRuntime.jsx(ArrayFieldProvider, { value: context, children: /* @__PURE__ */ jsxRuntime.jsx(BaseField, { name, ...fieldProps, children }) });
|
832
777
|
}
|
833
778
|
);
|
834
|
-
|
835
|
-
ArrayFieldContainer.displayName = "ArrayFieldContainer";
|
836
|
-
}
|
779
|
+
ArrayFieldContainer.displayName = "ArrayFieldContainer";
|
837
780
|
var FormLegend = (props) => {
|
838
781
|
const styles = react.useStyleConfig("SuiFormLegend");
|
839
|
-
return /* @__PURE__ */
|
840
|
-
as: "legend",
|
841
|
-
sx: styles,
|
842
|
-
...props
|
843
|
-
});
|
782
|
+
return /* @__PURE__ */ jsxRuntime.jsx(react.FormLabel, { as: "legend", sx: styles, ...props });
|
844
783
|
};
|
845
784
|
var ObjectField = (props) => {
|
846
785
|
const { name, label, hideLabel, children, columns, spacing, ...fieldProps } = props;
|
847
|
-
return /* @__PURE__ */
|
848
|
-
|
849
|
-
|
850
|
-
|
851
|
-
}, /* @__PURE__ */ React8__namespace.createElement(FormLegend, {
|
852
|
-
display: hideLabel ? "none" : "block"
|
853
|
-
}, label), /* @__PURE__ */ React8__namespace.createElement(FormLayout, {
|
854
|
-
columns,
|
855
|
-
gridGap: spacing
|
856
|
-
}, mapNestedFields(name, children)));
|
786
|
+
return /* @__PURE__ */ jsxRuntime.jsxs(react.FormControl, { name, as: "fieldset", ...fieldProps, children: [
|
787
|
+
/* @__PURE__ */ jsxRuntime.jsx(FormLegend, { display: hideLabel ? "none" : "block", children: label }),
|
788
|
+
/* @__PURE__ */ jsxRuntime.jsx(FormLayout, { columns, gridGap: spacing, children: mapNestedFields(name, children) })
|
789
|
+
] });
|
857
790
|
};
|
858
|
-
|
859
|
-
ObjectField.displayName = "ObjectField";
|
860
|
-
}
|
791
|
+
ObjectField.displayName = "ObjectField";
|
861
792
|
var mapNestedFields2 = (resolver, name) => {
|
862
793
|
var _a;
|
863
794
|
return (_a = resolver.getNestedFields(name)) == null ? void 0 : _a.map(
|
864
|
-
({ name: name2, type, ...nestedFieldProps }, i) => /* @__PURE__ */
|
865
|
-
|
866
|
-
|
867
|
-
|
868
|
-
|
869
|
-
|
795
|
+
({ name: name2, type, ...nestedFieldProps }, i) => /* @__PURE__ */ jsxRuntime.jsx(
|
796
|
+
Field,
|
797
|
+
{
|
798
|
+
name: name2,
|
799
|
+
type,
|
800
|
+
...nestedFieldProps
|
801
|
+
},
|
802
|
+
name2 || i
|
803
|
+
)
|
870
804
|
);
|
871
805
|
};
|
872
|
-
var
|
873
|
-
schema,
|
874
|
-
fieldResolver,
|
806
|
+
var AutoFields = ({
|
807
|
+
schema: schemaProp,
|
808
|
+
fieldResolver: fieldResolverProp,
|
875
809
|
focusFirstField,
|
876
810
|
...props
|
877
811
|
}) => {
|
878
|
-
const
|
879
|
-
|
880
|
-
|
881
|
-
);
|
882
|
-
const fields =
|
883
|
-
const form =
|
884
|
-
|
812
|
+
const context = useFormContext();
|
813
|
+
const schema = schemaProp || context.schema;
|
814
|
+
const fieldResolver = fieldResolverProp || context.fieldResolver;
|
815
|
+
const resolver = React13__namespace.useMemo(() => fieldResolver, [schema, fieldResolver]);
|
816
|
+
const fields = React13__namespace.useMemo(() => resolver == null ? void 0 : resolver.getFields(), [resolver]);
|
817
|
+
const form = useFormContext();
|
818
|
+
React13__namespace.useEffect(() => {
|
885
819
|
var _a;
|
886
|
-
if (focusFirstField && ((_a = fields[0]) == null ? void 0 : _a.name)) {
|
820
|
+
if (focusFirstField && ((_a = fields == null ? void 0 : fields[0]) == null ? void 0 : _a.name)) {
|
887
821
|
form.setFocus(fields[0].name);
|
888
822
|
}
|
889
823
|
}, [schema, fieldResolver, focusFirstField]);
|
890
|
-
|
891
|
-
|
892
|
-
}
|
824
|
+
if (!resolver) {
|
825
|
+
return null;
|
826
|
+
}
|
827
|
+
return /* @__PURE__ */ jsxRuntime.jsx(FormLayout, { ...props, children: fields == null ? void 0 : fields.map(
|
893
828
|
({
|
894
829
|
name,
|
895
830
|
type,
|
@@ -897,28 +832,15 @@ var Fields = ({
|
|
897
832
|
...fieldProps
|
898
833
|
}) => {
|
899
834
|
if (type === "array") {
|
900
|
-
return /* @__PURE__ */
|
901
|
-
key: name,
|
902
|
-
name,
|
903
|
-
...fieldProps
|
904
|
-
}, mapNestedFields2(resolver, name));
|
835
|
+
return /* @__PURE__ */ jsxRuntime.jsx(ArrayField, { name, ...fieldProps, children: mapNestedFields2(resolver, name) }, name);
|
905
836
|
} else if (type === "object") {
|
906
|
-
return /* @__PURE__ */
|
907
|
-
key: name,
|
908
|
-
name,
|
909
|
-
...fieldProps
|
910
|
-
}, mapNestedFields2(resolver, name));
|
837
|
+
return /* @__PURE__ */ jsxRuntime.jsx(ObjectField, { name, ...fieldProps, children: mapNestedFields2(resolver, name) }, name);
|
911
838
|
}
|
912
|
-
return /* @__PURE__ */
|
913
|
-
key: name,
|
914
|
-
name,
|
915
|
-
type,
|
916
|
-
...fieldProps
|
917
|
-
});
|
839
|
+
return /* @__PURE__ */ jsxRuntime.jsx(Field, { name, type, ...fieldProps }, name);
|
918
840
|
}
|
919
|
-
));
|
841
|
+
) });
|
920
842
|
};
|
921
|
-
|
843
|
+
AutoFields.displayName = "Fields";
|
922
844
|
var SubmitButton = react.forwardRef(
|
923
845
|
(props, ref) => {
|
924
846
|
const {
|
@@ -931,13 +853,17 @@ var SubmitButton = react.forwardRef(
|
|
931
853
|
} = props;
|
932
854
|
const { formState } = reactHookForm.useFormContext();
|
933
855
|
const isDisabled = disableIfUntouched && !formState.isDirty || disableIfInvalid && !formState.isValid || isDisabledProp;
|
934
|
-
return /* @__PURE__ */
|
935
|
-
|
936
|
-
|
937
|
-
|
938
|
-
|
939
|
-
|
940
|
-
|
856
|
+
return /* @__PURE__ */ jsxRuntime.jsx(
|
857
|
+
react.Button,
|
858
|
+
{
|
859
|
+
...rest,
|
860
|
+
ref,
|
861
|
+
type: "submit",
|
862
|
+
isLoading: formState.isSubmitting || isLoading,
|
863
|
+
isDisabled,
|
864
|
+
children
|
865
|
+
}
|
866
|
+
);
|
941
867
|
}
|
942
868
|
);
|
943
869
|
SubmitButton.defaultProps = {
|
@@ -946,28 +872,6 @@ SubmitButton.defaultProps = {
|
|
946
872
|
disableIfInvalid: false
|
947
873
|
};
|
948
874
|
SubmitButton.displayName = "SubmitButton";
|
949
|
-
|
950
|
-
// src/auto-form.tsx
|
951
|
-
var AutoForm = react.forwardRef(
|
952
|
-
(props, ref) => {
|
953
|
-
const {
|
954
|
-
schema,
|
955
|
-
submitLabel = "Submit",
|
956
|
-
fieldResolver,
|
957
|
-
children,
|
958
|
-
...rest
|
959
|
-
} = props;
|
960
|
-
return /* @__PURE__ */ React8__namespace.createElement(Form, {
|
961
|
-
...rest,
|
962
|
-
schema,
|
963
|
-
ref
|
964
|
-
}, /* @__PURE__ */ React8__namespace.createElement(FormLayout, null, /* @__PURE__ */ React8__namespace.createElement(Fields, {
|
965
|
-
schema,
|
966
|
-
fieldResolver
|
967
|
-
}), submitLabel && /* @__PURE__ */ React8__namespace.createElement(SubmitButton, null, submitLabel), children));
|
968
|
-
}
|
969
|
-
);
|
970
|
-
AutoForm.displayName = "AutoForm";
|
971
875
|
var DisplayIf = ({
|
972
876
|
children,
|
973
877
|
name,
|
@@ -982,12 +886,94 @@ var DisplayIf = ({
|
|
982
886
|
disabled: isDisabled,
|
983
887
|
exact: isExact
|
984
888
|
});
|
985
|
-
const context =
|
889
|
+
const context = useFormContext();
|
986
890
|
return condition(value, context) ? children : null;
|
987
891
|
};
|
988
|
-
|
989
|
-
|
990
|
-
|
892
|
+
DisplayIf.displayName = "DisplayIf";
|
893
|
+
var Form = react.forwardRef(
|
894
|
+
(props, ref) => {
|
895
|
+
const {
|
896
|
+
mode = "all",
|
897
|
+
resolver,
|
898
|
+
fieldResolver,
|
899
|
+
fields,
|
900
|
+
reValidateMode,
|
901
|
+
shouldFocusError,
|
902
|
+
shouldUnregister,
|
903
|
+
shouldUseNativeValidation,
|
904
|
+
criteriaMode,
|
905
|
+
delayError,
|
906
|
+
schema,
|
907
|
+
defaultValues,
|
908
|
+
values,
|
909
|
+
context,
|
910
|
+
resetOptions,
|
911
|
+
onChange,
|
912
|
+
onSubmit,
|
913
|
+
onError,
|
914
|
+
formRef,
|
915
|
+
children,
|
916
|
+
...rest
|
917
|
+
} = props;
|
918
|
+
const form = {
|
919
|
+
mode,
|
920
|
+
resolver,
|
921
|
+
defaultValues,
|
922
|
+
values,
|
923
|
+
reValidateMode,
|
924
|
+
shouldFocusError,
|
925
|
+
shouldUnregister,
|
926
|
+
shouldUseNativeValidation,
|
927
|
+
criteriaMode,
|
928
|
+
delayError,
|
929
|
+
context,
|
930
|
+
resetOptions
|
931
|
+
};
|
932
|
+
const methods = reactHookForm.useForm(form);
|
933
|
+
const { handleSubmit } = methods;
|
934
|
+
React13__namespace.useImperativeHandle(formRef, () => methods, [formRef, methods]);
|
935
|
+
React13__namespace.useEffect(() => {
|
936
|
+
let subscription;
|
937
|
+
if (onChange) {
|
938
|
+
subscription = methods.watch(onChange);
|
939
|
+
}
|
940
|
+
return () => subscription == null ? void 0 : subscription.unsubscribe();
|
941
|
+
}, [methods, onChange]);
|
942
|
+
let _children = children;
|
943
|
+
if (!_children && fieldResolver) {
|
944
|
+
_children = /* @__PURE__ */ jsxRuntime.jsxs(FormLayout, { children: [
|
945
|
+
/* @__PURE__ */ jsxRuntime.jsx(AutoFields, {}),
|
946
|
+
/* @__PURE__ */ jsxRuntime.jsx(SubmitButton, { ...fields == null ? void 0 : fields.submit })
|
947
|
+
] });
|
948
|
+
}
|
949
|
+
return /* @__PURE__ */ jsxRuntime.jsx(
|
950
|
+
FormProvider,
|
951
|
+
{
|
952
|
+
...methods,
|
953
|
+
schema,
|
954
|
+
fieldResolver,
|
955
|
+
fields,
|
956
|
+
children: /* @__PURE__ */ jsxRuntime.jsx(
|
957
|
+
react.chakra.form,
|
958
|
+
{
|
959
|
+
ref,
|
960
|
+
onSubmit: handleSubmit(onSubmit, onError),
|
961
|
+
...rest,
|
962
|
+
className: utils.cx("sui-form", props.className),
|
963
|
+
children: utils.runIfFn(_children, {
|
964
|
+
Field,
|
965
|
+
DisplayIf,
|
966
|
+
ArrayField,
|
967
|
+
ObjectField,
|
968
|
+
...methods
|
969
|
+
})
|
970
|
+
}
|
971
|
+
)
|
972
|
+
}
|
973
|
+
);
|
974
|
+
}
|
975
|
+
);
|
976
|
+
Form.displayName = "Form";
|
991
977
|
var [StepFormProvider, useStepFormContext] = reactUtils.createContext({
|
992
978
|
name: "StepFormContext",
|
993
979
|
errorMessage: "useStepFormContext: `context` is undefined. Seems you forgot to wrap step form components in `<StepForm />`"
|
@@ -996,8 +982,8 @@ function useStepForm(props) {
|
|
996
982
|
const { onChange, ...rest } = props;
|
997
983
|
const stepper = core.useStepper(rest);
|
998
984
|
const { activeStep, isLastStep, nextStep } = stepper;
|
999
|
-
const [steps, updateSteps] =
|
1000
|
-
const onSubmitStep =
|
985
|
+
const [steps, updateSteps] = React13__namespace.useState({});
|
986
|
+
const onSubmitStep = React13__namespace.useCallback(
|
1001
987
|
async (data) => {
|
1002
988
|
var _a, _b;
|
1003
989
|
try {
|
@@ -1018,7 +1004,7 @@ function useStepForm(props) {
|
|
1018
1004
|
},
|
1019
1005
|
[steps, activeStep, isLastStep]
|
1020
1006
|
);
|
1021
|
-
const getFormProps =
|
1007
|
+
const getFormProps = React13__namespace.useCallback(() => {
|
1022
1008
|
const step = steps[activeStep];
|
1023
1009
|
return {
|
1024
1010
|
onSubmit: onSubmitStep,
|
@@ -1026,7 +1012,7 @@ function useStepForm(props) {
|
|
1026
1012
|
resolver: step == null ? void 0 : step.resolver
|
1027
1013
|
};
|
1028
1014
|
}, [steps, onSubmitStep, activeStep]);
|
1029
|
-
const updateStep =
|
1015
|
+
const updateStep = React13__namespace.useCallback(
|
1030
1016
|
(step) => {
|
1031
1017
|
updateSteps((steps2) => {
|
1032
1018
|
return {
|
@@ -1048,7 +1034,7 @@ function useFormStep(props) {
|
|
1048
1034
|
const { name, schema, resolver, onSubmit } = props;
|
1049
1035
|
const step = core.useStep({ name });
|
1050
1036
|
const { steps, updateStep } = useStepFormContext();
|
1051
|
-
|
1037
|
+
React13__namespace.useEffect(() => {
|
1052
1038
|
updateStep({ name, schema, resolver, onSubmit });
|
1053
1039
|
}, [name, schema]);
|
1054
1040
|
return {
|
@@ -1056,95 +1042,114 @@ function useFormStep(props) {
|
|
1056
1042
|
...steps[name] || { name, schema }
|
1057
1043
|
};
|
1058
1044
|
}
|
1059
|
-
|
1060
|
-
// src/step-form.tsx
|
1061
|
-
var StepForm = React8__namespace.forwardRef(
|
1045
|
+
var StepForm = React13__namespace.forwardRef(
|
1062
1046
|
(props, ref) => {
|
1063
1047
|
const { children, ...rest } = props;
|
1064
1048
|
const stepper = useStepForm(props);
|
1065
1049
|
const { getFormProps, ...ctx } = stepper;
|
1066
|
-
const context =
|
1067
|
-
return /* @__PURE__ */
|
1068
|
-
value: context
|
1069
|
-
}, /* @__PURE__ */ React8__namespace.createElement(StepFormProvider, {
|
1070
|
-
value: context
|
1071
|
-
}, /* @__PURE__ */ React8__namespace.createElement(Form, {
|
1072
|
-
ref,
|
1073
|
-
...rest,
|
1074
|
-
...getFormProps()
|
1075
|
-
}, utils.runIfFn(children, stepper))));
|
1050
|
+
const context = React13__namespace.useMemo(() => ctx, [ctx]);
|
1051
|
+
return /* @__PURE__ */ jsxRuntime.jsx(core.StepperProvider, { value: context, children: /* @__PURE__ */ jsxRuntime.jsx(StepFormProvider, { value: context, children: /* @__PURE__ */ jsxRuntime.jsx(Form, { ref, ...rest, ...getFormProps(), children: utils.runIfFn(children, stepper) }) }) });
|
1076
1052
|
}
|
1077
1053
|
);
|
1078
1054
|
var FormStepper = (props) => {
|
1079
1055
|
const { activeIndex, setIndex } = core.useStepperContext();
|
1080
1056
|
const { children, orientation, variant, colorScheme, size, ...rest } = props;
|
1081
|
-
const elements =
|
1082
|
-
if (
|
1057
|
+
const elements = React13__namespace.Children.map(children, (child) => {
|
1058
|
+
if (React13__namespace.isValidElement(child) && (child == null ? void 0 : child.type) === FormStep) {
|
1083
1059
|
const { isCompleted } = useFormStep(child.props);
|
1084
|
-
return /* @__PURE__ */
|
1085
|
-
|
1086
|
-
|
1087
|
-
|
1088
|
-
|
1089
|
-
|
1060
|
+
return /* @__PURE__ */ jsxRuntime.jsx(
|
1061
|
+
core.StepperStep,
|
1062
|
+
{
|
1063
|
+
name: child.props.name,
|
1064
|
+
title: child.props.title,
|
1065
|
+
isCompleted,
|
1066
|
+
...rest,
|
1067
|
+
children: child.props.children
|
1068
|
+
}
|
1069
|
+
);
|
1090
1070
|
}
|
1091
1071
|
return child;
|
1092
1072
|
});
|
1093
|
-
const onChange =
|
1073
|
+
const onChange = React13__namespace.useCallback((i) => {
|
1094
1074
|
setIndex(i);
|
1095
1075
|
}, []);
|
1096
|
-
return /* @__PURE__ */
|
1097
|
-
|
1098
|
-
|
1099
|
-
|
1100
|
-
|
1101
|
-
|
1102
|
-
|
1103
|
-
|
1104
|
-
|
1105
|
-
|
1106
|
-
|
1076
|
+
return /* @__PURE__ */ jsxRuntime.jsx(
|
1077
|
+
core.StepperContainer,
|
1078
|
+
{
|
1079
|
+
orientation,
|
1080
|
+
step: activeIndex,
|
1081
|
+
variant,
|
1082
|
+
colorScheme,
|
1083
|
+
size,
|
1084
|
+
onChange,
|
1085
|
+
children: /* @__PURE__ */ jsxRuntime.jsx(core.StepperSteps, { mb: "4", ...props, children: elements })
|
1086
|
+
}
|
1087
|
+
);
|
1107
1088
|
};
|
1108
1089
|
var FormStep = (props) => {
|
1109
1090
|
const { name, schema, resolver, children, className, onSubmit, ...rest } = props;
|
1110
1091
|
const step = useFormStep({ name, schema, resolver, onSubmit });
|
1111
1092
|
const { isActive } = step;
|
1112
|
-
return isActive ? /* @__PURE__ */
|
1113
|
-
...rest,
|
1114
|
-
className: utils.cx("sui-form__step", className)
|
1115
|
-
}, children) : null;
|
1093
|
+
return isActive ? /* @__PURE__ */ jsxRuntime.jsx(react.chakra.div, { ...rest, className: utils.cx("sui-form__step", className), children }) : null;
|
1116
1094
|
};
|
1117
|
-
|
1118
|
-
FormStep.displayName = "FormStep";
|
1119
|
-
}
|
1095
|
+
FormStep.displayName = "FormStep";
|
1120
1096
|
var PrevButton = (props) => {
|
1121
1097
|
const { isFirstStep, isCompleted, prevStep } = core.useStepperContext();
|
1122
|
-
return /* @__PURE__ */
|
1123
|
-
|
1124
|
-
|
1125
|
-
|
1126
|
-
|
1127
|
-
|
1128
|
-
|
1098
|
+
return /* @__PURE__ */ jsxRuntime.jsx(
|
1099
|
+
react.Button,
|
1100
|
+
{
|
1101
|
+
isDisabled: isFirstStep || isCompleted,
|
1102
|
+
label: "Back",
|
1103
|
+
...props,
|
1104
|
+
className: utils.cx("sui-form__prev-button", props.className),
|
1105
|
+
onClick: utils.callAllHandlers(props.onClick, prevStep)
|
1106
|
+
}
|
1107
|
+
);
|
1129
1108
|
};
|
1130
|
-
|
1131
|
-
PrevButton.displayName = "PrevButton";
|
1132
|
-
}
|
1109
|
+
PrevButton.displayName = "PrevButton";
|
1133
1110
|
var NextButton = (props) => {
|
1134
1111
|
const { label = "Next", submitLabel = "Complete", ...rest } = props;
|
1135
1112
|
const { isLastStep, isCompleted } = core.useStepperContext();
|
1136
|
-
return /* @__PURE__ */
|
1137
|
-
|
1138
|
-
|
1139
|
-
|
1140
|
-
|
1113
|
+
return /* @__PURE__ */ jsxRuntime.jsx(
|
1114
|
+
SubmitButton,
|
1115
|
+
{
|
1116
|
+
...rest,
|
1117
|
+
isDisabled: isCompleted,
|
1118
|
+
className: utils.cx("sui-form__next-button", props.className),
|
1119
|
+
children: isLastStep || isCompleted ? submitLabel : label
|
1120
|
+
}
|
1121
|
+
);
|
1122
|
+
};
|
1123
|
+
NextButton.displayName = "NextButton";
|
1124
|
+
var mapFields = (schema) => schema && Object.entries(schema).map(([name, { items, label, title, ...field }]) => {
|
1125
|
+
return {
|
1126
|
+
...field,
|
1127
|
+
name,
|
1128
|
+
label: label || title || name
|
1129
|
+
// json schema compatibility
|
1130
|
+
};
|
1131
|
+
});
|
1132
|
+
var objectFieldResolver = (schema) => {
|
1133
|
+
const getFields = () => {
|
1134
|
+
return mapFields(schema);
|
1135
|
+
};
|
1136
|
+
const getNestedFields = (name) => {
|
1137
|
+
var _a;
|
1138
|
+
const field = utils.get(schema, name);
|
1139
|
+
if (!field)
|
1140
|
+
return [];
|
1141
|
+
if (((_a = field.items) == null ? void 0 : _a.type) === "object") {
|
1142
|
+
return mapFields(field.items.properties);
|
1143
|
+
} else if (field.type === "object") {
|
1144
|
+
return mapFields(field.properties);
|
1145
|
+
}
|
1146
|
+
return [field.items];
|
1147
|
+
};
|
1148
|
+
return { getFields, getNestedFields };
|
1141
1149
|
};
|
1142
|
-
if (utils.__DEV__) {
|
1143
|
-
NextButton.displayName = "NextButton";
|
1144
|
-
}
|
1145
1150
|
var WatchField = (props) => {
|
1146
1151
|
const { name, defaultValue, isDisabled, isExact } = props;
|
1147
|
-
const form =
|
1152
|
+
const form = useFormContext();
|
1148
1153
|
const field = reactHookForm.useWatch({
|
1149
1154
|
name,
|
1150
1155
|
defaultValue,
|
@@ -1153,15 +1158,33 @@ var WatchField = (props) => {
|
|
1153
1158
|
});
|
1154
1159
|
return props.children(field, form) || null;
|
1155
1160
|
};
|
1161
|
+
function createForm({
|
1162
|
+
resolver,
|
1163
|
+
fieldResolver = objectFieldResolver,
|
1164
|
+
fields
|
1165
|
+
} = {}) {
|
1166
|
+
const CreateForm = react.forwardRef(
|
1167
|
+
(props, ref) => {
|
1168
|
+
const { schema, ...rest } = props;
|
1169
|
+
return /* @__PURE__ */ jsxRuntime.jsx(FieldsProvider, { value: fields || {}, children: /* @__PURE__ */ jsxRuntime.jsx(
|
1170
|
+
Form,
|
1171
|
+
{
|
1172
|
+
ref,
|
1173
|
+
resolver: resolver == null ? void 0 : resolver(props.schema),
|
1174
|
+
fieldResolver: fieldResolver == null ? void 0 : fieldResolver(schema),
|
1175
|
+
...rest
|
1176
|
+
}
|
1177
|
+
) });
|
1178
|
+
}
|
1179
|
+
);
|
1180
|
+
return CreateForm;
|
1181
|
+
}
|
1182
|
+
var Form2 = createForm();
|
1156
1183
|
|
1157
1184
|
Object.defineProperty(exports, 'Controller', {
|
1158
1185
|
enumerable: true,
|
1159
1186
|
get: function () { return reactHookForm.Controller; }
|
1160
1187
|
});
|
1161
|
-
Object.defineProperty(exports, 'FormProvider', {
|
1162
|
-
enumerable: true,
|
1163
|
-
get: function () { return reactHookForm.FormProvider; }
|
1164
|
-
});
|
1165
1188
|
Object.defineProperty(exports, 'appendErrors', {
|
1166
1189
|
enumerable: true,
|
1167
1190
|
get: function () { return reactHookForm.appendErrors; }
|
@@ -1178,10 +1201,6 @@ Object.defineProperty(exports, 'useForm', {
|
|
1178
1201
|
enumerable: true,
|
1179
1202
|
get: function () { return reactHookForm.useForm; }
|
1180
1203
|
});
|
1181
|
-
Object.defineProperty(exports, 'useFormContext', {
|
1182
|
-
enumerable: true,
|
1183
|
-
get: function () { return reactHookForm.useFormContext; }
|
1184
|
-
});
|
1185
1204
|
Object.defineProperty(exports, 'useFormState', {
|
1186
1205
|
enumerable: true,
|
1187
1206
|
get: function () { return reactHookForm.useFormState; }
|
@@ -1200,16 +1219,18 @@ exports.ArrayFieldRowContainer = ArrayFieldRowContainer;
|
|
1200
1219
|
exports.ArrayFieldRowFields = ArrayFieldRowFields;
|
1201
1220
|
exports.ArrayFieldRowProvider = ArrayFieldRowProvider;
|
1202
1221
|
exports.ArrayFieldRows = ArrayFieldRows;
|
1203
|
-
exports.
|
1222
|
+
exports.AutoFields = AutoFields;
|
1204
1223
|
exports.BaseField = BaseField;
|
1224
|
+
exports.BaseForm = Form;
|
1205
1225
|
exports.CheckboxField = CheckboxField;
|
1206
1226
|
exports.DisplayField = DisplayField;
|
1207
1227
|
exports.DisplayIf = DisplayIf;
|
1208
1228
|
exports.Field = Field;
|
1209
|
-
exports.
|
1210
|
-
exports.Form =
|
1229
|
+
exports.FieldsProvider = FieldsProvider;
|
1230
|
+
exports.Form = Form2;
|
1211
1231
|
exports.FormLayout = FormLayout;
|
1212
1232
|
exports.FormLegend = FormLegend;
|
1233
|
+
exports.FormProvider = FormProvider;
|
1213
1234
|
exports.FormStep = FormStep;
|
1214
1235
|
exports.FormStepper = FormStepper;
|
1215
1236
|
exports.FormValue = FormValue;
|
@@ -1225,27 +1246,32 @@ exports.PasswordInputField = PasswordInputField;
|
|
1225
1246
|
exports.PinField = PinField;
|
1226
1247
|
exports.PrevButton = PrevButton;
|
1227
1248
|
exports.RadioField = RadioField;
|
1249
|
+
exports.RadioInput = RadioInput;
|
1228
1250
|
exports.Select = Select;
|
1251
|
+
exports.SelectButton = SelectButton;
|
1229
1252
|
exports.SelectField = SelectField;
|
1253
|
+
exports.SelectList = SelectList;
|
1254
|
+
exports.SelectOption = SelectOption;
|
1230
1255
|
exports.StepForm = StepForm;
|
1231
1256
|
exports.StepFormProvider = StepFormProvider;
|
1232
1257
|
exports.SubmitButton = SubmitButton;
|
1233
1258
|
exports.SwitchField = SwitchField;
|
1234
1259
|
exports.TextareaField = TextareaField;
|
1235
1260
|
exports.WatchField = WatchField;
|
1261
|
+
exports.createField = createField;
|
1236
1262
|
exports.createForm = createForm;
|
1263
|
+
exports.defaultFieldTypes = defaultFieldTypes;
|
1237
1264
|
exports.objectFieldResolver = objectFieldResolver;
|
1238
|
-
exports.registerFieldType = registerFieldType;
|
1239
1265
|
exports.useArrayField = useArrayField;
|
1240
1266
|
exports.useArrayFieldAddButton = useArrayFieldAddButton;
|
1241
1267
|
exports.useArrayFieldContext = useArrayFieldContext;
|
1242
1268
|
exports.useArrayFieldRemoveButton = useArrayFieldRemoveButton;
|
1243
1269
|
exports.useArrayFieldRow = useArrayFieldRow;
|
1244
1270
|
exports.useArrayFieldRowContext = useArrayFieldRowContext;
|
1271
|
+
exports.useField = useField;
|
1272
|
+
exports.useFormContext = useFormContext;
|
1245
1273
|
exports.useFormStep = useFormStep;
|
1246
1274
|
exports.useStepForm = useStepForm;
|
1247
1275
|
exports.useStepFormContext = useStepFormContext;
|
1248
|
-
exports.withControlledInput = withControlledInput;
|
1249
|
-
exports.withUncontrolledInput = withUncontrolledInput;
|
1250
1276
|
//# sourceMappingURL=out.js.map
|
1251
1277
|
//# sourceMappingURL=index.js.map
|