@saas-ui/forms 2.0.4 → 2.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 +19 -0
- package/dist/ajv/index.js +42 -14
- package/dist/ajv/index.js.map +1 -1
- package/dist/ajv/index.mjs +14 -6
- package/dist/ajv/index.mjs.map +1 -1
- package/dist/index.d.ts +5 -4
- package/dist/index.js +539 -322
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +481 -165
- package/dist/index.mjs.map +1 -1
- package/dist/yup/index.d.ts +2 -2
- package/dist/yup/index.js +120 -82
- package/dist/yup/index.js.map +1 -1
- package/dist/yup/index.mjs +132 -38
- package/dist/yup/index.mjs.map +1 -1
- package/dist/zod/index.d.ts +2 -2
- package/dist/zod/index.js +116 -83
- package/dist/zod/index.js.map +1 -1
- package/dist/zod/index.mjs +124 -35
- package/dist/zod/index.mjs.map +1 -1
- package/package.json +7 -7
package/dist/index.js
CHANGED
@@ -1,39 +1,119 @@
|
|
1
|
-
'use
|
2
|
-
|
3
|
-
var
|
4
|
-
var
|
5
|
-
var
|
6
|
-
var
|
7
|
-
var
|
8
|
-
var
|
9
|
-
var
|
10
|
-
var
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
var d = Object.getOwnPropertyDescriptor(e, k);
|
19
|
-
Object.defineProperty(n, k, d.get ? d : {
|
20
|
-
enumerable: true,
|
21
|
-
get: function () { return e[k]; }
|
22
|
-
});
|
23
|
-
}
|
24
|
-
});
|
1
|
+
'use client'
|
2
|
+
"use strict";
|
3
|
+
var __create = Object.create;
|
4
|
+
var __defProp = Object.defineProperty;
|
5
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
6
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
7
|
+
var __getProtoOf = Object.getPrototypeOf;
|
8
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
9
|
+
var __export = (target, all) => {
|
10
|
+
for (var name in all)
|
11
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
12
|
+
};
|
13
|
+
var __copyProps = (to, from, except, desc) => {
|
14
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
15
|
+
for (let key of __getOwnPropNames(from))
|
16
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
17
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
25
18
|
}
|
26
|
-
|
27
|
-
|
28
|
-
}
|
19
|
+
return to;
|
20
|
+
};
|
21
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
22
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
23
|
+
// file that has been converted to a CommonJS file using a Babel-
|
24
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
25
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
26
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
27
|
+
mod
|
28
|
+
));
|
29
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
29
30
|
|
30
|
-
|
31
|
+
// src/index.ts
|
32
|
+
var src_exports = {};
|
33
|
+
__export(src_exports, {
|
34
|
+
ArrayField: () => ArrayField,
|
35
|
+
ArrayFieldAddButton: () => ArrayFieldAddButton,
|
36
|
+
ArrayFieldContainer: () => ArrayFieldContainer,
|
37
|
+
ArrayFieldProvider: () => ArrayFieldProvider,
|
38
|
+
ArrayFieldRemoveButton: () => ArrayFieldRemoveButton,
|
39
|
+
ArrayFieldRow: () => ArrayFieldRow,
|
40
|
+
ArrayFieldRowContainer: () => ArrayFieldRowContainer,
|
41
|
+
ArrayFieldRowFields: () => ArrayFieldRowFields,
|
42
|
+
ArrayFieldRowProvider: () => ArrayFieldRowProvider,
|
43
|
+
ArrayFieldRows: () => ArrayFieldRows,
|
44
|
+
AutoFields: () => AutoFields,
|
45
|
+
BaseField: () => BaseField,
|
46
|
+
BaseForm: () => Form,
|
47
|
+
CheckboxField: () => CheckboxField,
|
48
|
+
Controller: () => import_react_hook_form9.Controller,
|
49
|
+
DisplayField: () => DisplayField,
|
50
|
+
DisplayIf: () => DisplayIf,
|
51
|
+
Field: () => Field,
|
52
|
+
FieldsProvider: () => FieldsProvider,
|
53
|
+
Form: () => Form2,
|
54
|
+
FormLayout: () => FormLayout,
|
55
|
+
FormLegend: () => FormLegend,
|
56
|
+
FormProvider: () => FormProvider,
|
57
|
+
FormStep: () => FormStep,
|
58
|
+
FormStepper: () => FormStepper,
|
59
|
+
FormValue: () => FormValue,
|
60
|
+
InputField: () => InputField,
|
61
|
+
InputRightButton: () => InputRightButton,
|
62
|
+
NativeSelect: () => NativeSelect,
|
63
|
+
NativeSelectField: () => NativeSelectField,
|
64
|
+
NextButton: () => NextButton,
|
65
|
+
NumberInputField: () => NumberInputField2,
|
66
|
+
ObjectField: () => ObjectField,
|
67
|
+
PasswordInput: () => PasswordInput,
|
68
|
+
PasswordInputField: () => PasswordInputField,
|
69
|
+
PinField: () => PinField,
|
70
|
+
PrevButton: () => PrevButton,
|
71
|
+
RadioField: () => RadioField,
|
72
|
+
RadioInput: () => RadioInput,
|
73
|
+
Select: () => Select,
|
74
|
+
SelectButton: () => SelectButton,
|
75
|
+
SelectField: () => SelectField,
|
76
|
+
SelectList: () => SelectList,
|
77
|
+
SelectOption: () => SelectOption,
|
78
|
+
StepForm: () => StepForm,
|
79
|
+
StepFormProvider: () => StepFormProvider,
|
80
|
+
SubmitButton: () => SubmitButton,
|
81
|
+
SwitchField: () => SwitchField,
|
82
|
+
TextareaField: () => TextareaField,
|
83
|
+
WatchField: () => WatchField,
|
84
|
+
appendErrors: () => import_react_hook_form9.appendErrors,
|
85
|
+
createField: () => createField,
|
86
|
+
createForm: () => createForm,
|
87
|
+
createStepForm: () => createStepForm,
|
88
|
+
defaultFieldTypes: () => defaultFieldTypes,
|
89
|
+
objectFieldResolver: () => objectFieldResolver,
|
90
|
+
useArrayField: () => useArrayField,
|
91
|
+
useArrayFieldAddButton: () => useArrayFieldAddButton,
|
92
|
+
useArrayFieldContext: () => useArrayFieldContext,
|
93
|
+
useArrayFieldRemoveButton: () => useArrayFieldRemoveButton,
|
94
|
+
useArrayFieldRow: () => useArrayFieldRow,
|
95
|
+
useArrayFieldRowContext: () => useArrayFieldRowContext,
|
96
|
+
useController: () => import_react_hook_form9.useController,
|
97
|
+
useField: () => useField,
|
98
|
+
useFieldArray: () => import_react_hook_form9.useFieldArray,
|
99
|
+
useForm: () => import_react_hook_form9.useForm,
|
100
|
+
useFormContext: () => useFormContext,
|
101
|
+
useFormState: () => import_react_hook_form9.useFormState,
|
102
|
+
useFormStep: () => useFormStep,
|
103
|
+
useStepForm: () => useStepForm,
|
104
|
+
useStepFormContext: () => useStepFormContext,
|
105
|
+
useWatch: () => import_react_hook_form9.useWatch
|
106
|
+
});
|
107
|
+
module.exports = __toCommonJS(src_exports);
|
31
108
|
|
32
109
|
// src/form-context.tsx
|
33
|
-
var
|
110
|
+
var React = __toESM(require("react"));
|
111
|
+
var import_react_hook_form = require("react-hook-form");
|
112
|
+
var import_jsx_runtime = require("react/jsx-runtime");
|
113
|
+
var FormContext = React.createContext(null);
|
34
114
|
var useFormContext = () => {
|
35
|
-
const context =
|
36
|
-
const hookContext =
|
115
|
+
const context = React.useContext(FormContext);
|
116
|
+
const hookContext = (0, import_react_hook_form.useFormContext)();
|
37
117
|
if (!context) {
|
38
118
|
throw new Error("FormProvider must be used within a Form component");
|
39
119
|
}
|
@@ -50,17 +130,21 @@ var useFieldProps = (name) => {
|
|
50
130
|
};
|
51
131
|
var FormProvider = (props) => {
|
52
132
|
const { children, fieldResolver, schema, fields, ...rest } = props;
|
53
|
-
return /* @__PURE__ */
|
133
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_react_hook_form.FormProvider, { ...rest, children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(FormContext.Provider, { value: { fieldResolver, schema, fields }, children }) });
|
54
134
|
};
|
135
|
+
|
136
|
+
// src/display-field.tsx
|
137
|
+
var import_react = require("@chakra-ui/react");
|
138
|
+
var import_jsx_runtime2 = require("react/jsx-runtime");
|
55
139
|
var DisplayField = ({
|
56
140
|
name,
|
57
141
|
label,
|
58
142
|
placeholder,
|
59
143
|
...props
|
60
144
|
}) => {
|
61
|
-
return /* @__PURE__ */
|
62
|
-
label ? /* @__PURE__ */
|
63
|
-
/* @__PURE__ */
|
145
|
+
return /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(import_react.FormControl, { ...props, children: [
|
146
|
+
label ? /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_react.FormLabel, { htmlFor: name, children: label }) : null,
|
147
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_react.Text, { fontSize: "md", children: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(FormValue, { name }) })
|
64
148
|
] });
|
65
149
|
};
|
66
150
|
DisplayField.displayName = "DisplayField";
|
@@ -69,18 +153,32 @@ var FormValue = ({ name }) => {
|
|
69
153
|
return getValues(name) || null;
|
70
154
|
};
|
71
155
|
FormValue.displayName = "FormValue";
|
72
|
-
|
156
|
+
|
157
|
+
// src/field.tsx
|
158
|
+
var React6 = __toESM(require("react"));
|
159
|
+
|
160
|
+
// src/fields-context.tsx
|
161
|
+
var import_react14 = __toESM(require("react"));
|
162
|
+
|
163
|
+
// src/default-fields.tsx
|
164
|
+
var import_react13 = require("@chakra-ui/react");
|
165
|
+
|
166
|
+
// src/number-input/number-input.tsx
|
167
|
+
var import_react2 = require("@chakra-ui/react");
|
168
|
+
var import_core = require("@saas-ui/core");
|
169
|
+
var import_jsx_runtime3 = require("react/jsx-runtime");
|
170
|
+
var NumberInput = (0, import_react2.forwardRef)((props, ref) => {
|
73
171
|
const {
|
74
172
|
hideStepper,
|
75
|
-
incrementIcon = /* @__PURE__ */
|
76
|
-
decrementIcon = /* @__PURE__ */
|
173
|
+
incrementIcon = /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(import_core.ChevronUpIcon, {}),
|
174
|
+
decrementIcon = /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(import_core.ChevronDownIcon, {}),
|
77
175
|
...rest
|
78
176
|
} = props;
|
79
|
-
return /* @__PURE__ */
|
80
|
-
/* @__PURE__ */
|
81
|
-
!hideStepper && /* @__PURE__ */
|
82
|
-
/* @__PURE__ */
|
83
|
-
/* @__PURE__ */
|
177
|
+
return /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(import_react2.NumberInput, { ...rest, ref, children: [
|
178
|
+
/* @__PURE__ */ (0, import_jsx_runtime3.jsx)(import_react2.NumberInputField, {}),
|
179
|
+
!hideStepper && /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(import_react2.NumberInputStepper, { children: [
|
180
|
+
/* @__PURE__ */ (0, import_jsx_runtime3.jsx)(import_react2.NumberIncrementStepper, { children: incrementIcon }),
|
181
|
+
/* @__PURE__ */ (0, import_jsx_runtime3.jsx)(import_react2.NumberDecrementStepper, { children: decrementIcon })
|
84
182
|
] })
|
85
183
|
] });
|
86
184
|
});
|
@@ -88,14 +186,26 @@ NumberInput.defaultProps = {
|
|
88
186
|
hideStepper: false
|
89
187
|
};
|
90
188
|
NumberInput.displayName = "NumberInput";
|
91
|
-
|
189
|
+
|
190
|
+
// src/password-input/password-input.tsx
|
191
|
+
var import_react4 = require("react");
|
192
|
+
var import_react5 = require("@chakra-ui/react");
|
193
|
+
var import_icons = require("@saas-ui/core/icons");
|
194
|
+
|
195
|
+
// src/input-right-button/input-right-button.tsx
|
196
|
+
var import_react3 = require("@chakra-ui/react");
|
197
|
+
var import_jsx_runtime4 = require("react/jsx-runtime");
|
198
|
+
var InputRightButton = (0, import_react3.forwardRef)(
|
92
199
|
(props, ref) => {
|
93
|
-
return /* @__PURE__ */
|
200
|
+
return /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(import_react3.InputRightElement, { w: "auto", px: "1", py: "1", alignItems: "stretch", children: /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(import_react3.Button, { ref, height: "auto", ...props }) });
|
94
201
|
}
|
95
202
|
);
|
96
203
|
InputRightButton.id = "InputRightElement";
|
97
204
|
InputRightButton.displayName = "InputRightButton";
|
98
|
-
|
205
|
+
|
206
|
+
// src/password-input/password-input.tsx
|
207
|
+
var import_jsx_runtime5 = require("react/jsx-runtime");
|
208
|
+
var PasswordInput = (0, import_react5.forwardRef)(
|
99
209
|
(props, ref) => {
|
100
210
|
const {
|
101
211
|
viewIcon,
|
@@ -108,24 +218,24 @@ var PasswordInput = react.forwardRef(
|
|
108
218
|
leftAddon,
|
109
219
|
...inputProps
|
110
220
|
} = props;
|
111
|
-
const [show, setShow] =
|
221
|
+
const [show, setShow] = (0, import_react4.useState)(false);
|
112
222
|
const handleClick = () => setShow(!show);
|
113
223
|
const label = show ? "Hide password" : "Show password";
|
114
224
|
let icon;
|
115
225
|
if (show) {
|
116
|
-
icon = viewIcon || /* @__PURE__ */
|
226
|
+
icon = viewIcon || /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(import_icons.ViewIcon, {});
|
117
227
|
} else {
|
118
|
-
icon = viewOffIcon || /* @__PURE__ */
|
228
|
+
icon = viewOffIcon || /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(import_icons.ViewOffIcon, {});
|
119
229
|
}
|
120
230
|
const groupProps = {
|
121
231
|
width: w || width,
|
122
232
|
size,
|
123
233
|
variant
|
124
234
|
};
|
125
|
-
return /* @__PURE__ */
|
235
|
+
return /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)(import_react5.InputGroup, { ...groupProps, children: [
|
126
236
|
leftAddon,
|
127
|
-
/* @__PURE__ */
|
128
|
-
|
237
|
+
/* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
|
238
|
+
import_react5.Input,
|
129
239
|
{
|
130
240
|
...inputProps,
|
131
241
|
ref,
|
@@ -133,7 +243,7 @@ var PasswordInput = react.forwardRef(
|
|
133
243
|
autoComplete: show ? "off" : autoComplete
|
134
244
|
}
|
135
245
|
),
|
136
|
-
/* @__PURE__ */
|
246
|
+
/* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
|
137
247
|
InputRightButton,
|
138
248
|
{
|
139
249
|
onClick: handleClick,
|
@@ -146,16 +256,22 @@ var PasswordInput = react.forwardRef(
|
|
146
256
|
}
|
147
257
|
);
|
148
258
|
PasswordInput.displayName = "PasswordInput";
|
259
|
+
|
260
|
+
// src/radio/radio-input.tsx
|
261
|
+
var import_react6 = require("@chakra-ui/react");
|
262
|
+
|
263
|
+
// src/utils.ts
|
264
|
+
var React3 = __toESM(require("react"));
|
149
265
|
var mapNestedFields = (name, children) => {
|
150
|
-
return
|
151
|
-
if (
|
266
|
+
return React3.Children.map(children, (child) => {
|
267
|
+
if (React3.isValidElement(child) && child.props.name) {
|
152
268
|
let childName = child.props.name;
|
153
269
|
if (childName.includes(".")) {
|
154
270
|
childName = childName.replace(/^.*\.(.*)/, "$1");
|
155
271
|
} else if (childName.includes(".$")) {
|
156
272
|
childName = childName.replace(/^.*\.\$(.*)/, "$1");
|
157
273
|
}
|
158
|
-
return
|
274
|
+
return React3.cloneElement(child, {
|
159
275
|
...child.props,
|
160
276
|
name: `${name}.${childName}`
|
161
277
|
});
|
@@ -174,13 +290,16 @@ var mapOptions = (options) => {
|
|
174
290
|
return option;
|
175
291
|
});
|
176
292
|
};
|
177
|
-
|
293
|
+
|
294
|
+
// src/radio/radio-input.tsx
|
295
|
+
var import_jsx_runtime6 = require("react/jsx-runtime");
|
296
|
+
var RadioInput = (0, import_react6.forwardRef)(
|
178
297
|
({ options: optionsProp, spacing, direction, ...props }, ref) => {
|
179
298
|
const { onBlur, onChange, ...groupProps } = props;
|
180
299
|
const options = mapOptions(optionsProp);
|
181
|
-
return /* @__PURE__ */
|
182
|
-
return /* @__PURE__ */
|
183
|
-
|
300
|
+
return /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(import_react6.RadioGroup, { onChange, ...groupProps, children: /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(import_react6.Stack, { spacing, direction, children: options.map(({ value, label, ...radioProps }, i) => {
|
301
|
+
return /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(
|
302
|
+
import_react6.Radio,
|
184
303
|
{
|
185
304
|
onBlur,
|
186
305
|
value,
|
@@ -194,8 +313,18 @@ var RadioInput = react.forwardRef(
|
|
194
313
|
}
|
195
314
|
);
|
196
315
|
RadioInput.displayName = "RadioInput";
|
197
|
-
|
198
|
-
|
316
|
+
|
317
|
+
// src/select/select.tsx
|
318
|
+
var import_react9 = require("@chakra-ui/react");
|
319
|
+
var import_utils3 = require("@chakra-ui/utils");
|
320
|
+
var import_core2 = require("@saas-ui/core");
|
321
|
+
|
322
|
+
// src/select/select-context.tsx
|
323
|
+
var import_react7 = require("@chakra-ui/react");
|
324
|
+
var import_react_utils = require("@chakra-ui/react-utils");
|
325
|
+
var import_react8 = __toESM(require("react"));
|
326
|
+
var [SelectStylesProvider, useSelectStyles] = (0, import_react7.createStylesContext)("SuiSelect");
|
327
|
+
var [SelectProvider, useSelectContext] = (0, import_react_utils.createContext)({
|
199
328
|
strict: true
|
200
329
|
});
|
201
330
|
var useSelect = (props) => {
|
@@ -210,20 +339,20 @@ var useSelect = (props) => {
|
|
210
339
|
isDisabled,
|
211
340
|
renderValue = (value2) => typeof value2 === "string" ? value2 : value2 == null ? void 0 : value2.join(", ")
|
212
341
|
} = props;
|
213
|
-
const [currentValue, setCurrentValue] =
|
342
|
+
const [currentValue, setCurrentValue] = (0, import_react7.useControllableState)({
|
214
343
|
value,
|
215
344
|
defaultValue,
|
216
345
|
onChange
|
217
346
|
});
|
218
|
-
const controlProps =
|
219
|
-
const options =
|
347
|
+
const controlProps = (0, import_react7.useFormControl)({ name });
|
348
|
+
const options = import_react8.default.useMemo(
|
220
349
|
() => optionsProp && mapOptions(optionsProp),
|
221
350
|
[optionsProp]
|
222
351
|
);
|
223
352
|
const handleChange = (value2) => {
|
224
353
|
setCurrentValue(value2);
|
225
354
|
};
|
226
|
-
const getDisplayValue =
|
355
|
+
const getDisplayValue = import_react8.default.useCallback(
|
227
356
|
(value2) => {
|
228
357
|
if (!options) {
|
229
358
|
return value2;
|
@@ -237,7 +366,7 @@ var useSelect = (props) => {
|
|
237
366
|
},
|
238
367
|
[options]
|
239
368
|
);
|
240
|
-
const displayValue =
|
369
|
+
const displayValue = import_react8.default.useMemo(
|
241
370
|
() => currentValue ? (Array.isArray(currentValue) ? currentValue : [currentValue]).map(
|
242
371
|
getDisplayValue
|
243
372
|
) : [],
|
@@ -256,7 +385,10 @@ var useSelect = (props) => {
|
|
256
385
|
isDisabled
|
257
386
|
};
|
258
387
|
};
|
259
|
-
|
388
|
+
|
389
|
+
// src/select/select.tsx
|
390
|
+
var import_jsx_runtime7 = require("react/jsx-runtime");
|
391
|
+
var SelectButton = (0, import_react9.forwardRef)(
|
260
392
|
(props, ref) => {
|
261
393
|
var _a, _b, _c, _d, _e;
|
262
394
|
const {
|
@@ -265,7 +397,7 @@ var SelectButton = react.forwardRef(
|
|
265
397
|
placeholder,
|
266
398
|
isDisabled: isSelectDisabled
|
267
399
|
} = useSelectContext();
|
268
|
-
const context =
|
400
|
+
const context = (0, import_react9.useFormControlContext)();
|
269
401
|
const styles = useSelectStyles();
|
270
402
|
const {
|
271
403
|
isInvalid,
|
@@ -277,7 +409,7 @@ var SelectButton = react.forwardRef(
|
|
277
409
|
onBlur,
|
278
410
|
onFocus
|
279
411
|
} = context || {};
|
280
|
-
const { rightIcon = /* @__PURE__ */
|
412
|
+
const { rightIcon = /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(import_core2.ChevronDownIcon, {}), ...rest } = props;
|
281
413
|
const focusStyles = (_a = styles.field) == null ? void 0 : _a._focusVisible;
|
282
414
|
const readOnlyStyles = (_b = styles.field) == null ? void 0 : _b._readOnly;
|
283
415
|
const invalid = (_c = styles.field) == null ? void 0 : _c._invalid;
|
@@ -298,9 +430,9 @@ var SelectButton = react.forwardRef(
|
|
298
430
|
...styles.field,
|
299
431
|
h: "auto"
|
300
432
|
};
|
301
|
-
const buttonProps =
|
302
|
-
return /* @__PURE__ */
|
303
|
-
|
433
|
+
const buttonProps = (0, import_react9.useMenuButton)(rest, ref);
|
434
|
+
return /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(
|
435
|
+
import_react9.Button,
|
304
436
|
{
|
305
437
|
...buttonProps,
|
306
438
|
...buttonStyles,
|
@@ -309,13 +441,13 @@ var SelectButton = react.forwardRef(
|
|
309
441
|
onFocus,
|
310
442
|
onBlur,
|
311
443
|
isDisabled: isDisabled || isSelectDisabled,
|
312
|
-
"data-invalid":
|
313
|
-
"data-read-only":
|
314
|
-
"data-focus":
|
315
|
-
"data-required":
|
444
|
+
"data-invalid": (0, import_utils3.dataAttr)(isInvalid),
|
445
|
+
"data-read-only": (0, import_utils3.dataAttr)(isReadOnly),
|
446
|
+
"data-focus": (0, import_utils3.dataAttr)(isFocused),
|
447
|
+
"data-required": (0, import_utils3.dataAttr)(isRequired),
|
316
448
|
rightIcon,
|
317
|
-
children: /* @__PURE__ */
|
318
|
-
|
449
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(
|
450
|
+
import_react9.chakra.span,
|
319
451
|
{
|
320
452
|
__css: {
|
321
453
|
display: "block",
|
@@ -333,16 +465,16 @@ var SelectButton = react.forwardRef(
|
|
333
465
|
}
|
334
466
|
);
|
335
467
|
SelectButton.displayName = "SelectButton";
|
336
|
-
var Select =
|
468
|
+
var Select = (0, import_react9.forwardRef)((props, ref) => {
|
337
469
|
const { name, children, isDisabled, multiple, ...rest } = props;
|
338
|
-
const styles =
|
339
|
-
const menuProps =
|
470
|
+
const styles = (0, import_react9.useMultiStyleConfig)("SuiSelect", props);
|
471
|
+
const menuProps = (0, import_react9.omitThemingProps)(rest);
|
340
472
|
const context = useSelect(props);
|
341
473
|
const { value, controlProps } = context;
|
342
|
-
return /* @__PURE__ */
|
474
|
+
return /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(SelectProvider, { value: context, children: /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(SelectStylesProvider, { value: styles, children: /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(import_react9.Menu, { ...menuProps, closeOnSelect: !multiple, children: /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)(import_react9.chakra.div, { className: (0, import_utils3.cx)("sui-select"), children: [
|
343
475
|
children,
|
344
|
-
/* @__PURE__ */
|
345
|
-
|
476
|
+
/* @__PURE__ */ (0, import_jsx_runtime7.jsx)(
|
477
|
+
import_react9.chakra.input,
|
346
478
|
{
|
347
479
|
...controlProps,
|
348
480
|
ref,
|
@@ -356,52 +488,69 @@ var Select = react.forwardRef((props, ref) => {
|
|
356
488
|
});
|
357
489
|
var SelectList = (props) => {
|
358
490
|
const { defaultValue, value, options, multiple, onChange } = useSelectContext();
|
359
|
-
return /* @__PURE__ */
|
360
|
-
|
491
|
+
return /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(import_react9.MenuList, { maxH: "100vh", overflowY: "auto", ...props, children: /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(
|
492
|
+
import_react9.MenuOptionGroup,
|
361
493
|
{
|
362
494
|
defaultValue: defaultValue || value,
|
363
495
|
value,
|
364
496
|
onChange,
|
365
497
|
type: multiple ? "checkbox" : "radio",
|
366
|
-
children: options ? options.map(({ value: value2, label, ...rest }, i) => /* @__PURE__ */
|
498
|
+
children: options ? options.map(({ value: value2, label, ...rest }, i) => /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(SelectOption, { value: value2, ...rest, children: label || value2 }, i)) : props.children
|
367
499
|
}
|
368
500
|
) });
|
369
501
|
};
|
370
502
|
Select.displayName = "Select";
|
371
|
-
var SelectOption =
|
503
|
+
var SelectOption = (0, import_react9.forwardRef)(
|
372
504
|
(props, ref) => {
|
373
|
-
return /* @__PURE__ */
|
505
|
+
return /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(import_react9.MenuItemOption, { ref, ...props });
|
374
506
|
}
|
375
507
|
);
|
376
508
|
SelectOption.id = "MenuItemOption";
|
377
509
|
SelectOption.displayName = "SelectOption";
|
378
|
-
|
510
|
+
|
511
|
+
// src/select/native-select.tsx
|
512
|
+
var import_react10 = require("@chakra-ui/react");
|
513
|
+
var import_jsx_runtime8 = require("react/jsx-runtime");
|
514
|
+
var NativeSelect = (0, import_react10.forwardRef)(
|
379
515
|
({ options, children, ...props }, ref) => {
|
380
|
-
return /* @__PURE__ */
|
381
|
-
return /* @__PURE__ */
|
516
|
+
return /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(import_react10.Select, { ref, ...props, children: children || (options == null ? void 0 : options.map(({ value, label }) => {
|
517
|
+
return /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("option", { value, children: label || value }, value);
|
382
518
|
})) });
|
383
519
|
}
|
384
520
|
);
|
385
521
|
NativeSelect.displayName = "NativeSelect";
|
522
|
+
|
523
|
+
// src/create-field.tsx
|
524
|
+
var import_react_hook_form3 = require("react-hook-form");
|
525
|
+
var import_react12 = require("@chakra-ui/react");
|
526
|
+
var import_utils4 = require("@chakra-ui/utils");
|
527
|
+
|
528
|
+
// src/base-field.tsx
|
529
|
+
var import_react_hook_form2 = require("react-hook-form");
|
530
|
+
var import_react11 = require("@chakra-ui/react");
|
531
|
+
var import_jsx_runtime9 = require("react/jsx-runtime");
|
386
532
|
var getError = (name, formState) => {
|
387
|
-
return
|
533
|
+
return (0, import_react_hook_form2.get)(formState.errors, name);
|
388
534
|
};
|
389
535
|
var BaseField = (props) => {
|
390
536
|
const { name, label, help, hideLabel, children, ...controlProps } = props;
|
391
537
|
const { formState } = useFormContext();
|
392
538
|
const error = getError(name, formState);
|
393
|
-
return /* @__PURE__ */
|
394
|
-
label && !hideLabel ? /* @__PURE__ */
|
395
|
-
/* @__PURE__ */
|
539
|
+
return /* @__PURE__ */ (0, import_jsx_runtime9.jsxs)(import_react11.FormControl, { ...controlProps, isInvalid: !!error, children: [
|
540
|
+
label && !hideLabel ? /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(import_react11.FormLabel, { children: label }) : null,
|
541
|
+
/* @__PURE__ */ (0, import_jsx_runtime9.jsxs)(import_react11.Box, { children: [
|
396
542
|
children,
|
397
|
-
help && !(error == null ? void 0 : error.message) ? /* @__PURE__ */
|
398
|
-
(error == null ? void 0 : error.message) && /* @__PURE__ */
|
543
|
+
help && !(error == null ? void 0 : error.message) ? /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(import_react11.FormHelperText, { children: help }) : null,
|
544
|
+
(error == null ? void 0 : error.message) && /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(import_react11.FormErrorMessage, { children: error == null ? void 0 : error.message })
|
399
545
|
] })
|
400
546
|
] });
|
401
547
|
};
|
402
548
|
BaseField.displayName = "BaseField";
|
549
|
+
|
550
|
+
// src/create-field.tsx
|
551
|
+
var import_jsx_runtime10 = require("react/jsx-runtime");
|
403
552
|
var _createField = (InputComponent, { displayName, hideLabel, BaseField: BaseField2 }) => {
|
404
|
-
const Field2 =
|
553
|
+
const Field2 = (0, import_react12.forwardRef)((props, ref) => {
|
405
554
|
const {
|
406
555
|
id,
|
407
556
|
name,
|
@@ -418,7 +567,7 @@ var _createField = (InputComponent, { displayName, hideLabel, BaseField: BaseFie
|
|
418
567
|
required: isRequired,
|
419
568
|
...rules
|
420
569
|
};
|
421
|
-
return /* @__PURE__ */
|
570
|
+
return /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(
|
422
571
|
BaseField2,
|
423
572
|
{
|
424
573
|
id,
|
@@ -430,7 +579,7 @@ var _createField = (InputComponent, { displayName, hideLabel, BaseField: BaseFie
|
|
430
579
|
isInvalid,
|
431
580
|
isReadOnly,
|
432
581
|
isRequired,
|
433
|
-
children: /* @__PURE__ */
|
582
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(
|
434
583
|
InputComponent,
|
435
584
|
{
|
436
585
|
ref,
|
@@ -448,23 +597,23 @@ var _createField = (InputComponent, { displayName, hideLabel, BaseField: BaseFie
|
|
448
597
|
return Field2;
|
449
598
|
};
|
450
599
|
var withControlledInput = (InputComponent) => {
|
451
|
-
return
|
600
|
+
return (0, import_react12.forwardRef)(
|
452
601
|
({ name, rules, ...inputProps }, ref) => {
|
453
602
|
const { control } = useFormContext();
|
454
|
-
return /* @__PURE__ */
|
455
|
-
|
603
|
+
return /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(
|
604
|
+
import_react_hook_form3.Controller,
|
456
605
|
{
|
457
606
|
name,
|
458
607
|
control,
|
459
608
|
rules,
|
460
|
-
render: ({ field: { ref: _ref, ...field } }) => /* @__PURE__ */
|
609
|
+
render: ({ field: { ref: _ref, ...field } }) => /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(
|
461
610
|
InputComponent,
|
462
611
|
{
|
463
612
|
...field,
|
464
613
|
...inputProps,
|
465
|
-
onChange:
|
466
|
-
onBlur:
|
467
|
-
ref:
|
614
|
+
onChange: (0, import_utils4.callAllHandlers)(inputProps.onChange, field.onChange),
|
615
|
+
onBlur: (0, import_utils4.callAllHandlers)(inputProps.onBlur, field.onBlur),
|
616
|
+
ref: (0, import_react12.useMergeRefs)(ref, _ref)
|
468
617
|
}
|
469
618
|
)
|
470
619
|
}
|
@@ -473,18 +622,18 @@ var withControlledInput = (InputComponent) => {
|
|
473
622
|
);
|
474
623
|
};
|
475
624
|
var withUncontrolledInput = (InputComponent) => {
|
476
|
-
return
|
625
|
+
return (0, import_react12.forwardRef)(
|
477
626
|
({ name, rules, ...inputProps }, ref) => {
|
478
627
|
const { register } = useFormContext();
|
479
628
|
const { ref: _ref, ...field } = register(name, rules);
|
480
|
-
return /* @__PURE__ */
|
629
|
+
return /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(
|
481
630
|
InputComponent,
|
482
631
|
{
|
483
632
|
...field,
|
484
633
|
...inputProps,
|
485
|
-
onChange:
|
486
|
-
onBlur:
|
487
|
-
ref:
|
634
|
+
onChange: (0, import_utils4.callAllHandlers)(inputProps.onChange, field.onChange),
|
635
|
+
onBlur: (0, import_utils4.callAllHandlers)(inputProps.onBlur, field.onBlur),
|
636
|
+
ref: (0, import_react12.useMergeRefs)(ref, _ref)
|
488
637
|
}
|
489
638
|
);
|
490
639
|
}
|
@@ -505,11 +654,14 @@ var createField = (component, options) => {
|
|
505
654
|
});
|
506
655
|
return Field2;
|
507
656
|
};
|
657
|
+
|
658
|
+
// src/default-fields.tsx
|
659
|
+
var import_jsx_runtime11 = require("react/jsx-runtime");
|
508
660
|
var InputField = createField(
|
509
|
-
|
510
|
-
const input = /* @__PURE__ */
|
661
|
+
(0, import_react13.forwardRef)(({ type = "text", leftAddon, rightAddon, size, ...rest }, ref) => {
|
662
|
+
const input = /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(import_react13.Input, { type, size, ...rest, ref });
|
511
663
|
if (leftAddon || rightAddon) {
|
512
|
-
return /* @__PURE__ */
|
664
|
+
return /* @__PURE__ */ (0, import_jsx_runtime11.jsxs)(import_react13.InputGroup, { size, children: [
|
513
665
|
leftAddon,
|
514
666
|
input,
|
515
667
|
rightAddon
|
@@ -525,22 +677,22 @@ var NumberInputField2 = createField(
|
|
525
677
|
}
|
526
678
|
);
|
527
679
|
var PasswordInputField = createField(
|
528
|
-
|
680
|
+
(0, import_react13.forwardRef)((props, ref) => /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(PasswordInput, { ref, ...props }))
|
529
681
|
);
|
530
|
-
var TextareaField = createField(
|
682
|
+
var TextareaField = createField(import_react13.Textarea);
|
531
683
|
var SwitchField = createField(
|
532
|
-
|
533
|
-
return /* @__PURE__ */
|
684
|
+
(0, import_react13.forwardRef)(({ type, value, ...rest }, ref) => {
|
685
|
+
return /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(import_react13.Switch, { isChecked: !!value, ...rest, ref });
|
534
686
|
}),
|
535
687
|
{
|
536
688
|
isControlled: true
|
537
689
|
}
|
538
690
|
);
|
539
691
|
var SelectField = createField(
|
540
|
-
|
541
|
-
return /* @__PURE__ */
|
542
|
-
/* @__PURE__ */
|
543
|
-
/* @__PURE__ */
|
692
|
+
(0, import_react13.forwardRef)((props, ref) => {
|
693
|
+
return /* @__PURE__ */ (0, import_jsx_runtime11.jsxs)(Select, { ref, ...props, children: [
|
694
|
+
/* @__PURE__ */ (0, import_jsx_runtime11.jsx)(SelectButton, {}),
|
695
|
+
/* @__PURE__ */ (0, import_jsx_runtime11.jsx)(SelectList, {})
|
544
696
|
] });
|
545
697
|
}),
|
546
698
|
{
|
@@ -548,8 +700,8 @@ var SelectField = createField(
|
|
548
700
|
}
|
549
701
|
);
|
550
702
|
var CheckboxField = createField(
|
551
|
-
|
552
|
-
return /* @__PURE__ */
|
703
|
+
(0, import_react13.forwardRef)(({ label, type, ...props }, ref) => {
|
704
|
+
return /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(import_react13.Checkbox, { ref, ...props, children: label });
|
553
705
|
}),
|
554
706
|
{
|
555
707
|
hideLabel: true
|
@@ -562,13 +714,13 @@ var NativeSelectField = createField(NativeSelect, {
|
|
562
714
|
isControlled: true
|
563
715
|
});
|
564
716
|
var PinField = createField(
|
565
|
-
|
717
|
+
(0, import_react13.forwardRef)((props, ref) => {
|
566
718
|
const { pinLength = 4, pinType, spacing, ...inputProps } = props;
|
567
719
|
const inputs = [];
|
568
720
|
for (let i = 0; i < pinLength; i++) {
|
569
|
-
inputs.push(/* @__PURE__ */
|
721
|
+
inputs.push(/* @__PURE__ */ (0, import_jsx_runtime11.jsx)(import_react13.PinInputField, { ref }, i));
|
570
722
|
}
|
571
|
-
return /* @__PURE__ */
|
723
|
+
return /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(import_react13.HStack, { spacing, children: /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(import_react13.PinInput, { ...inputProps, type: pinType, children: inputs }) });
|
572
724
|
}),
|
573
725
|
{
|
574
726
|
isControlled: true
|
@@ -589,33 +741,48 @@ var defaultFieldTypes = {
|
|
589
741
|
pin: PinField,
|
590
742
|
"native-select": NativeSelectField
|
591
743
|
};
|
592
|
-
|
744
|
+
|
745
|
+
// src/fields-context.tsx
|
746
|
+
var import_jsx_runtime12 = require("react/jsx-runtime");
|
747
|
+
var FieldsContext = import_react14.default.createContext(
|
593
748
|
null
|
594
749
|
);
|
595
750
|
var FieldsProvider = (props) => {
|
596
751
|
const fields = { ...defaultFieldTypes, ...props.value };
|
597
|
-
return /* @__PURE__ */
|
752
|
+
return /* @__PURE__ */ (0, import_jsx_runtime12.jsx)(FieldsContext.Provider, { value: fields, children: props.children });
|
598
753
|
};
|
599
754
|
var useField = (type) => {
|
600
|
-
const context =
|
755
|
+
const context = import_react14.default.useContext(FieldsContext);
|
601
756
|
return (context == null ? void 0 : context[type]) || InputField;
|
602
757
|
};
|
758
|
+
|
759
|
+
// src/field.tsx
|
760
|
+
var import_jsx_runtime13 = require("react/jsx-runtime");
|
603
761
|
var defaultInputType = "text";
|
604
|
-
var Field =
|
762
|
+
var Field = React6.forwardRef(
|
605
763
|
(props, ref) => {
|
606
764
|
const { type = defaultInputType, name } = props;
|
607
765
|
const overrides = useFieldProps(name);
|
608
766
|
const InputComponent = useField((overrides == null ? void 0 : overrides.type) || type);
|
609
|
-
return /* @__PURE__ */
|
767
|
+
return /* @__PURE__ */ (0, import_jsx_runtime13.jsx)(InputComponent, { ref, ...props, ...overrides });
|
610
768
|
}
|
611
769
|
);
|
770
|
+
|
771
|
+
// src/fields.tsx
|
772
|
+
var React10 = __toESM(require("react"));
|
773
|
+
|
774
|
+
// src/layout.tsx
|
775
|
+
var React7 = __toESM(require("react"));
|
776
|
+
var import_react15 = require("@chakra-ui/react");
|
777
|
+
var import_utils5 = require("@chakra-ui/utils");
|
778
|
+
var import_jsx_runtime14 = require("react/jsx-runtime");
|
612
779
|
var FormLayoutItem = ({ children }) => {
|
613
|
-
return /* @__PURE__ */
|
780
|
+
return /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(import_react15.chakra.div, { children });
|
614
781
|
};
|
615
782
|
FormLayoutItem.displayName = "FormLayoutItem";
|
616
783
|
var FormLayout = ({ children, ...props }) => {
|
617
784
|
var _a, _b, _c;
|
618
|
-
const theme =
|
785
|
+
const theme = (0, import_react15.useTheme)();
|
619
786
|
const defaultProps = (_c = (_b = (_a = theme.components) == null ? void 0 : _a.SuiFormLayout) == null ? void 0 : _b.defaultProps) != null ? _c : {
|
620
787
|
spacing: 4
|
621
788
|
};
|
@@ -623,14 +790,14 @@ var FormLayout = ({ children, ...props }) => {
|
|
623
790
|
...defaultProps,
|
624
791
|
...props
|
625
792
|
};
|
626
|
-
return /* @__PURE__ */
|
627
|
-
|
793
|
+
return /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(
|
794
|
+
import_react15.SimpleGrid,
|
628
795
|
{
|
629
796
|
...gridProps,
|
630
|
-
className:
|
631
|
-
children:
|
632
|
-
if (
|
633
|
-
return /* @__PURE__ */
|
797
|
+
className: (0, import_utils5.cx)("sui-form__layout", props.className),
|
798
|
+
children: React7.Children.map(children, (child) => {
|
799
|
+
if (React7.isValidElement(child)) {
|
800
|
+
return /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(FormLayoutItem, { children: child });
|
634
801
|
}
|
635
802
|
return child;
|
636
803
|
})
|
@@ -638,10 +805,20 @@ var FormLayout = ({ children, ...props }) => {
|
|
638
805
|
);
|
639
806
|
};
|
640
807
|
FormLayout.displayName = "FormLayout";
|
641
|
-
|
808
|
+
|
809
|
+
// src/array-field.tsx
|
810
|
+
var React9 = __toESM(require("react"));
|
811
|
+
var import_react16 = require("@chakra-ui/react");
|
812
|
+
var import_icons2 = require("@saas-ui/core/icons");
|
813
|
+
|
814
|
+
// src/use-array-field.tsx
|
815
|
+
var React8 = __toESM(require("react"));
|
816
|
+
var import_react_hook_form4 = require("react-hook-form");
|
817
|
+
var import_react_utils2 = require("@chakra-ui/react-utils");
|
818
|
+
var [ArrayFieldProvider, useArrayFieldContext] = (0, import_react_utils2.createContext)({
|
642
819
|
name: "ArrayFieldContext"
|
643
820
|
});
|
644
|
-
var [ArrayFieldRowProvider, useArrayFieldRowContext] =
|
821
|
+
var [ArrayFieldRowProvider, useArrayFieldRowContext] = (0, import_react_utils2.createContext)({
|
645
822
|
name: "ArrayFieldRowContext"
|
646
823
|
});
|
647
824
|
var useArrayField = ({
|
@@ -652,7 +829,7 @@ var useArrayField = ({
|
|
652
829
|
max
|
653
830
|
}) => {
|
654
831
|
const { control } = useFormContext();
|
655
|
-
const context =
|
832
|
+
const context = (0, import_react_hook_form4.useFieldArray)({
|
656
833
|
control,
|
657
834
|
name,
|
658
835
|
keyName
|
@@ -668,7 +845,7 @@ var useArrayField = ({
|
|
668
845
|
var useArrayFieldRow = ({ index }) => {
|
669
846
|
const { clearErrors } = useFormContext();
|
670
847
|
const { name, remove, fields } = useArrayFieldContext();
|
671
|
-
|
848
|
+
React8.useEffect(() => {
|
672
849
|
clearErrors(name);
|
673
850
|
}, []);
|
674
851
|
return {
|
@@ -676,7 +853,7 @@ var useArrayFieldRow = ({ index }) => {
|
|
676
853
|
isFirst: index === 0,
|
677
854
|
isLast: index === fields.length - 1,
|
678
855
|
name: `${name}.${index}`,
|
679
|
-
remove:
|
856
|
+
remove: React8.useCallback(() => {
|
680
857
|
clearErrors(name);
|
681
858
|
remove(index);
|
682
859
|
}, [index])
|
@@ -701,14 +878,18 @@ var useArrayFieldAddButton = () => {
|
|
701
878
|
isDisabled
|
702
879
|
};
|
703
880
|
};
|
881
|
+
|
882
|
+
// src/array-field.tsx
|
883
|
+
var import_utils7 = require("@chakra-ui/utils");
|
884
|
+
var import_jsx_runtime15 = require("react/jsx-runtime");
|
704
885
|
var ArrayFieldRow = ({
|
705
886
|
children,
|
706
887
|
index,
|
707
888
|
...rowFieldsProps
|
708
889
|
}) => {
|
709
|
-
return /* @__PURE__ */
|
710
|
-
/* @__PURE__ */
|
711
|
-
/* @__PURE__ */
|
890
|
+
return /* @__PURE__ */ (0, import_jsx_runtime15.jsxs)(ArrayFieldRowContainer, { index, children: [
|
891
|
+
/* @__PURE__ */ (0, import_jsx_runtime15.jsx)(ArrayFieldRowFields, { ...rowFieldsProps, children }),
|
892
|
+
/* @__PURE__ */ (0, import_jsx_runtime15.jsx)(ArrayFieldRemoveButton, {})
|
712
893
|
] });
|
713
894
|
};
|
714
895
|
ArrayFieldRow.displayName = "ArrayFieldRow";
|
@@ -717,7 +898,7 @@ var ArrayFieldRowFields = ({
|
|
717
898
|
...layoutProps
|
718
899
|
}) => {
|
719
900
|
const { name } = useArrayFieldRowContext();
|
720
|
-
return /* @__PURE__ */
|
901
|
+
return /* @__PURE__ */ (0, import_jsx_runtime15.jsx)(FormLayout, { flex: "1", mr: "2", ...layoutProps, children: mapNestedFields(name, children) });
|
721
902
|
};
|
722
903
|
ArrayFieldRowFields.displayName = "ArrayFieldRowFields";
|
723
904
|
var ArrayFieldRowContainer = ({
|
@@ -733,33 +914,33 @@ var ArrayFieldRowContainer = ({
|
|
733
914
|
width: "100%",
|
734
915
|
mb: 4
|
735
916
|
};
|
736
|
-
return /* @__PURE__ */
|
917
|
+
return /* @__PURE__ */ (0, import_jsx_runtime15.jsx)(ArrayFieldRowProvider, { value: context, children: /* @__PURE__ */ (0, import_jsx_runtime15.jsx)(import_react16.chakra.div, { ...rest, __css: styles, children }) });
|
737
918
|
};
|
738
919
|
ArrayFieldRowContainer.displayName = "ArrayFieldRowContainer";
|
739
920
|
var ArrayFieldRemoveButton = (props) => {
|
740
|
-
return /* @__PURE__ */
|
921
|
+
return /* @__PURE__ */ (0, import_jsx_runtime15.jsx)(import_react16.Button, { "aria-label": "Remove row", ...useArrayFieldRemoveButton(), ...props, children: props.children || /* @__PURE__ */ (0, import_jsx_runtime15.jsx)(import_icons2.MinusIcon, {}) });
|
741
922
|
};
|
742
923
|
ArrayFieldRemoveButton.displayName = "ArrayFieldRemoveButton";
|
743
924
|
var ArrayFieldAddButton = (props) => {
|
744
|
-
return /* @__PURE__ */
|
745
|
-
|
925
|
+
return /* @__PURE__ */ (0, import_jsx_runtime15.jsx)(
|
926
|
+
import_react16.Button,
|
746
927
|
{
|
747
928
|
"aria-label": "Add row",
|
748
929
|
float: "right",
|
749
930
|
...useArrayFieldAddButton(),
|
750
931
|
...props,
|
751
|
-
children: props.children || /* @__PURE__ */
|
932
|
+
children: props.children || /* @__PURE__ */ (0, import_jsx_runtime15.jsx)(import_icons2.PlusIcon, {})
|
752
933
|
}
|
753
934
|
);
|
754
935
|
};
|
755
936
|
ArrayFieldAddButton.displayName = "ArrayFieldAddButton";
|
756
|
-
var ArrayField =
|
937
|
+
var ArrayField = (0, import_react16.forwardRef)(
|
757
938
|
(props, ref) => {
|
758
939
|
const { children, ...containerProps } = props;
|
759
|
-
const rowFn =
|
760
|
-
return /* @__PURE__ */
|
761
|
-
/* @__PURE__ */
|
762
|
-
/* @__PURE__ */
|
940
|
+
const rowFn = (0, import_utils7.isFunction)(children) ? children : (fields) => /* @__PURE__ */ (0, import_jsx_runtime15.jsx)(import_jsx_runtime15.Fragment, { children: fields.map(({ id }, index) => /* @__PURE__ */ (0, import_jsx_runtime15.jsx)(ArrayFieldRow, { index, children }, id)) || null });
|
941
|
+
return /* @__PURE__ */ (0, import_jsx_runtime15.jsxs)(ArrayFieldContainer, { ref, ...containerProps, children: [
|
942
|
+
/* @__PURE__ */ (0, import_jsx_runtime15.jsx)(ArrayFieldRows, { children: rowFn }),
|
943
|
+
/* @__PURE__ */ (0, import_jsx_runtime15.jsx)(ArrayFieldAddButton, {})
|
763
944
|
] });
|
764
945
|
}
|
765
946
|
);
|
@@ -771,7 +952,7 @@ var ArrayFieldRows = ({
|
|
771
952
|
return children(fields);
|
772
953
|
};
|
773
954
|
ArrayFieldRows.displayName = "ArrayFieldRows";
|
774
|
-
var ArrayFieldContainer =
|
955
|
+
var ArrayFieldContainer = React9.forwardRef(
|
775
956
|
({
|
776
957
|
name,
|
777
958
|
defaultValue,
|
@@ -789,14 +970,18 @@ var ArrayFieldContainer = React11__namespace.forwardRef(
|
|
789
970
|
min: min || (overrides == null ? void 0 : overrides.min),
|
790
971
|
max: max || (overrides == null ? void 0 : overrides.max)
|
791
972
|
});
|
792
|
-
|
793
|
-
return /* @__PURE__ */
|
973
|
+
React9.useImperativeHandle(ref, () => context, [ref, context]);
|
974
|
+
return /* @__PURE__ */ (0, import_jsx_runtime15.jsx)(ArrayFieldProvider, { value: context, children: /* @__PURE__ */ (0, import_jsx_runtime15.jsx)(BaseField, { name, ...fieldProps, ...overrides, children }) });
|
794
975
|
}
|
795
976
|
);
|
796
977
|
ArrayFieldContainer.displayName = "ArrayFieldContainer";
|
978
|
+
|
979
|
+
// src/object-field.tsx
|
980
|
+
var import_react17 = require("@chakra-ui/react");
|
981
|
+
var import_jsx_runtime16 = require("react/jsx-runtime");
|
797
982
|
var FormLegend = (props) => {
|
798
|
-
const styles =
|
799
|
-
return /* @__PURE__ */
|
983
|
+
const styles = (0, import_react17.useStyleConfig)("SuiFormLegend");
|
984
|
+
return /* @__PURE__ */ (0, import_jsx_runtime16.jsx)(import_react17.FormLabel, { as: "legend", sx: styles, ...props });
|
800
985
|
};
|
801
986
|
var ObjectField = (props) => {
|
802
987
|
const {
|
@@ -811,9 +996,9 @@ var ObjectField = (props) => {
|
|
811
996
|
const { hideLabel, columns, spacing, ...overrides } = useFieldProps(
|
812
997
|
name
|
813
998
|
);
|
814
|
-
return /* @__PURE__ */
|
815
|
-
/* @__PURE__ */
|
816
|
-
/* @__PURE__ */
|
999
|
+
return /* @__PURE__ */ (0, import_jsx_runtime16.jsxs)(import_react17.FormControl, { name, as: "fieldset", ...fieldProps, ...overrides, children: [
|
1000
|
+
/* @__PURE__ */ (0, import_jsx_runtime16.jsx)(FormLegend, { display: hideLabelProp || hideLabel ? "none" : "block", children: label }),
|
1001
|
+
/* @__PURE__ */ (0, import_jsx_runtime16.jsx)(
|
817
1002
|
FormLayout,
|
818
1003
|
{
|
819
1004
|
columns: columnsProp || columns,
|
@@ -824,10 +1009,13 @@ var ObjectField = (props) => {
|
|
824
1009
|
] });
|
825
1010
|
};
|
826
1011
|
ObjectField.displayName = "ObjectField";
|
1012
|
+
|
1013
|
+
// src/fields.tsx
|
1014
|
+
var import_jsx_runtime17 = require("react/jsx-runtime");
|
827
1015
|
var mapNestedFields2 = (resolver, name) => {
|
828
1016
|
var _a;
|
829
1017
|
return (_a = resolver.getNestedFields(name)) == null ? void 0 : _a.map(
|
830
|
-
({ name: name2, type, ...nestedFieldProps }, i) => /* @__PURE__ */
|
1018
|
+
({ name: name2, type, ...nestedFieldProps }, i) => /* @__PURE__ */ (0, import_jsx_runtime17.jsx)(
|
831
1019
|
Field,
|
832
1020
|
{
|
833
1021
|
name: name2,
|
@@ -847,10 +1035,10 @@ var AutoFields = ({
|
|
847
1035
|
const context = useFormContext();
|
848
1036
|
const schema = schemaProp || context.schema;
|
849
1037
|
const fieldResolver = fieldResolverProp || context.fieldResolver;
|
850
|
-
const resolver =
|
851
|
-
const fields =
|
1038
|
+
const resolver = React10.useMemo(() => fieldResolver, [schema, fieldResolver]);
|
1039
|
+
const fields = React10.useMemo(() => resolver == null ? void 0 : resolver.getFields(), [resolver]);
|
852
1040
|
const form = useFormContext();
|
853
|
-
|
1041
|
+
React10.useEffect(() => {
|
854
1042
|
var _a;
|
855
1043
|
if (focusFirstField && ((_a = fields == null ? void 0 : fields[0]) == null ? void 0 : _a.name)) {
|
856
1044
|
form.setFocus(fields[0].name);
|
@@ -859,7 +1047,7 @@ var AutoFields = ({
|
|
859
1047
|
if (!resolver) {
|
860
1048
|
return null;
|
861
1049
|
}
|
862
|
-
return /* @__PURE__ */
|
1050
|
+
return /* @__PURE__ */ (0, import_jsx_runtime17.jsx)(FormLayout, { ...props, children: fields == null ? void 0 : fields.map(
|
863
1051
|
({
|
864
1052
|
name,
|
865
1053
|
type,
|
@@ -867,16 +1055,21 @@ var AutoFields = ({
|
|
867
1055
|
...fieldProps
|
868
1056
|
}) => {
|
869
1057
|
if (type === "array") {
|
870
|
-
return /* @__PURE__ */
|
1058
|
+
return /* @__PURE__ */ (0, import_jsx_runtime17.jsx)(ArrayField, { name, ...fieldProps, children: mapNestedFields2(resolver, name) }, name);
|
871
1059
|
} else if (type === "object") {
|
872
|
-
return /* @__PURE__ */
|
1060
|
+
return /* @__PURE__ */ (0, import_jsx_runtime17.jsx)(ObjectField, { name, ...fieldProps, children: mapNestedFields2(resolver, name) }, name);
|
873
1061
|
}
|
874
|
-
return /* @__PURE__ */
|
1062
|
+
return /* @__PURE__ */ (0, import_jsx_runtime17.jsx)(Field, { name, type, ...fieldProps }, name);
|
875
1063
|
}
|
876
1064
|
) });
|
877
1065
|
};
|
878
1066
|
AutoFields.displayName = "Fields";
|
879
|
-
|
1067
|
+
|
1068
|
+
// src/submit-button.tsx
|
1069
|
+
var import_react_hook_form5 = require("react-hook-form");
|
1070
|
+
var import_react18 = require("@chakra-ui/react");
|
1071
|
+
var import_jsx_runtime18 = require("react/jsx-runtime");
|
1072
|
+
var SubmitButton = (0, import_react18.forwardRef)(
|
880
1073
|
(props, ref) => {
|
881
1074
|
const {
|
882
1075
|
children = "Submit",
|
@@ -886,10 +1079,10 @@ var SubmitButton = react.forwardRef(
|
|
886
1079
|
isLoading,
|
887
1080
|
...rest
|
888
1081
|
} = props;
|
889
|
-
const { formState } =
|
1082
|
+
const { formState } = (0, import_react_hook_form5.useFormContext)();
|
890
1083
|
const isDisabled = disableIfUntouched && !formState.isDirty || disableIfInvalid && !formState.isValid || isDisabledProp;
|
891
|
-
return /* @__PURE__ */
|
892
|
-
|
1084
|
+
return /* @__PURE__ */ (0, import_jsx_runtime18.jsx)(
|
1085
|
+
import_react18.Button,
|
893
1086
|
{
|
894
1087
|
...rest,
|
895
1088
|
ref,
|
@@ -907,6 +1100,9 @@ SubmitButton.defaultProps = {
|
|
907
1100
|
disableIfInvalid: false
|
908
1101
|
};
|
909
1102
|
SubmitButton.displayName = "SubmitButton";
|
1103
|
+
|
1104
|
+
// src/display-if.tsx
|
1105
|
+
var import_react_hook_form6 = require("react-hook-form");
|
910
1106
|
var DisplayIf = ({
|
911
1107
|
children,
|
912
1108
|
name,
|
@@ -915,7 +1111,7 @@ var DisplayIf = ({
|
|
915
1111
|
isExact,
|
916
1112
|
condition = (value) => !!value
|
917
1113
|
}) => {
|
918
|
-
const value =
|
1114
|
+
const value = (0, import_react_hook_form6.useWatch)({
|
919
1115
|
name,
|
920
1116
|
defaultValue,
|
921
1117
|
disabled: isDisabled,
|
@@ -925,17 +1121,28 @@ var DisplayIf = ({
|
|
925
1121
|
return condition(value, context) ? children : null;
|
926
1122
|
};
|
927
1123
|
DisplayIf.displayName = "DisplayIf";
|
928
|
-
|
1124
|
+
|
1125
|
+
// src/step-form.tsx
|
1126
|
+
var React12 = __toESM(require("react"));
|
1127
|
+
var import_react19 = require("@chakra-ui/react");
|
1128
|
+
var import_utils9 = require("@chakra-ui/utils");
|
1129
|
+
var import_core4 = require("@saas-ui/core");
|
1130
|
+
|
1131
|
+
// src/use-step-form.tsx
|
1132
|
+
var React11 = __toESM(require("react"));
|
1133
|
+
var import_react_utils3 = require("@chakra-ui/react-utils");
|
1134
|
+
var import_core3 = require("@saas-ui/core");
|
1135
|
+
var [StepFormProvider, useStepFormContext] = (0, import_react_utils3.createContext)({
|
929
1136
|
name: "StepFormContext",
|
930
1137
|
errorMessage: "useStepFormContext: `context` is undefined. Seems you forgot to wrap step form components in `<StepForm />`"
|
931
1138
|
});
|
932
1139
|
function useStepForm(props) {
|
933
1140
|
const { onChange, steps: stepsOptions, resolver, ...rest } = props;
|
934
|
-
const stepper =
|
935
|
-
const [options, setOptions] =
|
1141
|
+
const stepper = (0, import_core3.useStepper)(rest);
|
1142
|
+
const [options, setOptions] = React11.useState(stepsOptions);
|
936
1143
|
const { activeStep, isLastStep, nextStep } = stepper;
|
937
|
-
const [steps, updateSteps] =
|
938
|
-
const onSubmitStep =
|
1144
|
+
const [steps, updateSteps] = React11.useState({});
|
1145
|
+
const onSubmitStep = React11.useCallback(
|
939
1146
|
async (data) => {
|
940
1147
|
var _a, _b;
|
941
1148
|
try {
|
@@ -956,7 +1163,7 @@ function useStepForm(props) {
|
|
956
1163
|
},
|
957
1164
|
[steps, activeStep, isLastStep]
|
958
1165
|
);
|
959
|
-
const getFormProps =
|
1166
|
+
const getFormProps = React11.useCallback(() => {
|
960
1167
|
const step = steps[activeStep];
|
961
1168
|
return {
|
962
1169
|
onSubmit: onSubmitStep,
|
@@ -967,7 +1174,7 @@ function useStepForm(props) {
|
|
967
1174
|
) : void 0
|
968
1175
|
};
|
969
1176
|
}, [steps, onSubmitStep, activeStep]);
|
970
|
-
const updateStep =
|
1177
|
+
const updateStep = React11.useCallback(
|
971
1178
|
(step) => {
|
972
1179
|
const stepOptions = options == null ? void 0 : options.find((s) => s.name === step.name);
|
973
1180
|
updateSteps((steps2) => {
|
@@ -991,9 +1198,9 @@ function useStepForm(props) {
|
|
991
1198
|
}
|
992
1199
|
function useFormStep(props) {
|
993
1200
|
const { name, schema, resolver, onSubmit } = props;
|
994
|
-
const step =
|
1201
|
+
const step = (0, import_core3.useStep)({ name });
|
995
1202
|
const { steps, updateStep } = useStepFormContext();
|
996
|
-
|
1203
|
+
React11.useEffect(() => {
|
997
1204
|
updateStep({ name, schema, resolver, onSubmit });
|
998
1205
|
}, [name, schema]);
|
999
1206
|
return {
|
@@ -1001,8 +1208,11 @@ function useFormStep(props) {
|
|
1001
1208
|
...steps[name] || { name, schema }
|
1002
1209
|
};
|
1003
1210
|
}
|
1211
|
+
|
1212
|
+
// src/step-form.tsx
|
1213
|
+
var import_jsx_runtime19 = require("react/jsx-runtime");
|
1004
1214
|
var FormStepper = (props) => {
|
1005
|
-
const { activeIndex, setIndex } =
|
1215
|
+
const { activeIndex, setIndex } = (0, import_core4.useStepperContext)();
|
1006
1216
|
const {
|
1007
1217
|
children,
|
1008
1218
|
orientation,
|
@@ -1013,11 +1223,11 @@ var FormStepper = (props) => {
|
|
1013
1223
|
render,
|
1014
1224
|
...rest
|
1015
1225
|
} = props;
|
1016
|
-
const elements =
|
1017
|
-
if (
|
1226
|
+
const elements = React12.Children.map(children, (child) => {
|
1227
|
+
if (React12.isValidElement(child) && (child == null ? void 0 : child.type) === FormStep) {
|
1018
1228
|
const { isCompleted } = useFormStep(child.props);
|
1019
|
-
return /* @__PURE__ */
|
1020
|
-
|
1229
|
+
return /* @__PURE__ */ (0, import_jsx_runtime19.jsx)(
|
1230
|
+
import_core4.StepsItem,
|
1021
1231
|
{
|
1022
1232
|
render,
|
1023
1233
|
name: child.props.name,
|
@@ -1030,12 +1240,12 @@ var FormStepper = (props) => {
|
|
1030
1240
|
}
|
1031
1241
|
return child;
|
1032
1242
|
});
|
1033
|
-
const onChange =
|
1243
|
+
const onChange = React12.useCallback((i) => {
|
1034
1244
|
setIndex(i);
|
1035
1245
|
onChangeProp == null ? void 0 : onChangeProp(i);
|
1036
1246
|
}, []);
|
1037
|
-
return /* @__PURE__ */
|
1038
|
-
|
1247
|
+
return /* @__PURE__ */ (0, import_jsx_runtime19.jsx)(
|
1248
|
+
import_core4.Steps,
|
1039
1249
|
{
|
1040
1250
|
orientation,
|
1041
1251
|
step: activeIndex,
|
@@ -1051,37 +1261,40 @@ var FormStep = (props) => {
|
|
1051
1261
|
const { name, children, className, onSubmit, ...rest } = props;
|
1052
1262
|
const step = useFormStep({ name, onSubmit });
|
1053
1263
|
const { isActive } = step;
|
1054
|
-
return isActive ? /* @__PURE__ */
|
1264
|
+
return isActive ? /* @__PURE__ */ (0, import_jsx_runtime19.jsx)(import_react19.chakra.div, { ...rest, className: (0, import_utils9.cx)("sui-form__step", className), children }) : null;
|
1055
1265
|
};
|
1056
1266
|
FormStep.displayName = "FormStep";
|
1057
1267
|
var PrevButton = (props) => {
|
1058
|
-
const { isFirstStep, isCompleted, prevStep } =
|
1059
|
-
return /* @__PURE__ */
|
1060
|
-
|
1268
|
+
const { isFirstStep, isCompleted, prevStep } = (0, import_core4.useStepperContext)();
|
1269
|
+
return /* @__PURE__ */ (0, import_jsx_runtime19.jsx)(
|
1270
|
+
import_react19.Button,
|
1061
1271
|
{
|
1062
1272
|
isDisabled: isFirstStep || isCompleted,
|
1063
1273
|
children: "Back",
|
1064
1274
|
...props,
|
1065
|
-
className:
|
1066
|
-
onClick:
|
1275
|
+
className: (0, import_utils9.cx)("sui-form__prev-button", props.className),
|
1276
|
+
onClick: (0, import_utils9.callAllHandlers)(props.onClick, prevStep)
|
1067
1277
|
}
|
1068
1278
|
);
|
1069
1279
|
};
|
1070
1280
|
PrevButton.displayName = "PrevButton";
|
1071
1281
|
var NextButton = (props) => {
|
1072
1282
|
const { label = "Next", submitLabel = "Complete", ...rest } = props;
|
1073
|
-
const { isLastStep, isCompleted } =
|
1074
|
-
return /* @__PURE__ */
|
1283
|
+
const { isLastStep, isCompleted } = (0, import_core4.useStepperContext)();
|
1284
|
+
return /* @__PURE__ */ (0, import_jsx_runtime19.jsx)(
|
1075
1285
|
SubmitButton,
|
1076
1286
|
{
|
1077
1287
|
...rest,
|
1078
1288
|
isDisabled: isCompleted,
|
1079
|
-
className:
|
1289
|
+
className: (0, import_utils9.cx)("sui-form__next-button", props.className),
|
1080
1290
|
children: isLastStep || isCompleted ? submitLabel : label
|
1081
1291
|
}
|
1082
1292
|
);
|
1083
1293
|
};
|
1084
1294
|
NextButton.displayName = "NextButton";
|
1295
|
+
|
1296
|
+
// src/field-resolver.ts
|
1297
|
+
var import_utils10 = require("@chakra-ui/utils");
|
1085
1298
|
var mapFields = (schema) => schema && Object.entries(schema).map(([name, { items, label, title, ...field }]) => {
|
1086
1299
|
return {
|
1087
1300
|
...field,
|
@@ -1096,7 +1309,7 @@ var objectFieldResolver = (schema) => {
|
|
1096
1309
|
};
|
1097
1310
|
const getNestedFields = (name) => {
|
1098
1311
|
var _a;
|
1099
|
-
const field =
|
1312
|
+
const field = (0, import_utils10.get)(schema, name);
|
1100
1313
|
if (!field)
|
1101
1314
|
return [];
|
1102
1315
|
if (((_a = field.items) == null ? void 0 : _a.type) === "object") {
|
@@ -1108,10 +1321,13 @@ var objectFieldResolver = (schema) => {
|
|
1108
1321
|
};
|
1109
1322
|
return { getFields, getNestedFields };
|
1110
1323
|
};
|
1324
|
+
|
1325
|
+
// src/watch-field.tsx
|
1326
|
+
var import_react_hook_form7 = require("react-hook-form");
|
1111
1327
|
var WatchField = (props) => {
|
1112
1328
|
const { name, defaultValue, isDisabled, isExact } = props;
|
1113
1329
|
const form = useFormContext();
|
1114
|
-
const field =
|
1330
|
+
const field = (0, import_react_hook_form7.useWatch)({
|
1115
1331
|
name,
|
1116
1332
|
defaultValue,
|
1117
1333
|
disabled: isDisabled,
|
@@ -1119,7 +1335,14 @@ var WatchField = (props) => {
|
|
1119
1335
|
});
|
1120
1336
|
return props.children(field, form) || null;
|
1121
1337
|
};
|
1122
|
-
|
1338
|
+
|
1339
|
+
// src/form.tsx
|
1340
|
+
var React13 = __toESM(require("react"));
|
1341
|
+
var import_react20 = require("@chakra-ui/react");
|
1342
|
+
var import_utils11 = require("@chakra-ui/utils");
|
1343
|
+
var import_react_hook_form8 = require("react-hook-form");
|
1344
|
+
var import_jsx_runtime20 = require("react/jsx-runtime");
|
1345
|
+
var Form = (0, import_react20.forwardRef)(
|
1123
1346
|
(props, ref) => {
|
1124
1347
|
const {
|
1125
1348
|
mode = "all",
|
@@ -1158,10 +1381,10 @@ var Form = react.forwardRef(
|
|
1158
1381
|
context,
|
1159
1382
|
resetOptions
|
1160
1383
|
};
|
1161
|
-
const methods =
|
1384
|
+
const methods = (0, import_react_hook_form8.useForm)(form);
|
1162
1385
|
const { handleSubmit } = methods;
|
1163
|
-
|
1164
|
-
|
1386
|
+
React13.useImperativeHandle(formRef, () => methods, [formRef, methods]);
|
1387
|
+
React13.useEffect(() => {
|
1165
1388
|
let subscription;
|
1166
1389
|
if (onChange) {
|
1167
1390
|
subscription = methods.watch(onChange);
|
@@ -1170,26 +1393,26 @@ var Form = react.forwardRef(
|
|
1170
1393
|
}, [methods, onChange]);
|
1171
1394
|
let _children = children;
|
1172
1395
|
if (!_children && fieldResolver) {
|
1173
|
-
_children = /* @__PURE__ */
|
1174
|
-
/* @__PURE__ */
|
1175
|
-
/* @__PURE__ */
|
1396
|
+
_children = /* @__PURE__ */ (0, import_jsx_runtime20.jsxs)(FormLayout, { children: [
|
1397
|
+
/* @__PURE__ */ (0, import_jsx_runtime20.jsx)(AutoFields, {}),
|
1398
|
+
/* @__PURE__ */ (0, import_jsx_runtime20.jsx)(SubmitButton, { ...fields == null ? void 0 : fields.submit })
|
1176
1399
|
] });
|
1177
1400
|
}
|
1178
|
-
return /* @__PURE__ */
|
1401
|
+
return /* @__PURE__ */ (0, import_jsx_runtime20.jsx)(
|
1179
1402
|
FormProvider,
|
1180
1403
|
{
|
1181
1404
|
...methods,
|
1182
1405
|
schema,
|
1183
1406
|
fieldResolver,
|
1184
1407
|
fields,
|
1185
|
-
children: /* @__PURE__ */
|
1186
|
-
|
1408
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime20.jsx)(
|
1409
|
+
import_react20.chakra.form,
|
1187
1410
|
{
|
1188
1411
|
ref,
|
1189
1412
|
onSubmit: handleSubmit(onSubmit, onError),
|
1190
1413
|
...rest,
|
1191
|
-
className:
|
1192
|
-
children:
|
1414
|
+
className: (0, import_utils11.cx)("sui-form", props.className),
|
1415
|
+
children: (0, import_utils11.runIfFn)(_children, {
|
1193
1416
|
Field,
|
1194
1417
|
DisplayIf,
|
1195
1418
|
ArrayField,
|
@@ -1203,15 +1426,19 @@ var Form = react.forwardRef(
|
|
1203
1426
|
}
|
1204
1427
|
);
|
1205
1428
|
Form.displayName = "Form";
|
1429
|
+
|
1430
|
+
// src/create-form.tsx
|
1431
|
+
var import_react21 = require("@chakra-ui/react");
|
1432
|
+
var import_jsx_runtime21 = require("react/jsx-runtime");
|
1206
1433
|
function createForm({
|
1207
1434
|
resolver,
|
1208
1435
|
fieldResolver = objectFieldResolver,
|
1209
1436
|
fields
|
1210
1437
|
} = {}) {
|
1211
|
-
const DefaultForm =
|
1438
|
+
const DefaultForm = (0, import_react21.forwardRef)(
|
1212
1439
|
(props, ref) => {
|
1213
1440
|
const { schema, ...rest } = props;
|
1214
|
-
return /* @__PURE__ */
|
1441
|
+
return /* @__PURE__ */ (0, import_jsx_runtime21.jsx)(FieldsProvider, { value: fields || {}, children: /* @__PURE__ */ (0, import_jsx_runtime21.jsx)(
|
1215
1442
|
Form,
|
1216
1443
|
{
|
1217
1444
|
ref,
|
@@ -1226,8 +1453,15 @@ function createForm({
|
|
1226
1453
|
DefaultForm.id = "Form";
|
1227
1454
|
return DefaultForm;
|
1228
1455
|
}
|
1456
|
+
|
1457
|
+
// src/create-step-form.tsx
|
1458
|
+
var import_react22 = require("react");
|
1459
|
+
var import_react23 = require("@chakra-ui/react");
|
1460
|
+
var import_core5 = require("@saas-ui/core");
|
1461
|
+
var import_utils12 = require("@chakra-ui/utils");
|
1462
|
+
var import_jsx_runtime22 = require("react/jsx-runtime");
|
1229
1463
|
function createStepForm({ fields, resolver, fieldResolver } = {}) {
|
1230
|
-
const StepForm2 =
|
1464
|
+
const StepForm2 = (0, import_react23.forwardRef)((props, ref) => {
|
1231
1465
|
const { children, steps, ...rest } = props;
|
1232
1466
|
const stepper = useStepForm({
|
1233
1467
|
resolver,
|
@@ -1235,8 +1469,8 @@ function createStepForm({ fields, resolver, fieldResolver } = {}) {
|
|
1235
1469
|
...props
|
1236
1470
|
});
|
1237
1471
|
const { getFormProps, ...ctx } = stepper;
|
1238
|
-
const context =
|
1239
|
-
return /* @__PURE__ */
|
1472
|
+
const context = (0, import_react22.useMemo)(() => ctx, [ctx]);
|
1473
|
+
return /* @__PURE__ */ (0, import_jsx_runtime22.jsx)(import_core5.StepperProvider, { value: context, children: /* @__PURE__ */ (0, import_jsx_runtime22.jsx)(StepFormProvider, { value: context, children: /* @__PURE__ */ (0, import_jsx_runtime22.jsx)(FieldsProvider, { value: fields || {}, children: /* @__PURE__ */ (0, import_jsx_runtime22.jsx)(Form, { ref, ...rest, ...getFormProps(), children: (0, import_utils12.runIfFn)(children, {
|
1240
1474
|
...stepper,
|
1241
1475
|
Field,
|
1242
1476
|
FormStep,
|
@@ -1248,101 +1482,84 @@ function createStepForm({ fields, resolver, fieldResolver } = {}) {
|
|
1248
1482
|
StepForm2.displayName = `Step${Form.displayName || Form.name}`;
|
1249
1483
|
return StepForm2;
|
1250
1484
|
}
|
1485
|
+
|
1486
|
+
// src/index.ts
|
1487
|
+
var import_react_hook_form9 = require("react-hook-form");
|
1251
1488
|
var Form2 = createForm();
|
1252
1489
|
var StepForm = createStepForm();
|
1253
|
-
|
1254
|
-
|
1255
|
-
|
1256
|
-
|
1257
|
-
|
1258
|
-
|
1259
|
-
|
1260
|
-
|
1261
|
-
|
1262
|
-
|
1263
|
-
|
1264
|
-
|
1265
|
-
|
1266
|
-
|
1267
|
-
|
1268
|
-
|
1269
|
-
|
1270
|
-
|
1271
|
-
|
1272
|
-
|
1273
|
-
|
1274
|
-
|
1275
|
-
|
1276
|
-
|
1277
|
-
|
1278
|
-
|
1279
|
-
|
1280
|
-
|
1490
|
+
// Annotate the CommonJS export names for ESM import in node:
|
1491
|
+
0 && (module.exports = {
|
1492
|
+
ArrayField,
|
1493
|
+
ArrayFieldAddButton,
|
1494
|
+
ArrayFieldContainer,
|
1495
|
+
ArrayFieldProvider,
|
1496
|
+
ArrayFieldRemoveButton,
|
1497
|
+
ArrayFieldRow,
|
1498
|
+
ArrayFieldRowContainer,
|
1499
|
+
ArrayFieldRowFields,
|
1500
|
+
ArrayFieldRowProvider,
|
1501
|
+
ArrayFieldRows,
|
1502
|
+
AutoFields,
|
1503
|
+
BaseField,
|
1504
|
+
BaseForm,
|
1505
|
+
CheckboxField,
|
1506
|
+
Controller,
|
1507
|
+
DisplayField,
|
1508
|
+
DisplayIf,
|
1509
|
+
Field,
|
1510
|
+
FieldsProvider,
|
1511
|
+
Form,
|
1512
|
+
FormLayout,
|
1513
|
+
FormLegend,
|
1514
|
+
FormProvider,
|
1515
|
+
FormStep,
|
1516
|
+
FormStepper,
|
1517
|
+
FormValue,
|
1518
|
+
InputField,
|
1519
|
+
InputRightButton,
|
1520
|
+
NativeSelect,
|
1521
|
+
NativeSelectField,
|
1522
|
+
NextButton,
|
1523
|
+
NumberInputField,
|
1524
|
+
ObjectField,
|
1525
|
+
PasswordInput,
|
1526
|
+
PasswordInputField,
|
1527
|
+
PinField,
|
1528
|
+
PrevButton,
|
1529
|
+
RadioField,
|
1530
|
+
RadioInput,
|
1531
|
+
Select,
|
1532
|
+
SelectButton,
|
1533
|
+
SelectField,
|
1534
|
+
SelectList,
|
1535
|
+
SelectOption,
|
1536
|
+
StepForm,
|
1537
|
+
StepFormProvider,
|
1538
|
+
SubmitButton,
|
1539
|
+
SwitchField,
|
1540
|
+
TextareaField,
|
1541
|
+
WatchField,
|
1542
|
+
appendErrors,
|
1543
|
+
createField,
|
1544
|
+
createForm,
|
1545
|
+
createStepForm,
|
1546
|
+
defaultFieldTypes,
|
1547
|
+
objectFieldResolver,
|
1548
|
+
useArrayField,
|
1549
|
+
useArrayFieldAddButton,
|
1550
|
+
useArrayFieldContext,
|
1551
|
+
useArrayFieldRemoveButton,
|
1552
|
+
useArrayFieldRow,
|
1553
|
+
useArrayFieldRowContext,
|
1554
|
+
useController,
|
1555
|
+
useField,
|
1556
|
+
useFieldArray,
|
1557
|
+
useForm,
|
1558
|
+
useFormContext,
|
1559
|
+
useFormState,
|
1560
|
+
useFormStep,
|
1561
|
+
useStepForm,
|
1562
|
+
useStepFormContext,
|
1563
|
+
useWatch
|
1281
1564
|
});
|
1282
|
-
exports.ArrayField = ArrayField;
|
1283
|
-
exports.ArrayFieldAddButton = ArrayFieldAddButton;
|
1284
|
-
exports.ArrayFieldContainer = ArrayFieldContainer;
|
1285
|
-
exports.ArrayFieldProvider = ArrayFieldProvider;
|
1286
|
-
exports.ArrayFieldRemoveButton = ArrayFieldRemoveButton;
|
1287
|
-
exports.ArrayFieldRow = ArrayFieldRow;
|
1288
|
-
exports.ArrayFieldRowContainer = ArrayFieldRowContainer;
|
1289
|
-
exports.ArrayFieldRowFields = ArrayFieldRowFields;
|
1290
|
-
exports.ArrayFieldRowProvider = ArrayFieldRowProvider;
|
1291
|
-
exports.ArrayFieldRows = ArrayFieldRows;
|
1292
|
-
exports.AutoFields = AutoFields;
|
1293
|
-
exports.BaseField = BaseField;
|
1294
|
-
exports.BaseForm = Form;
|
1295
|
-
exports.CheckboxField = CheckboxField;
|
1296
|
-
exports.DisplayField = DisplayField;
|
1297
|
-
exports.DisplayIf = DisplayIf;
|
1298
|
-
exports.Field = Field;
|
1299
|
-
exports.FieldsProvider = FieldsProvider;
|
1300
|
-
exports.Form = Form2;
|
1301
|
-
exports.FormLayout = FormLayout;
|
1302
|
-
exports.FormLegend = FormLegend;
|
1303
|
-
exports.FormProvider = FormProvider;
|
1304
|
-
exports.FormStep = FormStep;
|
1305
|
-
exports.FormStepper = FormStepper;
|
1306
|
-
exports.FormValue = FormValue;
|
1307
|
-
exports.InputField = InputField;
|
1308
|
-
exports.InputRightButton = InputRightButton;
|
1309
|
-
exports.NativeSelect = NativeSelect;
|
1310
|
-
exports.NativeSelectField = NativeSelectField;
|
1311
|
-
exports.NextButton = NextButton;
|
1312
|
-
exports.NumberInputField = NumberInputField2;
|
1313
|
-
exports.ObjectField = ObjectField;
|
1314
|
-
exports.PasswordInput = PasswordInput;
|
1315
|
-
exports.PasswordInputField = PasswordInputField;
|
1316
|
-
exports.PinField = PinField;
|
1317
|
-
exports.PrevButton = PrevButton;
|
1318
|
-
exports.RadioField = RadioField;
|
1319
|
-
exports.RadioInput = RadioInput;
|
1320
|
-
exports.Select = Select;
|
1321
|
-
exports.SelectButton = SelectButton;
|
1322
|
-
exports.SelectField = SelectField;
|
1323
|
-
exports.SelectList = SelectList;
|
1324
|
-
exports.SelectOption = SelectOption;
|
1325
|
-
exports.StepForm = StepForm;
|
1326
|
-
exports.StepFormProvider = StepFormProvider;
|
1327
|
-
exports.SubmitButton = SubmitButton;
|
1328
|
-
exports.SwitchField = SwitchField;
|
1329
|
-
exports.TextareaField = TextareaField;
|
1330
|
-
exports.WatchField = WatchField;
|
1331
|
-
exports.createField = createField;
|
1332
|
-
exports.createForm = createForm;
|
1333
|
-
exports.createStepForm = createStepForm;
|
1334
|
-
exports.defaultFieldTypes = defaultFieldTypes;
|
1335
|
-
exports.objectFieldResolver = objectFieldResolver;
|
1336
|
-
exports.useArrayField = useArrayField;
|
1337
|
-
exports.useArrayFieldAddButton = useArrayFieldAddButton;
|
1338
|
-
exports.useArrayFieldContext = useArrayFieldContext;
|
1339
|
-
exports.useArrayFieldRemoveButton = useArrayFieldRemoveButton;
|
1340
|
-
exports.useArrayFieldRow = useArrayFieldRow;
|
1341
|
-
exports.useArrayFieldRowContext = useArrayFieldRowContext;
|
1342
|
-
exports.useField = useField;
|
1343
|
-
exports.useFormContext = useFormContext;
|
1344
|
-
exports.useFormStep = useFormStep;
|
1345
|
-
exports.useStepForm = useStepForm;
|
1346
|
-
exports.useStepFormContext = useStepFormContext;
|
1347
|
-
//# sourceMappingURL=out.js.map
|
1348
1565
|
//# sourceMappingURL=index.js.map
|