@saas-ui/forms 2.0.0-next.2 → 2.0.0-next.21
Sign up to get free protection for your applications and to get access to all the features.
- package/CHANGELOG.md +194 -0
- package/README.md +53 -6
- package/dist/ajv/index.d.ts +24 -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 +519 -280
- package/dist/index.js +777 -696
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +756 -676
- package/dist/index.mjs.map +1 -1
- package/dist/yup/index.d.ts +525 -21
- package/dist/yup/index.js +21 -9
- package/dist/yup/index.js.map +1 -1
- package/dist/yup/index.mjs +21 -10
- package/dist/yup/index.mjs.map +1 -1
- package/dist/zod/index.d.ts +525 -12
- package/dist/zod/index.js +21 -1
- package/dist/zod/index.js.map +1 -1
- package/dist/zod/index.mjs +21 -3
- package/dist/zod/index.mjs.map +1 -1
- package/package.json +33 -10
- package/src/array-field.tsx +88 -48
- 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 +68 -0
- package/src/create-step-form.tsx +100 -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 +77 -55
- package/src/index.ts +58 -4
- package/src/input-right-button/input-right-button.stories.tsx +1 -1
- package/src/input-right-button/input-right-button.tsx +0 -2
- package/src/layout.tsx +16 -11
- package/src/number-input/number-input.tsx +9 -5
- package/src/object-field.tsx +35 -13
- 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 +116 -85
- package/src/select/select.test.tsx +1 -1
- package/src/select/select.tsx +162 -146
- package/src/step-form.tsx +76 -76
- package/src/submit-button.tsx +5 -1
- package/src/types.ts +149 -0
- package/src/use-array-field.tsx +9 -3
- package/src/use-step-form.tsx +54 -9
- 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.d.ts
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
import * as React$1 from 'react';
|
2
2
|
import React__default from 'react';
|
3
|
-
import { NumberInputProps as NumberInputProps$1, InputProps, RadioGroupProps, SystemProps, StackDirection, RadioProps, MenuProps, ButtonProps, MenuOptionGroupProps, MenuListProps, SelectProps as SelectProps$1, FormControlProps, TextareaProps, SwitchProps, CheckboxProps, UsePinInputProps, HTMLChakraProps, SimpleGridProps, ResponsiveValue, FormLabelProps, ThemingProps } from '@chakra-ui/react';
|
4
|
-
import * as _chakra_ui_system_dist_system_types from '@chakra-ui/system/dist/system.types';
|
5
3
|
import * as react_hook_form from 'react-hook-form';
|
6
|
-
import {
|
7
|
-
export { BatchFieldArrayUpdate, ChangeHandler, Control, Controller, ControllerFieldState, ControllerProps, ControllerRenderProps, CriteriaMode, CustomElement, DeepMap, DeepPartial, DeepPartialSkipArrayKey, DefaultValues, DelayCallback, EmptyObject, ErrorOption, EventType, FieldArray, FieldArrayMethodProps, FieldArrayWithId, Field as FieldDef, FieldElement, FieldError, FieldErrors, FieldName, FieldNamesMarkedBoolean, FieldRefs, FieldValue, FieldValues,
|
8
|
-
import { FocusableElement } from '@chakra-ui/utils';
|
4
|
+
import { FieldValues, FieldPath, RegisterOptions, UseFormReturn as UseFormReturn$1, UseFieldArrayReturn, UseFormProps, WatchObserver, SubmitHandler, SubmitErrorHandler, ResolverOptions, ResolverResult, FormProviderProps as FormProviderProps$1 } from 'react-hook-form';
|
5
|
+
export { BatchFieldArrayUpdate, ChangeHandler, Control, Controller, ControllerFieldState, ControllerProps, ControllerRenderProps, CriteriaMode, CustomElement, DeepMap, DeepPartial, DeepPartialSkipArrayKey, DefaultValues, DelayCallback, EmptyObject, ErrorOption, EventType, FieldArray, FieldArrayMethodProps, FieldArrayWithId, Field as FieldDef, FieldElement, FieldError, FieldErrors, FieldName, FieldNamesMarkedBoolean, FieldRefs, FieldValue, FieldValues, FormProviderProps, FormState, FormStateProxy, FormStateSubjectRef, GetIsDirty, InternalFieldErrors, InternalFieldName, InternalNameSet, IsAny, IsFlatObject, KeepStateOptions, LiteralUnion, Message, Mode, MultipleFieldErrors, Names, NativeFieldValue, NestedValue, NonUndefined, Noop, Primitive, ReadFormState, Ref, RefCallBack, RegisterOptions, Resolver, ResolverError, ResolverOptions, ResolverResult, ResolverSuccess, SetFieldValue, SetValueConfig, Subjects, SubmitErrorHandler, SubmitHandler, TriggerConfig, UnpackNestedValue, UseControllerProps, UseControllerReturn, UseFieldArrayProps, UseFieldArrayReturn, UseFormClearErrors, UseFormGetValues, UseFormHandleSubmit, UseFormProps, UseFormRegister, UseFormRegisterReturn, UseFormReset, UseFormResetField, UseFormReturn, UseFormSetError, UseFormSetFocus, UseFormSetValue, UseFormStateProps, UseFormStateReturn, UseFormTrigger, UseFormUnregister, UseFormWatch, UseWatchProps, Validate, ValidateResult, ValidationMode, ValidationRule, ValidationValue, ValidationValueMessage, WatchInternal, WatchObserver, appendErrors, useController, useFieldArray, useForm, useFormState, useWatch } from 'react-hook-form';
|
9
6
|
import { MaybeRenderProp } from '@chakra-ui/react-utils';
|
10
|
-
import { UseStepperReturn, UseStepperProps
|
7
|
+
import { StepsProps, StepsItemProps, UseStepperReturn, UseStepperProps } from '@saas-ui/core';
|
8
|
+
import { NumberInputProps as NumberInputProps$1, InputProps, RadioProps, RadioGroupProps, SystemProps, StackDirection, MenuProps, ButtonProps, MenuListProps, MenuItemOptionProps, SelectProps as SelectProps$1, TextareaProps, SwitchProps, CheckboxProps, UsePinInputProps, FormControlProps, SimpleGridProps, ResponsiveValue, FormLabelProps, HTMLChakraProps, ThemingProps } from '@chakra-ui/react';
|
9
|
+
import { FocusableElement } from '@chakra-ui/utils';
|
10
|
+
import * as _chakra_ui_system_dist_system_types from '@chakra-ui/system/dist/system.types';
|
11
11
|
|
12
12
|
interface NumberInputOptions {
|
13
13
|
/**
|
@@ -29,50 +29,99 @@ interface NumberInputProps extends NumberInputProps$1, NumberInputOptions {
|
|
29
29
|
interface PasswordOptions {
|
30
30
|
viewIcon?: React__default.ReactNode;
|
31
31
|
viewOffIcon?: React__default.ReactNode;
|
32
|
+
leftAddon?: React__default.ReactNode;
|
32
33
|
}
|
33
34
|
interface PasswordInputProps extends InputProps, PasswordOptions {
|
34
35
|
}
|
35
36
|
declare const PasswordInput: _chakra_ui_system_dist_system_types.ComponentWithAs<"div", PasswordInputProps>;
|
36
37
|
|
37
|
-
interface
|
38
|
-
value: string;
|
39
|
-
label?: string;
|
38
|
+
interface RadioOption extends Omit<RadioProps, 'value' | 'label'>, FieldOption {
|
40
39
|
}
|
40
|
+
type RadioOptions = FieldOptions<RadioOption>;
|
41
41
|
interface RadioInputOptions {
|
42
|
-
options:
|
42
|
+
options: RadioOptions;
|
43
43
|
spacing?: SystemProps['margin'];
|
44
44
|
direction?: StackDirection;
|
45
45
|
}
|
46
46
|
interface RadioInputProps extends Omit<RadioGroupProps, 'children'>, RadioInputOptions {
|
47
47
|
}
|
48
|
+
declare const RadioInput: _chakra_ui_system_dist_system_types.ComponentWithAs<"div", RadioInputProps>;
|
48
49
|
|
49
|
-
interface Option$2 {
|
50
|
-
value: string;
|
51
|
-
label?: string;
|
52
|
-
}
|
53
50
|
interface SelectOptions {
|
54
51
|
/**
|
55
|
-
*
|
56
|
-
|
52
|
+
* The name of the input field in a native form.
|
53
|
+
*/
|
54
|
+
name: string;
|
55
|
+
/**
|
56
|
+
* The value of the select field.
|
57
|
+
*/
|
58
|
+
value?: string | string[];
|
59
|
+
/**
|
60
|
+
* The initial value of the select field.
|
57
61
|
*/
|
58
|
-
|
62
|
+
defaultValue?: string | string[];
|
59
63
|
/**
|
60
|
-
*
|
64
|
+
* The callback invoked when the value of the select field changes.
|
65
|
+
* @param value The value of the select field.
|
61
66
|
*/
|
62
|
-
|
67
|
+
onChange?: (value: string | string[]) => void;
|
63
68
|
/**
|
64
|
-
*
|
65
|
-
* @type (value?: string[]) => React.ReactElement
|
69
|
+
* The placeholder text when there's no value.
|
66
70
|
*/
|
67
|
-
|
71
|
+
placeholder?: string;
|
72
|
+
/**
|
73
|
+
* If `true`, the select will be disabled.
|
74
|
+
*/
|
75
|
+
isDisabled?: boolean;
|
76
|
+
/**
|
77
|
+
* An array of options
|
78
|
+
* If you leave this empty the children prop will be rendered.
|
79
|
+
*/
|
80
|
+
options?: FieldOptions<SelectOption>;
|
68
81
|
/**
|
69
82
|
* Enable multiple select.
|
70
83
|
*/
|
71
84
|
multiple?: boolean;
|
85
|
+
/**
|
86
|
+
* The function used to render the value of the select field.
|
87
|
+
* @param value The value of the select field.
|
88
|
+
* @returns The rendered value.
|
89
|
+
*/
|
90
|
+
renderValue?: (value: string | string[]) => React__default.ReactNode;
|
72
91
|
}
|
73
|
-
|
92
|
+
|
93
|
+
interface SelectProps extends Omit<MenuProps, 'children'>, SelectOptions {
|
94
|
+
}
|
95
|
+
interface SelectButtonProps extends ButtonProps {
|
74
96
|
}
|
97
|
+
/**
|
98
|
+
* Button that opens the select menu and displays the selected value.
|
99
|
+
*
|
100
|
+
* @see https://saas-ui.dev/docs/components/forms/select
|
101
|
+
*/
|
102
|
+
declare const SelectButton: _chakra_ui_system_dist_system_types.ComponentWithAs<"button", SelectButtonProps>;
|
103
|
+
/**
|
104
|
+
* Allow users to select a value from a list of options.
|
105
|
+
*
|
106
|
+
* @see https://saas-ui.dev/docs/components/forms/select
|
107
|
+
*/
|
75
108
|
declare const Select: _chakra_ui_system_dist_system_types.ComponentWithAs<"select", SelectProps>;
|
109
|
+
interface SelectListProps extends MenuListProps {
|
110
|
+
}
|
111
|
+
/**
|
112
|
+
* The list of options to choose from.
|
113
|
+
*
|
114
|
+
* @see https://saas-ui.dev/docs/components/forms/select
|
115
|
+
*/
|
116
|
+
declare const SelectList: React$1.FC<SelectListProps>;
|
117
|
+
interface SelectOption extends Omit<MenuItemOptionProps, 'value'>, FieldOption {
|
118
|
+
}
|
119
|
+
/**
|
120
|
+
* An option in a select list
|
121
|
+
*
|
122
|
+
* @see https://saas-ui.dev/docs/components/forms/select
|
123
|
+
*/
|
124
|
+
declare const SelectOption: _chakra_ui_system_dist_system_types.ComponentWithAs<"button", MenuItemOptionProps>;
|
76
125
|
|
77
126
|
interface Option$1 {
|
78
127
|
value: string;
|
@@ -85,17 +134,85 @@ interface NativeSelectProps extends SelectProps$1, NativeSelectOptions {
|
|
85
134
|
}
|
86
135
|
declare const NativeSelect: _chakra_ui_system_dist_system_types.ComponentWithAs<"select", NativeSelectProps>;
|
87
136
|
|
88
|
-
interface
|
89
|
-
|
90
|
-
|
91
|
-
|
137
|
+
interface InputFieldProps extends InputProps {
|
138
|
+
type?: string;
|
139
|
+
leftAddon?: React$1.ReactNode;
|
140
|
+
rightAddon?: React$1.ReactNode;
|
92
141
|
}
|
93
|
-
|
94
|
-
interface
|
142
|
+
declare const InputField: React$1.FC<InputFieldProps & BaseFieldProps<react_hook_form.FieldValues, string>>;
|
143
|
+
interface NumberInputFieldProps extends NumberInputProps {
|
144
|
+
type: 'number';
|
145
|
+
}
|
146
|
+
declare const NumberInputField: React$1.FC<NumberInputFieldProps & BaseFieldProps<react_hook_form.FieldValues, string>>;
|
147
|
+
declare const PasswordInputField: React$1.FC<PasswordInputProps & BaseFieldProps<react_hook_form.FieldValues, string>>;
|
148
|
+
declare const TextareaField: React$1.FC<TextareaProps & BaseFieldProps<react_hook_form.FieldValues, string>>;
|
149
|
+
declare const SwitchField: React$1.FC<SwitchProps & BaseFieldProps<react_hook_form.FieldValues, string>>;
|
150
|
+
declare const SelectField: React$1.FC<SelectProps & BaseFieldProps<react_hook_form.FieldValues, string>>;
|
151
|
+
declare const CheckboxField: React$1.FC<CheckboxProps & BaseFieldProps<react_hook_form.FieldValues, string>>;
|
152
|
+
declare const RadioField: React$1.FC<RadioInputProps & BaseFieldProps<react_hook_form.FieldValues, string>>;
|
153
|
+
declare const NativeSelectField: React$1.FC<NativeSelectProps & BaseFieldProps<react_hook_form.FieldValues, string>>;
|
154
|
+
interface PinFieldProps extends Omit<UsePinInputProps, 'type'> {
|
155
|
+
pinLength?: number;
|
156
|
+
pinType?: 'alphanumeric' | 'number';
|
157
|
+
spacing?: SystemProps['margin'];
|
158
|
+
}
|
159
|
+
declare const PinField: React$1.FC<PinFieldProps & BaseFieldProps<react_hook_form.FieldValues, string>>;
|
160
|
+
declare const defaultFieldTypes: {
|
161
|
+
text: React$1.FC<InputFieldProps & BaseFieldProps<react_hook_form.FieldValues, string>>;
|
162
|
+
email: React$1.FC<InputFieldProps & BaseFieldProps<react_hook_form.FieldValues, string>>;
|
163
|
+
url: React$1.FC<InputFieldProps & BaseFieldProps<react_hook_form.FieldValues, string>>;
|
164
|
+
phone: React$1.FC<InputFieldProps & BaseFieldProps<react_hook_form.FieldValues, string>>;
|
165
|
+
number: React$1.FC<NumberInputFieldProps & BaseFieldProps<react_hook_form.FieldValues, string>>;
|
166
|
+
password: React$1.FC<PasswordInputProps & BaseFieldProps<react_hook_form.FieldValues, string>>;
|
167
|
+
textarea: React$1.FC<TextareaProps & BaseFieldProps<react_hook_form.FieldValues, string>>;
|
168
|
+
switch: React$1.FC<SwitchProps & BaseFieldProps<react_hook_form.FieldValues, string>>;
|
169
|
+
select: React$1.FC<SelectProps & BaseFieldProps<react_hook_form.FieldValues, string>>;
|
170
|
+
checkbox: React$1.FC<CheckboxProps & BaseFieldProps<react_hook_form.FieldValues, string>>;
|
171
|
+
radio: React$1.FC<RadioInputProps & BaseFieldProps<react_hook_form.FieldValues, string>>;
|
172
|
+
pin: React$1.FC<PinFieldProps & BaseFieldProps<react_hook_form.FieldValues, string>>;
|
173
|
+
'native-select': React$1.FC<NativeSelectProps & BaseFieldProps<react_hook_form.FieldValues, string>>;
|
174
|
+
};
|
175
|
+
type DefaultFields = typeof defaultFieldTypes;
|
176
|
+
|
177
|
+
interface SubmitButtonProps extends ButtonProps {
|
178
|
+
/**
|
179
|
+
* Disable the submit button if the form is untouched.
|
180
|
+
*
|
181
|
+
* Change the default behavior by updating
|
182
|
+
* `SubmitButton.defaultProps.disableIfUntouched`
|
183
|
+
*/
|
184
|
+
disableIfUntouched?: boolean;
|
185
|
+
/**
|
186
|
+
* Disable the submit button if the form is invalid.
|
187
|
+
*
|
188
|
+
* Change the default behavior by updating
|
189
|
+
* `SubmitButton.defaultProps.disableIfInvalid`
|
190
|
+
*/
|
191
|
+
disableIfInvalid?: boolean;
|
192
|
+
}
|
193
|
+
/**
|
194
|
+
* A button with type submit and default color scheme primary and isLoading state when the form is submitting.
|
195
|
+
*
|
196
|
+
* @see Docs https://saas-ui.dev/docs/components/forms/form
|
197
|
+
*/
|
198
|
+
declare const SubmitButton: _chakra_ui_system_dist_system_types.ComponentWithAs<"button", SubmitButtonProps>;
|
199
|
+
|
200
|
+
type FieldOption = {
|
201
|
+
label?: string;
|
202
|
+
value: string;
|
203
|
+
};
|
204
|
+
type FieldOptions<TOption extends FieldOption = FieldOption> = Array<string> | Array<TOption>;
|
205
|
+
type ValueOf<T> = T[keyof T];
|
206
|
+
type ShallowMerge<A, B> = Omit<A, keyof B> & B;
|
207
|
+
type Split<S extends string, D extends string> = string extends S ? string[] : S extends '' ? [] : S extends `${infer T}${D}${infer U}` ? [T, ...Split<U, D>] : [S];
|
208
|
+
type MapPath<T extends string[]> = T extends [infer U, ...infer R] ? U extends string ? `${U extends `${number}` ? '$' : U}${R[0] extends string ? '.' : ''}${R extends string[] ? MapPath<R> : ''}` : '' : '';
|
209
|
+
type TransformPath<T extends string> = MapPath<Split<T, '.'>>;
|
210
|
+
type ArrayFieldPath<Name extends string> = Name extends string ? TransformPath<Name> : never;
|
211
|
+
interface BaseFieldProps<TFieldValues extends FieldValues = FieldValues, TName extends FieldPath<TFieldValues> = FieldPath<TFieldValues>> extends Omit<FormControlProps, 'label' | 'type'> {
|
95
212
|
/**
|
96
213
|
* The field name
|
97
214
|
*/
|
98
|
-
name: TName
|
215
|
+
name: TName | ArrayFieldPath<TName>;
|
99
216
|
/**
|
100
217
|
* The field label
|
101
218
|
*/
|
@@ -114,16 +231,7 @@ interface FieldProps<TFieldValues extends FieldValues = FieldValues, TName exten
|
|
114
231
|
rules?: Omit<RegisterOptions<TFieldValues, TName>, 'valueAsNumber' | 'valueAsDate' | 'setValueAs' | 'disabled'>;
|
115
232
|
/**
|
116
233
|
* Build-in types:
|
117
|
-
* -
|
118
|
-
* - number
|
119
|
-
* - password
|
120
|
-
* - textarea
|
121
|
-
* - select
|
122
|
-
* - native-select
|
123
|
-
* - checkbox
|
124
|
-
* - radio
|
125
|
-
* - switch
|
126
|
-
* - pin
|
234
|
+
* text, number, password, textarea, select, native-select, checkbox, radio, switch, pin
|
127
235
|
*
|
128
236
|
* Will default to a text field if there is no matching type.
|
129
237
|
*/
|
@@ -133,218 +241,74 @@ interface FieldProps<TFieldValues extends FieldValues = FieldValues, TName exten
|
|
133
241
|
*/
|
134
242
|
placeholder?: string;
|
135
243
|
}
|
136
|
-
|
137
|
-
type
|
138
|
-
|
139
|
-
|
140
|
-
};
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
* - select
|
148
|
-
* - native-select
|
149
|
-
* - checkbox
|
150
|
-
* - radio
|
151
|
-
* - switch
|
152
|
-
* - pin
|
153
|
-
*
|
154
|
-
* Will default to a text field if there is no matching type.
|
155
|
-
*/
|
156
|
-
declare const Field: (<TFieldValues extends FieldValues>(props: FieldProps<TFieldValues, react_hook_form.Path<TFieldValues>> & FieldTypeProps & {
|
157
|
-
ref?: React$1.ForwardedRef<FocusableElement> | undefined;
|
158
|
-
}) => React$1.ReactElement) & {
|
159
|
-
displayName?: string | undefined;
|
160
|
-
};
|
161
|
-
declare const withControlledInput: (InputComponent: React$1.FC<any>) => _chakra_ui_system_dist_system_types.ComponentWithAs<React$1.FC<any>, FieldProps<FieldValues, string>>;
|
162
|
-
declare const withUncontrolledInput: (InputComponent: React$1.FC<any>) => _chakra_ui_system_dist_system_types.ComponentWithAs<React$1.FC<any>, FieldProps<FieldValues, string>>;
|
163
|
-
interface RegisterFieldTypeOptions {
|
164
|
-
isControlled?: boolean;
|
165
|
-
hideLabel?: boolean;
|
166
|
-
BaseField?: React$1.FC<any>;
|
167
|
-
}
|
168
|
-
/**
|
169
|
-
* Register a new field type
|
170
|
-
* @param type The name for this field in kebab-case, eg `email` or `array-field`
|
171
|
-
* @param component The React component
|
172
|
-
* @param options
|
173
|
-
* @param options.isControlled Set this to true if this is a controlled field.
|
174
|
-
* @param options.hideLabel Hide the field label, for example for the checkbox field.
|
175
|
-
*/
|
176
|
-
declare const registerFieldType: <T extends object>(type: string, component: React$1.FC<T>, options?: RegisterFieldTypeOptions) => React$1.FC<T & FieldProps<FieldValues, string>>;
|
177
|
-
interface InputFieldProps extends InputProps {
|
178
|
-
type?: string;
|
179
|
-
leftAddon?: React$1.ReactNode;
|
180
|
-
rightAddon?: React$1.ReactNode;
|
181
|
-
}
|
182
|
-
declare const InputField: React$1.FC<InputFieldProps & FieldProps<FieldValues, string>>;
|
183
|
-
interface NumberInputFieldProps extends NumberInputProps {
|
184
|
-
type: 'number';
|
185
|
-
}
|
186
|
-
declare const NumberInputField: React$1.FC<NumberInputFieldProps & FieldProps<FieldValues, string>>;
|
187
|
-
declare const PasswordInputField: React$1.FC<PasswordInputProps & FieldProps<FieldValues, string>>;
|
188
|
-
declare const TextareaField: React$1.FC<TextareaProps & FieldProps<FieldValues, string>>;
|
189
|
-
declare const SwitchField: React$1.FC<SwitchProps & FieldProps<FieldValues, string>>;
|
190
|
-
declare const SelectField: React$1.FC<SelectProps & FieldProps<FieldValues, string>>;
|
191
|
-
declare const CheckboxField: React$1.FC<CheckboxProps & FieldProps<FieldValues, string>>;
|
192
|
-
declare const RadioField: React$1.FC<RadioInputProps & FieldProps<FieldValues, string>>;
|
193
|
-
declare const NativeSelectField: React$1.FC<NativeSelectProps & FieldProps<FieldValues, string>>;
|
194
|
-
interface PinFieldProps extends Omit<UsePinInputProps, 'type'> {
|
195
|
-
pinLength?: number;
|
196
|
-
pinType?: 'alphanumeric' | 'number';
|
197
|
-
spacing?: SystemProps['margin'];
|
198
|
-
}
|
199
|
-
declare const PinField: React$1.FC<PinFieldProps & FieldProps<FieldValues, string>>;
|
200
|
-
declare const fieldTypes: {
|
201
|
-
text: React$1.FC<InputFieldProps & FieldProps<FieldValues, string>>;
|
202
|
-
email: React$1.FC<InputFieldProps & FieldProps<FieldValues, string>>;
|
203
|
-
url: React$1.FC<InputFieldProps & FieldProps<FieldValues, string>>;
|
204
|
-
phone: React$1.FC<InputFieldProps & FieldProps<FieldValues, string>>;
|
205
|
-
number: React$1.FC<NumberInputFieldProps & FieldProps<FieldValues, string>>;
|
206
|
-
password: React$1.FC<PasswordInputProps & FieldProps<FieldValues, string>>;
|
207
|
-
textarea: React$1.FC<TextareaProps & FieldProps<FieldValues, string>>;
|
208
|
-
switch: React$1.FC<SwitchProps & FieldProps<FieldValues, string>>;
|
209
|
-
checkbox: React$1.FC<CheckboxProps & FieldProps<FieldValues, string>>;
|
210
|
-
radio: React$1.FC<RadioInputProps & FieldProps<FieldValues, string>>;
|
211
|
-
pin: React$1.FC<PinFieldProps & FieldProps<FieldValues, string>>;
|
212
|
-
select: React$1.FC<SelectProps & FieldProps<FieldValues, string>>;
|
213
|
-
'native-select': React$1.FC<NativeSelectProps & FieldProps<FieldValues, string>>;
|
244
|
+
type FieldPathWithArray<TFieldValues extends FieldValues, TName extends FieldPath<TFieldValues> = FieldPath<TFieldValues>> = TName | ArrayFieldPath<TName>;
|
245
|
+
type MergeFieldProps<FieldDefs, TFieldValues extends FieldValues = FieldValues, TName extends FieldPath<TFieldValues> = FieldPath<TFieldValues>> = ValueOf<{
|
246
|
+
[K in keyof FieldDefs]: FieldDefs[K] extends React.FC<infer Props> ? {
|
247
|
+
type?: K;
|
248
|
+
} & ShallowMerge<Props, BaseFieldProps<TFieldValues, TName>> : never;
|
249
|
+
}>;
|
250
|
+
type FieldProps<TFieldValues extends FieldValues = FieldValues> = MergeFieldProps<DefaultFields, TFieldValues>;
|
251
|
+
type FormChildren<FieldDefs, TFieldValues extends FieldValues = FieldValues, TContext extends object = object> = MaybeRenderProp<FormRenderContext<TFieldValues, TContext, MergeFieldProps<FieldDefs extends never ? DefaultFields : ShallowMerge<DefaultFields, FieldDefs>, TFieldValues>>>;
|
252
|
+
type DefaultFieldOverrides = {
|
253
|
+
submit?: SubmitButtonProps;
|
254
|
+
[key: string]: any;
|
214
255
|
};
|
215
|
-
type
|
216
|
-
|
217
|
-
type TypeProps<P extends FieldType, T> = React$1.ComponentPropsWithoutRef<P> & {
|
218
|
-
type: T;
|
219
|
-
};
|
220
|
-
type FieldTypeProps = {
|
221
|
-
[Property in keyof FieldTypes]: TypeProps<FieldTypes[Property], Property>;
|
222
|
-
}[keyof FieldTypes] | {
|
223
|
-
type?: string;
|
256
|
+
type FieldOverrides<FieldDefs, TFieldValues extends FieldValues = FieldValues, TName extends FieldPath<TFieldValues> = FieldPath<TFieldValues>> = {
|
257
|
+
[K in FieldPathWithArray<TFieldValues, TName>]?: Omit<MergeFieldProps<FieldDefs extends never ? DefaultFields : ShallowMerge<DefaultFields, FieldDefs>, TFieldValues>, 'name'>;
|
224
258
|
};
|
225
|
-
|
226
|
-
|
227
|
-
|
228
|
-
|
229
|
-
|
230
|
-
|
231
|
-
}>;
|
259
|
+
type WithFields<TFormProps extends FormProps<any, any, any, any>, FieldDefs, ExtraOverrides = object> = TFormProps extends FormProps<infer TSchema, infer TFieldValues, infer TContext> ? Omit<TFormProps, 'children' | 'fields'> & {
|
260
|
+
children?: FormChildren<FieldDefs, TFieldValues, TContext>;
|
261
|
+
fields?: FieldOverrides<FieldDefs, TFieldValues> & {
|
262
|
+
submit?: SubmitButtonProps;
|
263
|
+
} & ExtraOverrides;
|
264
|
+
} : never;
|
232
265
|
|
233
266
|
type FieldResolver = {
|
234
|
-
getFields():
|
235
|
-
getNestedFields(name: string):
|
267
|
+
getFields(): BaseFieldProps[];
|
268
|
+
getNestedFields(name: string): BaseFieldProps[];
|
236
269
|
};
|
237
|
-
|
270
|
+
type GetFieldResolver<TSchema = any> = (schema: TSchema) => FieldResolver;
|
271
|
+
interface SchemaField extends BaseFieldProps {
|
238
272
|
items?: SchemaField[];
|
239
273
|
properties?: Record<string, SchemaField>;
|
240
274
|
}
|
241
275
|
type ObjectSchema = Record<string, SchemaField>;
|
242
|
-
declare const objectFieldResolver:
|
276
|
+
declare const objectFieldResolver: GetFieldResolver<ObjectSchema>;
|
243
277
|
|
244
|
-
interface
|
245
|
-
|
246
|
-
|
247
|
-
|
248
|
-
|
249
|
-
|
250
|
-
|
251
|
-
interface FormRenderContext<TFieldValues extends FieldValues = FieldValues, TContext extends object = object> extends UseFormReturn<TFieldValues, TContext> {
|
252
|
-
Field: React$1.FC<FieldProps<TFieldValues>>;
|
253
|
-
}
|
254
|
-
interface FormOptions<TFieldValues extends FieldValues = FieldValues, TContext extends object = object, TSchema = any> {
|
255
|
-
/**
|
256
|
-
* The form schema, supports Yup, Zod, and AJV.
|
257
|
-
*/
|
258
|
-
schema?: TSchema;
|
259
|
-
/**
|
260
|
-
* Triggers when any of the field change.
|
261
|
-
*/
|
262
|
-
onChange?: WatchObserver<TFieldValues>;
|
263
|
-
/**
|
264
|
-
* The submit handler.
|
265
|
-
*/
|
266
|
-
onSubmit: SubmitHandler<TFieldValues>;
|
267
|
-
/**
|
268
|
-
* Triggers when there are validation errors.
|
269
|
-
*/
|
270
|
-
onError?: SubmitErrorHandler<TFieldValues>;
|
271
|
-
/**
|
272
|
-
* The Hook Form state ref.
|
273
|
-
*/
|
274
|
-
formRef?: React$1.RefObject<UseFormReturn<TFieldValues, TContext>>;
|
275
|
-
/**
|
276
|
-
* The form children, can be a render prop or a ReactNode.
|
277
|
-
*/
|
278
|
-
children?: MaybeRenderProp<FormRenderContext<TFieldValues, TContext>>;
|
279
|
-
}
|
280
|
-
interface FormProps<TFieldValues extends FieldValues = FieldValues, TContext extends object = object, TSchema = any> extends UseFormProps<TFieldValues, TContext>, Omit<HTMLChakraProps<'form'>, 'children' | 'onChange' | 'onSubmit' | 'onError'>, FormOptions<TFieldValues, TContext, TSchema> {
|
278
|
+
interface DisplayIfProps<TFieldValues extends FieldValues = FieldValues, TName extends FieldPath<TFieldValues> = FieldPath<TFieldValues>> {
|
279
|
+
children: React$1.ReactElement;
|
280
|
+
name: TName;
|
281
|
+
defaultValue?: unknown;
|
282
|
+
isDisabled?: boolean;
|
283
|
+
isExact?: boolean;
|
284
|
+
condition?: (value: unknown, context: UseFormReturn$1<TFieldValues>) => boolean;
|
281
285
|
}
|
282
|
-
|
283
|
-
|
284
|
-
|
285
|
-
|
286
|
-
|
287
|
-
|
286
|
+
/**
|
287
|
+
* Conditionally render parts of a form.
|
288
|
+
*
|
289
|
+
* @see Docs https://saas-ui.dev/docs/components/forms/form
|
290
|
+
*/
|
291
|
+
declare const DisplayIf: {
|
292
|
+
<TFieldValues extends FieldValues = FieldValues, TName extends FieldPath<TFieldValues> = FieldPath<TFieldValues>>({ children, name, defaultValue, isDisabled, isExact, condition, }: DisplayIfProps<TFieldValues, TName>): React$1.ReactElement<any, string | React$1.JSXElementConstructor<any>> | null;
|
293
|
+
displayName: string;
|
288
294
|
};
|
289
|
-
type GetResolver = <TFieldValues extends FieldValues, TContext extends object>(schema: any) => (values: TFieldValues, context: TContext | undefined, options: ResolverOptions<TFieldValues>) => Promise<ResolverResult<TFieldValues>>;
|
290
|
-
type GetFieldResolver = (schema: any) => FieldResolver;
|
291
|
-
interface CreateFormProps {
|
292
|
-
resolver?: GetResolver;
|
293
|
-
}
|
294
|
-
declare function createForm<Schema = any>({ resolver }: CreateFormProps): <TFieldValues extends FieldValues, TContext extends object = object, TSchema extends Schema = Schema>(props: FormProps<TFieldValues, TContext, TSchema>) => JSX.Element;
|
295
295
|
|
296
|
-
interface
|
297
|
-
/**
|
298
|
-
* The submit button label.
|
299
|
-
* Pass `null` to render no submit button.
|
300
|
-
*/
|
301
|
-
submitLabel?: React$1.ReactNode;
|
302
|
-
/**
|
303
|
-
* The schema.
|
304
|
-
* Supports object schema, Zod, Yup or Ajv (JSON Schema).
|
305
|
-
* @see https://www.saas-ui.dev/docs/forms/auto-form
|
306
|
-
*/
|
307
|
-
schema: any;
|
308
|
-
/**
|
309
|
-
* The field resolver.
|
310
|
-
*/
|
311
|
-
fieldResolver?: any;
|
312
|
-
}
|
313
|
-
interface AutoFormProps<TFieldValues extends FieldValues, TContext extends object = object> extends Omit<FormProps<TFieldValues, TContext>, 'schema' | 'children'>, AutoFormOptions {
|
314
|
-
children?: React$1.ReactNode;
|
296
|
+
interface FormLayoutProps extends SimpleGridProps {
|
315
297
|
}
|
316
|
-
declare const AutoForm: _chakra_ui_system_dist_system_types.ComponentWithAs<_chakra_ui_system_dist_system_types.As<any>, AutoFormProps<FieldValues, object>>;
|
317
|
-
|
318
|
-
type FormLayoutProps = SimpleGridProps;
|
319
298
|
/**
|
320
|
-
*
|
299
|
+
* Create consistent field spacing and positioning.
|
300
|
+
*
|
321
301
|
*
|
322
302
|
* Renders form items in a `SimpleGrid`
|
323
303
|
* @see https://chakra-ui.com/docs/layout/simple-grid
|
304
|
+
*
|
305
|
+
* @see https://saas-ui.dev/docs/components/forms/form
|
324
306
|
*/
|
325
307
|
declare const FormLayout: {
|
326
308
|
({ children, ...props }: FormLayoutProps): JSX.Element;
|
327
309
|
displayName: string;
|
328
310
|
};
|
329
311
|
|
330
|
-
interface SubmitButtonProps extends ButtonProps {
|
331
|
-
/**
|
332
|
-
* Disable the submit button if the form is untouched.
|
333
|
-
*
|
334
|
-
* Change the default behavior by updating
|
335
|
-
* `SubmitButton.defaultProps.disableIfUntouched`
|
336
|
-
*/
|
337
|
-
disableIfUntouched?: boolean;
|
338
|
-
/**
|
339
|
-
* Disable the submit button if the form is invalid.
|
340
|
-
*
|
341
|
-
* Change the default behavior by updating
|
342
|
-
* `SubmitButton.defaultProps.disableIfInvalid`
|
343
|
-
*/
|
344
|
-
disableIfInvalid?: boolean;
|
345
|
-
}
|
346
|
-
declare const SubmitButton: _chakra_ui_system_dist_system_types.ComponentWithAs<"button", SubmitButtonProps>;
|
347
|
-
|
348
312
|
interface UseArrayFieldReturn extends UseFieldArrayReturn {
|
349
313
|
/**
|
350
314
|
* The array field name
|
@@ -389,11 +353,11 @@ interface UseArrayFieldRowReturn {
|
|
389
353
|
}
|
390
354
|
declare const ArrayFieldRowProvider: React$1.Provider<UseArrayFieldRowReturn>;
|
391
355
|
declare const useArrayFieldRowContext: () => UseArrayFieldRowReturn;
|
392
|
-
interface ArrayFieldOptions {
|
356
|
+
interface ArrayFieldOptions<TFieldValues extends FieldValues = FieldValues, TName extends FieldPath<TFieldValues> = FieldPath<TFieldValues>> {
|
393
357
|
/**
|
394
358
|
* The field name
|
395
359
|
*/
|
396
|
-
name:
|
360
|
+
name: TName;
|
397
361
|
/**
|
398
362
|
* Default value for new values in the array
|
399
363
|
*/
|
@@ -413,12 +377,12 @@ declare const useArrayField: ({ name, defaultValue, keyName, min, max, }: ArrayF
|
|
413
377
|
max: number | undefined;
|
414
378
|
swap: react_hook_form.UseFieldArraySwap;
|
415
379
|
move: react_hook_form.UseFieldArrayMove;
|
416
|
-
prepend: react_hook_form.UseFieldArrayPrepend<
|
417
|
-
append: react_hook_form.UseFieldArrayAppend<
|
380
|
+
prepend: react_hook_form.UseFieldArrayPrepend<FieldValues, string>;
|
381
|
+
append: react_hook_form.UseFieldArrayAppend<FieldValues, string>;
|
418
382
|
remove: react_hook_form.UseFieldArrayRemove;
|
419
|
-
insert: react_hook_form.UseFieldArrayInsert<
|
420
|
-
update: react_hook_form.UseFieldArrayUpdate<
|
421
|
-
replace: react_hook_form.UseFieldArrayReplace<
|
383
|
+
insert: react_hook_form.UseFieldArrayInsert<FieldValues, string>;
|
384
|
+
update: react_hook_form.UseFieldArrayUpdate<FieldValues, string>;
|
385
|
+
replace: react_hook_form.UseFieldArrayReplace<FieldValues, string>;
|
422
386
|
fields: Record<string, string>[];
|
423
387
|
};
|
424
388
|
interface UseArrayFieldRowProps {
|
@@ -460,6 +424,11 @@ interface ArrayFieldRowProps extends FormLayoutProps {
|
|
460
424
|
*/
|
461
425
|
children: React$1.ReactNode;
|
462
426
|
}
|
427
|
+
/**
|
428
|
+
* Render prop component, to get access to the internal fields state. Must be a child of ArrayFieldContainer.
|
429
|
+
*
|
430
|
+
* @see Docs https://saas-ui.dev/docs/components/forms/array-field
|
431
|
+
*/
|
463
432
|
declare const ArrayFieldRow: React$1.FC<ArrayFieldRowProps>;
|
464
433
|
interface ArrayFieldRowFieldsProps extends FormLayoutProps {
|
465
434
|
/**
|
@@ -475,16 +444,42 @@ interface ArrayFieldRowFieldsProps extends FormLayoutProps {
|
|
475
444
|
*/
|
476
445
|
children: React$1.ReactNode;
|
477
446
|
}
|
447
|
+
/**
|
448
|
+
* Add the name prefix to the fields and acts as a horizontal form layout by default.
|
449
|
+
*
|
450
|
+
* @see Docs https://saas-ui.dev/docs/components/forms/array-field
|
451
|
+
*/
|
478
452
|
declare const ArrayFieldRowFields: React$1.FC<ArrayFieldRowFieldsProps>;
|
453
|
+
/**
|
454
|
+
* The row container component providers row context.
|
455
|
+
*
|
456
|
+
* @see Docs https://saas-ui.dev/docs/components/forms/array-field
|
457
|
+
*/
|
479
458
|
declare const ArrayFieldRowContainer: React$1.FC<ArrayFieldRowProps>;
|
459
|
+
/**
|
460
|
+
* The default remove button.
|
461
|
+
*
|
462
|
+
* @see Docs https://saas-ui.dev/docs/components/forms/array-field
|
463
|
+
*/
|
480
464
|
declare const ArrayFieldRemoveButton: React$1.FC<ArrayFieldButtonProps>;
|
465
|
+
/**
|
466
|
+
* The default add button.
|
467
|
+
*
|
468
|
+
* @see Docs https://saas-ui.dev/docs/components/forms/array-field
|
469
|
+
*/
|
481
470
|
declare const ArrayFieldAddButton: React$1.FC<ArrayFieldButtonProps>;
|
482
|
-
interface ArrayFieldProps extends ArrayFieldOptions, Omit<
|
471
|
+
interface ArrayFieldProps<TFieldValues extends FieldValues = FieldValues, TName extends FieldPath<TFieldValues> = FieldPath<TFieldValues>> extends ArrayFieldOptions<TFieldValues, TName>, Omit<BaseFieldProps<TFieldValues, TName>, 'name' | 'defaultValue' | 'children'> {
|
472
|
+
children: MaybeRenderProp<ArrayField[]>;
|
483
473
|
}
|
484
474
|
interface ArrayField {
|
485
475
|
id: string;
|
486
476
|
[key: string]: unknown;
|
487
477
|
}
|
478
|
+
/**
|
479
|
+
* The wrapper component that composes the default ArrayField functionality.
|
480
|
+
*
|
481
|
+
* @see Docs https://saas-ui.dev/docs/components/forms/array-field
|
482
|
+
*/
|
488
483
|
declare const ArrayField: ((props: ArrayFieldProps & {
|
489
484
|
ref?: React$1.ForwardedRef<UseArrayFieldReturn>;
|
490
485
|
}) => React$1.ReactElement) & {
|
@@ -497,29 +492,148 @@ declare const ArrayFieldRows: {
|
|
497
492
|
({ children, }: ArrayFieldRowsProps): React$1.ReactElement | null;
|
498
493
|
displayName: string;
|
499
494
|
};
|
500
|
-
|
495
|
+
interface ArrayFieldContainerProps extends Omit<ArrayFieldProps, 'children'> {
|
496
|
+
children: React$1.ReactNode;
|
497
|
+
}
|
498
|
+
/**
|
499
|
+
* The container component provides context and state management.
|
500
|
+
*
|
501
|
+
* @see Docs https://saas-ui.dev/docs/components/forms/array-field
|
502
|
+
*/
|
503
|
+
declare const ArrayFieldContainer: React$1.ForwardRefExoticComponent<ArrayFieldContainerProps & React$1.RefAttributes<UseArrayFieldReturn>>;
|
501
504
|
|
502
|
-
interface ObjectFieldProps extends
|
503
|
-
name:
|
505
|
+
interface ObjectFieldProps<TFieldValues extends FieldValues = FieldValues, TName extends FieldPath<TFieldValues> = FieldPath<TFieldValues>> extends BaseFieldProps {
|
506
|
+
name: TName;
|
504
507
|
children: React$1.ReactNode;
|
505
508
|
columns?: ResponsiveValue<number>;
|
506
509
|
spacing?: ResponsiveValue<string | number>;
|
507
510
|
}
|
508
511
|
declare const FormLegend: (props: FormLabelProps) => JSX.Element;
|
512
|
+
/**
|
513
|
+
* The object field component.
|
514
|
+
*
|
515
|
+
* @see Docs https://saas-ui.dev/docs/components/forms/object-field
|
516
|
+
*/
|
509
517
|
declare const ObjectField: React$1.FC<ObjectFieldProps>;
|
510
518
|
|
511
|
-
interface
|
512
|
-
|
513
|
-
|
514
|
-
|
515
|
-
|
516
|
-
isExact?: boolean;
|
517
|
-
condition?: (value: unknown, context: UseFormReturn<TFieldValues>) => boolean;
|
519
|
+
interface FormRenderContext<TFieldValues extends FieldValues = FieldValues, TContext extends object = object, TFieldTypes = FieldProps<TFieldValues>> extends UseFormReturn$1<TFieldValues, TContext> {
|
520
|
+
Field: React$1.FC<TFieldTypes & React$1.RefAttributes<FocusableElement>>;
|
521
|
+
DisplayIf: React$1.FC<DisplayIfProps<TFieldValues>>;
|
522
|
+
ArrayField: React$1.FC<ArrayFieldProps<TFieldValues> & React$1.RefAttributes<UseArrayFieldReturn>>;
|
523
|
+
ObjectField: React$1.FC<ObjectFieldProps<TFieldValues>>;
|
518
524
|
}
|
519
|
-
|
520
|
-
|
525
|
+
interface FormOptions<TSchema = unknown, TFieldValues extends FieldValues = FieldValues, TContext extends object = object, TFieldTypes = FieldProps<TFieldValues>> {
|
526
|
+
/**
|
527
|
+
* The form schema.
|
528
|
+
*/
|
529
|
+
schema?: TSchema;
|
530
|
+
/**
|
531
|
+
* Triggers when any of the field change.
|
532
|
+
*/
|
533
|
+
onChange?: WatchObserver<TFieldValues>;
|
534
|
+
/**
|
535
|
+
* The submit handler.
|
536
|
+
*/
|
537
|
+
onSubmit: SubmitHandler<TFieldValues>;
|
538
|
+
/**
|
539
|
+
* Triggers when there are validation errors.
|
540
|
+
*/
|
541
|
+
onError?: SubmitErrorHandler<TFieldValues>;
|
542
|
+
/**
|
543
|
+
* The Hook Form state ref.
|
544
|
+
*/
|
545
|
+
formRef?: React$1.RefObject<UseFormReturn$1<TFieldValues, TContext>>;
|
546
|
+
/**
|
547
|
+
* The form children, can be a render prop or a ReactNode.
|
548
|
+
*/
|
549
|
+
children?: MaybeRenderProp<FormRenderContext<TFieldValues, TContext, TFieldTypes>>;
|
550
|
+
/**
|
551
|
+
* The field resolver, used to resolve the fields from schemas.
|
552
|
+
*/
|
553
|
+
fieldResolver?: FieldResolver;
|
554
|
+
/**
|
555
|
+
* Field overrides
|
556
|
+
*/
|
557
|
+
fields?: DefaultFieldOverrides;
|
558
|
+
}
|
559
|
+
interface FormProps<TSchema = unknown, TFieldValues extends FieldValues = FieldValues, TContext extends object = object, TFieldTypes = FieldProps<TFieldValues>> extends UseFormProps<TFieldValues, TContext>, Omit<HTMLChakraProps<'form'>, 'children' | 'onChange' | 'onSubmit' | 'onError'>, FormOptions<TSchema, TFieldValues, TContext, TFieldTypes> {
|
560
|
+
}
|
561
|
+
/**
|
562
|
+
* The wrapper component provides context, state, and focus management.
|
563
|
+
*
|
564
|
+
* @see Docs https://saas-ui.dev/docs/components/forms/form
|
565
|
+
*/
|
566
|
+
declare const Form$1: FormComponent;
|
567
|
+
type FormComponent = (<TSchema = unknown, TFieldValues extends FieldValues = FieldValues, TContext extends object = object, TFieldTypes = FieldProps<TFieldValues>>(props: FormProps<TSchema, TFieldValues, TContext, TFieldTypes> & {
|
568
|
+
ref?: React$1.ForwardedRef<HTMLFormElement>;
|
569
|
+
}) => React$1.ReactElement) & {
|
570
|
+
displayName?: string;
|
571
|
+
};
|
572
|
+
type GetResolver = <TFieldValues extends FieldValues, TContext extends object>(schema: unknown) => (values: TFieldValues, context: TContext | undefined, options: ResolverOptions<TFieldValues>) => Promise<ResolverResult<TFieldValues>>;
|
573
|
+
|
574
|
+
type StepsOptions<TSchema, TName extends string = string> = {
|
575
|
+
/**
|
576
|
+
* The step name
|
577
|
+
*/
|
578
|
+
name: TName;
|
579
|
+
/**
|
580
|
+
* Schema
|
581
|
+
*/
|
582
|
+
schema?: TSchema;
|
583
|
+
}[];
|
584
|
+
interface StepFormProps<TSteps extends StepsOptions<any> = StepsOptions<any>, TFieldValues extends FieldValues = FieldValues, TContext extends object = object, TFieldTypes = FieldProps<TFieldValues>> extends UseStepFormProps<TSteps, TFieldValues, TContext, TFieldTypes> {
|
585
|
+
}
|
586
|
+
interface FormStepOptions<TName extends string = string> {
|
587
|
+
/**
|
588
|
+
* The step name
|
589
|
+
*/
|
590
|
+
name: TName;
|
591
|
+
/**
|
592
|
+
* Schema
|
593
|
+
*/
|
594
|
+
schema?: any;
|
595
|
+
/**
|
596
|
+
* Hook Form Resolver
|
597
|
+
*/
|
598
|
+
resolver?: any;
|
599
|
+
}
|
600
|
+
interface FormStepperProps extends StepsProps, ThemingProps<'Stepper'> {
|
601
|
+
render?: StepsItemProps['render'];
|
602
|
+
}
|
603
|
+
/**
|
604
|
+
* Renders a stepper that displays progress above the form.
|
605
|
+
*
|
606
|
+
* @see Docs https://saas-ui.dev/docs/components/forms/step-form
|
607
|
+
*/
|
608
|
+
declare const FormStepper: React$1.FC<FormStepperProps>;
|
609
|
+
interface FormStepProps<TName extends string = string> extends FormStepOptions<TName>, Omit<HTMLChakraProps<'div'>, 'onSubmit'> {
|
610
|
+
onSubmit?: FormStepSubmitHandler;
|
611
|
+
}
|
612
|
+
/**
|
613
|
+
* The form step containing fields for a specific step.
|
614
|
+
*
|
615
|
+
* @see Docs https://saas-ui.dev/docs/components/forms/step-form
|
616
|
+
*/
|
617
|
+
declare const FormStep: {
|
618
|
+
<TName extends string = string>(props: FormStepProps<TName>): JSX.Element | null;
|
521
619
|
displayName: string;
|
522
620
|
};
|
621
|
+
/**
|
622
|
+
* A button that this opens the previous step when clicked. Disabled on the first step.
|
623
|
+
*
|
624
|
+
* @see Docs https://saas-ui.dev/docs/components/forms/step-form
|
625
|
+
*/
|
626
|
+
declare const PrevButton: React$1.FC<ButtonProps>;
|
627
|
+
interface NextButtonProps extends Omit<ButtonProps, 'children'> {
|
628
|
+
submitLabel?: string;
|
629
|
+
label?: string;
|
630
|
+
}
|
631
|
+
/**
|
632
|
+
* A button that submits the active step.
|
633
|
+
*
|
634
|
+
* @see Docs https://saas-ui.dev/docs/components/forms/step-form
|
635
|
+
*/
|
636
|
+
declare const NextButton: React$1.FC<NextButtonProps>;
|
523
637
|
|
524
638
|
interface StepState {
|
525
639
|
name: string;
|
@@ -537,8 +651,21 @@ interface StepFormContext extends UseStepperReturn {
|
|
537
651
|
declare const StepFormProvider: React$1.Provider<StepFormContext>;
|
538
652
|
declare const useStepFormContext: () => StepFormContext;
|
539
653
|
|
540
|
-
|
541
|
-
|
654
|
+
type StepName<T extends {
|
655
|
+
[k: number]: {
|
656
|
+
readonly name: string;
|
657
|
+
};
|
658
|
+
}> = T[number]['name'];
|
659
|
+
interface StepFormRenderContext<TSteps extends StepsOptions<any> = StepsOptions<any>, TFieldValues extends FieldValues = FieldValues, TContext extends object = object, TFieldTypes = FieldProps<TFieldValues>> extends UseStepFormReturn<TFieldValues> {
|
660
|
+
Field: React$1.FC<TFieldTypes & React$1.RefAttributes<FocusableElement>>;
|
661
|
+
FormStep: React$1.FC<FormStepProps<StepName<TSteps>>>;
|
662
|
+
DisplayIf: React$1.FC<DisplayIfProps<TFieldValues>>;
|
663
|
+
ArrayField: React$1.FC<ArrayFieldProps<TFieldValues> & React$1.RefAttributes<UseArrayFieldReturn>>;
|
664
|
+
ObjectField: React$1.FC<ObjectFieldProps<TFieldValues>>;
|
665
|
+
}
|
666
|
+
interface UseStepFormProps<TSteps extends StepsOptions<any> = StepsOptions<any>, TFieldValues extends FieldValues = FieldValues, TContext extends object = object, TFieldTypes = FieldProps<TFieldValues>> extends Omit<UseStepperProps, 'onChange'>, Omit<FormProps<any, TFieldValues, TContext, TFieldTypes>, 'children'> {
|
667
|
+
steps?: TSteps;
|
668
|
+
children: MaybeRenderProp<StepFormRenderContext<TSteps, TFieldValues, TContext, TFieldTypes>>;
|
542
669
|
}
|
543
670
|
interface UseStepFormReturn<TFieldValues extends FieldValues = FieldValues> extends UseStepperReturn {
|
544
671
|
getFormProps(): {
|
@@ -549,7 +676,7 @@ interface UseStepFormReturn<TFieldValues extends FieldValues = FieldValues> exte
|
|
549
676
|
updateStep(step: any): void;
|
550
677
|
steps: Record<string, any>;
|
551
678
|
}
|
552
|
-
declare function useStepForm<TFieldValues extends FieldValues = FieldValues
|
679
|
+
declare function useStepForm<TSteps extends StepsOptions<any> = StepsOptions<any>, TFieldValues extends FieldValues = FieldValues, TContext extends object = object, TFieldTypes = FieldProps<TFieldValues>>(props: UseStepFormProps<TSteps, TFieldValues, TContext, TFieldTypes>): UseStepFormReturn<TFieldValues>;
|
553
680
|
interface UseFormStepProps {
|
554
681
|
name: string;
|
555
682
|
schema?: any;
|
@@ -558,38 +685,97 @@ interface UseFormStepProps {
|
|
558
685
|
}
|
559
686
|
declare function useFormStep(props: UseFormStepProps): StepState;
|
560
687
|
|
561
|
-
interface
|
688
|
+
interface CreateFormProps$1<FieldDefs> {
|
689
|
+
resolver?: GetResolver;
|
690
|
+
fieldResolver?: GetFieldResolver;
|
691
|
+
fields?: FieldDefs extends Record<string, React__default.FC<any>> ? FieldDefs : never;
|
692
|
+
}
|
693
|
+
type FormType<FieldDefs, ExtraProps = object, ExtraOverrides = object> = (<TSchema = unknown, TFieldValues extends FieldValues = FieldValues, TContext extends object = object>(props: WithFields<FormProps<TSchema, TFieldValues, TContext>, FieldDefs, ExtraOverrides> & {
|
694
|
+
ref?: React__default.ForwardedRef<HTMLFormElement>;
|
695
|
+
} & ExtraProps) => React__default.ReactElement) & {
|
696
|
+
displayName?: string;
|
697
|
+
id?: string;
|
698
|
+
};
|
699
|
+
declare function createForm<FieldDefs>({ resolver, fieldResolver, fields, }?: CreateFormProps$1<FieldDefs>): FormType<FieldDefs, object, object>;
|
700
|
+
|
701
|
+
interface DisplayFieldProps extends FormControlProps, Omit<FieldProps, 'type' | 'label'> {
|
562
702
|
}
|
563
|
-
|
564
|
-
|
565
|
-
|
566
|
-
|
567
|
-
|
568
|
-
|
569
|
-
|
703
|
+
/**
|
704
|
+
*
|
705
|
+
*
|
706
|
+
* @see Docs https://saas-ui.dev/
|
707
|
+
*/
|
708
|
+
declare const DisplayField: React$1.FC<DisplayFieldProps>;
|
709
|
+
declare const FormValue: React$1.FC<{
|
570
710
|
name: string;
|
571
|
-
|
572
|
-
|
573
|
-
|
574
|
-
|
575
|
-
/**
|
576
|
-
* Hook Form Resolver
|
577
|
-
*/
|
578
|
-
resolver?: any;
|
579
|
-
}
|
580
|
-
interface FormStepperProps extends StepperStepsProps, ThemingProps<'Stepper'> {
|
581
|
-
}
|
582
|
-
declare const FormStepper: React$1.FC<FormStepperProps>;
|
583
|
-
interface FormStepProps extends FormStepOptions, Omit<HTMLChakraProps<'div'>, 'onSubmit'> {
|
584
|
-
onSubmit?: FormStepSubmitHandler;
|
585
|
-
}
|
586
|
-
declare const FormStep: React$1.FC<FormStepProps>;
|
587
|
-
declare const PrevButton: React$1.FC<ButtonProps>;
|
588
|
-
interface NextButtonProps extends Omit<ButtonProps, 'children'> {
|
589
|
-
submitLabel?: string;
|
711
|
+
}>;
|
712
|
+
|
713
|
+
interface Option {
|
714
|
+
value: string;
|
590
715
|
label?: string;
|
716
|
+
[key: string]: unknown;
|
591
717
|
}
|
592
|
-
|
718
|
+
type FieldRules = Pick<RegisterOptions, 'required' | 'min' | 'max' | 'maxLength' | 'minLength' | 'pattern'>;
|
719
|
+
/**
|
720
|
+
* Form field component.
|
721
|
+
*
|
722
|
+
* Build-in types:
|
723
|
+
* text, number, password, textarea, select, native-select, checkbox, radio, switch, pin
|
724
|
+
*
|
725
|
+
* Will default to a text field if there is no matching type.
|
726
|
+
|
727
|
+
* @see Docs https://saas-ui.dev/docs/components/forms/field
|
728
|
+
*/
|
729
|
+
declare const Field: (<TFieldValues extends FieldValues>(props: FieldProps<TFieldValues> & {
|
730
|
+
ref?: React$1.ForwardedRef<FocusableElement> | undefined;
|
731
|
+
}) => React$1.ReactElement) & {
|
732
|
+
displayName?: string | undefined;
|
733
|
+
};
|
734
|
+
|
735
|
+
interface FieldsProps<TSchema = any> {
|
736
|
+
schema?: TSchema;
|
737
|
+
fieldResolver?: FieldResolver;
|
738
|
+
focusFirstField?: boolean;
|
739
|
+
}
|
740
|
+
declare const AutoFields: React$1.FC<FieldsProps>;
|
741
|
+
|
742
|
+
declare const FieldsProvider: React__default.FC<{
|
743
|
+
value: Record<string, React__default.FC<any>>;
|
744
|
+
children: React__default.ReactNode;
|
745
|
+
}>;
|
746
|
+
declare const useField: (type: string) => React__default.FC<any>;
|
747
|
+
|
748
|
+
type FormProviderProps<TFieldValues extends FieldValues = FieldValues, TContext = any, TSchema = any> = FormProviderProps$1<TFieldValues, TContext> & {
|
749
|
+
fieldResolver?: FieldResolver;
|
750
|
+
schema?: TSchema;
|
751
|
+
fields?: {
|
752
|
+
[key: string]: unknown;
|
753
|
+
};
|
754
|
+
};
|
755
|
+
declare const useFormContext: <TFieldValues extends FieldValues = FieldValues, TContext = any, TSchema = any>() => {
|
756
|
+
fieldResolver?: FieldResolver | undefined;
|
757
|
+
schema?: any;
|
758
|
+
fields?: {
|
759
|
+
[key: string]: unknown;
|
760
|
+
} | undefined;
|
761
|
+
watch: react_hook_form.UseFormWatch<FieldValues>;
|
762
|
+
getValues: react_hook_form.UseFormGetValues<FieldValues>;
|
763
|
+
getFieldState: react_hook_form.UseFormGetFieldState<FieldValues>;
|
764
|
+
setError: react_hook_form.UseFormSetError<FieldValues>;
|
765
|
+
clearErrors: react_hook_form.UseFormClearErrors<FieldValues>;
|
766
|
+
setValue: react_hook_form.UseFormSetValue<FieldValues>;
|
767
|
+
trigger: react_hook_form.UseFormTrigger<FieldValues>;
|
768
|
+
formState: react_hook_form.FormState<FieldValues>;
|
769
|
+
resetField: react_hook_form.UseFormResetField<FieldValues>;
|
770
|
+
reset: react_hook_form.UseFormReset<FieldValues>;
|
771
|
+
handleSubmit: react_hook_form.UseFormHandleSubmit<FieldValues>;
|
772
|
+
unregister: react_hook_form.UseFormUnregister<FieldValues>;
|
773
|
+
control: react_hook_form.Control<FieldValues, any>;
|
774
|
+
register: react_hook_form.UseFormRegister<FieldValues>;
|
775
|
+
setFocus: react_hook_form.UseFormSetFocus<FieldValues>;
|
776
|
+
};
|
777
|
+
type UseFormReturn<TFieldValues extends FieldValues = FieldValues, TContext = any, TSchema = any> = ReturnType<typeof useFormContext>;
|
778
|
+
declare const FormProvider: <TFieldValues extends FieldValues = FieldValues, TContext = any, TSchema = any>(props: FormProviderProps<TFieldValues, TContext, TSchema>) => JSX.Element;
|
593
779
|
|
594
780
|
interface WatchFieldProps<Value = unknown, TFieldValues extends FieldValues = FieldValues> {
|
595
781
|
name: string;
|
@@ -603,4 +789,57 @@ declare const WatchField: <Value = unknown, TFieldValues extends FieldValues = F
|
|
603
789
|
type InputRightButtonProps = ButtonProps;
|
604
790
|
declare const InputRightButton: _chakra_ui_system_dist_system_types.ComponentWithAs<"div", ButtonProps>;
|
605
791
|
|
606
|
-
|
792
|
+
/**
|
793
|
+
* The default BaseField component
|
794
|
+
* Composes the Chakra UI FormControl component, with FormLabel, FormHelperText and FormErrorMessage.
|
795
|
+
*/
|
796
|
+
declare const BaseField: React$1.FC<BaseFieldProps>;
|
797
|
+
|
798
|
+
interface CreateFieldOptions {
|
799
|
+
isControlled?: boolean;
|
800
|
+
hideLabel?: boolean;
|
801
|
+
BaseField?: React$1.FC<any>;
|
802
|
+
}
|
803
|
+
/**
|
804
|
+
* Register a new field type
|
805
|
+
* @param type The name for this field in kebab-case, eg `email` or `array-field`
|
806
|
+
* @param component The React component
|
807
|
+
* @param options
|
808
|
+
* @param options.isControlled Set this to true if this is a controlled field.
|
809
|
+
* @param options.hideLabel Hide the field label, for example for the checkbox field.
|
810
|
+
*/
|
811
|
+
declare const createField: <TProps extends object>(component: React$1.FC<TProps>, options?: CreateFieldOptions) => React$1.FC<TProps & BaseFieldProps<react_hook_form.FieldValues, string>>;
|
812
|
+
|
813
|
+
type StepFormType<FieldDefs, ExtraProps = object, ExtraOverrides = object> = (<TSteps extends StepsOptions<any> = StepsOptions<any>, TFieldValues extends FieldValues = FieldValues, TContext extends object = object, TFieldTypes = FieldProps<TFieldValues>>(props: UseStepFormProps<TSteps, TFieldValues, TContext, TFieldTypes> & {
|
814
|
+
ref?: React__default.ForwardedRef<HTMLFormElement>;
|
815
|
+
}) => React__default.ReactElement) & {
|
816
|
+
displayName?: string;
|
817
|
+
id?: string;
|
818
|
+
};
|
819
|
+
interface CreateFormProps<FieldDefs> {
|
820
|
+
resolver?: GetResolver;
|
821
|
+
fieldResolver?: GetFieldResolver;
|
822
|
+
fields?: FieldDefs extends Record<string, React__default.FC<any>> ? FieldDefs : never;
|
823
|
+
}
|
824
|
+
declare function createStepForm<FieldDefs = any, ExtraProps = object, ExtraOverrides = object>({ fields, resolver, fieldResolver }?: CreateFormProps<FieldDefs>): StepFormType<FieldDefs, ExtraProps, ExtraOverrides>;
|
825
|
+
|
826
|
+
/**
|
827
|
+
* Form component.
|
828
|
+
*
|
829
|
+
* @see Docs https://saas-ui.dev/docs/components/forms/form
|
830
|
+
*/
|
831
|
+
declare const Form: FormType<unknown, object, object>;
|
832
|
+
|
833
|
+
/**
|
834
|
+
* Multi-step form component.
|
835
|
+
*
|
836
|
+
* @see Docs https://saas-ui.dev/docs/components/forms/step-form
|
837
|
+
*/
|
838
|
+
declare const StepForm: (<TSteps extends StepsOptions<any> = StepsOptions<any>, TFieldValues extends react_hook_form.FieldValues = react_hook_form.FieldValues, TContext extends object = object, TFieldTypes = FieldProps<TFieldValues>>(props: UseStepFormProps<TSteps, TFieldValues, TContext, TFieldTypes> & {
|
839
|
+
ref?: React$1.ForwardedRef<HTMLFormElement> | undefined;
|
840
|
+
}) => React$1.ReactElement<any, string | React$1.JSXElementConstructor<any>>) & {
|
841
|
+
displayName?: string | undefined;
|
842
|
+
id?: string | undefined;
|
843
|
+
};
|
844
|
+
|
845
|
+
export { ArrayField, ArrayFieldAddButton, ArrayFieldButtonProps, ArrayFieldContainer, ArrayFieldContainerProps, ArrayFieldOptions, ArrayFieldProps, ArrayFieldProvider, ArrayFieldRemoveButton, ArrayFieldRow, ArrayFieldRowContainer, ArrayFieldRowFields, ArrayFieldRowFieldsProps, ArrayFieldRowProvider, ArrayFieldRows, ArrayFieldRowsProps, AutoFields, BaseField, BaseFieldProps, Form$1 as BaseForm, CheckboxField, CreateFieldOptions, CreateFormProps$1 as CreateFormProps, DefaultFieldOverrides, DefaultFields, DisplayField, DisplayFieldProps, DisplayIf, DisplayIfProps, Field, FieldOptions, FieldProps, FieldResolver, FieldRules, FieldsProps, FieldsProvider, Form, FormComponent, FormLayout, FormLayoutProps, FormLegend, FormProps, FormProvider, FormRenderContext, FormStep, FormStepOptions, FormStepProps, FormStepSubmitHandler, FormStepper, FormStepperProps, FormType, FormValue, GetFieldResolver, InputField, InputFieldProps, InputRightButton, InputRightButtonProps, NativeSelect, NativeSelectField, NativeSelectProps, NextButton, NextButtonProps, NumberInputField, NumberInputFieldProps, ObjectField, ObjectFieldProps, ObjectSchema, Option, PasswordInput, PasswordInputField, PasswordInputProps, PinField, PinFieldProps, PrevButton, RadioField, RadioInput, RadioInputProps, RadioOption, RadioOptions, Select, SelectButton, SelectButtonProps, SelectField, SelectList, SelectListProps, SelectOption, SelectProps, StepForm, StepFormContext, StepFormProps, StepFormProvider, StepState, StepsOptions, SubmitButton, SubmitButtonProps, SwitchField, TextareaField, UseArrayFieldReturn, UseArrayFieldRowProps, UseArrayFieldRowReturn, UseFormStepProps, UseStepFormProps, UseStepFormReturn, WatchField, WatchFieldProps, WithFields, createField, createForm, createStepForm, defaultFieldTypes, objectFieldResolver, useArrayField, useArrayFieldAddButton, useArrayFieldContext, useArrayFieldRemoveButton, useArrayFieldRow, useArrayFieldRowContext, useField, useFormContext, useFormStep, useStepForm, useStepFormContext };
|