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