@saas-ui/forms 1.5.2 → 2.0.0-next.0
Sign up to get free protection for your applications and to get access to all the features.
- package/CHANGELOG.md +15 -0
- package/dist/ajv/index.d.ts +21 -2
- package/dist/ajv/index.js +31 -2
- package/dist/ajv/index.js.map +1 -1
- package/dist/ajv/index.mjs +25 -0
- package/dist/ajv/index.mjs.map +1 -0
- package/dist/index.d.ts +606 -19
- package/dist/index.js +1251 -2
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +1140 -0
- package/dist/index.mjs.map +1 -0
- package/dist/yup/index.d.ts +41 -2
- package/dist/yup/index.js +95 -2
- package/dist/yup/index.js.map +1 -1
- package/dist/yup/index.mjs +86 -0
- package/dist/yup/index.mjs.map +1 -0
- package/dist/zod/index.d.ts +38 -2
- package/dist/zod/index.js +95 -2
- package/dist/zod/index.js.map +1 -1
- package/dist/zod/index.mjs +85 -0
- package/dist/zod/index.mjs.map +1 -0
- package/package.json +18 -28
- package/src/array-field.tsx +20 -13
- package/src/auto-form.tsx +13 -19
- package/src/field-resolver.ts +1 -1
- package/src/field.tsx +4 -9
- package/src/fields.tsx +1 -3
- package/src/form.tsx +70 -26
- package/src/index.ts +3 -1
- package/src/input-right-button/index.ts +1 -0
- package/src/input-right-button/input-right-button.stories.tsx +47 -0
- package/src/input-right-button/input-right-button.test.tsx +12 -0
- package/src/input-right-button/input-right-button.tsx +26 -0
- package/src/layout.tsx +1 -1
- package/src/number-input/index.ts +1 -0
- package/src/number-input/number-input.stories.tsx +39 -0
- package/src/number-input/number-input.test.tsx +6 -0
- package/src/number-input/number-input.tsx +56 -0
- package/src/object-field.tsx +1 -1
- package/src/password-input/index.ts +1 -0
- package/src/password-input/password-input.stories.tsx +50 -0
- package/src/password-input/password-input.test.tsx +20 -0
- package/src/password-input/password-input.tsx +69 -0
- package/src/pin-input/index.ts +1 -0
- package/src/pin-input/pin-input.stories.tsx +38 -0
- package/src/pin-input/pin-input.test.tsx +6 -0
- package/src/pin-input/pin-input.tsx +50 -0
- package/src/radio/index.ts +1 -0
- package/src/radio/radio-input.stories.tsx +45 -0
- package/src/radio/radio-input.tsx +58 -0
- package/src/radio/radio.test.tsx +6 -0
- package/src/select/index.ts +2 -0
- package/src/select/native-select.tsx +42 -0
- package/src/select/select.stories.tsx +144 -0
- package/src/select/select.test.tsx +8 -0
- package/src/select/select.tsx +185 -0
- package/src/step-form.tsx +24 -13
- package/src/submit-button.tsx +32 -38
- package/src/use-step-form.tsx +1 -1
- package/ajv/package.json +0 -28
- package/dist/ajv/ajv-resolver.d.ts +0 -11
- package/dist/ajv/ajv-resolver.d.ts.map +0 -1
- package/dist/ajv/index.d.ts.map +0 -1
- package/dist/ajv/index.modern.mjs +0 -2
- package/dist/ajv/index.modern.mjs.map +0 -1
- package/dist/array-field.d.ts +0 -64
- package/dist/array-field.d.ts.map +0 -1
- package/dist/auto-form.d.ts +0 -32
- package/dist/auto-form.d.ts.map +0 -1
- package/dist/display-field.d.ts +0 -10
- package/dist/display-field.d.ts.map +0 -1
- package/dist/display-if.d.ts +0 -15
- package/dist/display-if.d.ts.map +0 -1
- package/dist/field-resolver.d.ts +0 -13
- package/dist/field-resolver.d.ts.map +0 -1
- package/dist/field.d.ts +0 -147
- package/dist/field.d.ts.map +0 -1
- package/dist/fields.d.ts +0 -9
- package/dist/fields.d.ts.map +0 -1
- package/dist/form.d.ts +0 -44
- package/dist/form.d.ts.map +0 -1
- package/dist/index.d.ts.map +0 -1
- package/dist/index.modern.mjs +0 -2
- package/dist/index.modern.mjs.map +0 -1
- package/dist/layout.d.ts +0 -14
- package/dist/layout.d.ts.map +0 -1
- package/dist/object-field.d.ts +0 -12
- package/dist/object-field.d.ts.map +0 -1
- package/dist/step-form.d.ts +0 -38
- package/dist/step-form.d.ts.map +0 -1
- package/dist/submit-button.d.ts +0 -20
- package/dist/submit-button.d.ts.map +0 -1
- package/dist/use-array-field.d.ts +0 -95
- package/dist/use-array-field.d.ts.map +0 -1
- package/dist/use-step-form.d.ts +0 -40
- package/dist/use-step-form.d.ts.map +0 -1
- package/dist/utils.d.ts +0 -3
- package/dist/utils.d.ts.map +0 -1
- package/dist/watch-field.d.ts +0 -11
- package/dist/watch-field.d.ts.map +0 -1
- package/dist/yup/index.d.ts.map +0 -1
- package/dist/yup/index.modern.mjs +0 -2
- package/dist/yup/index.modern.mjs.map +0 -1
- package/dist/yup/yup-resolver.d.ts +0 -29
- package/dist/yup/yup-resolver.d.ts.map +0 -1
- package/dist/zod/index.d.ts.map +0 -1
- package/dist/zod/index.modern.mjs +0 -2
- package/dist/zod/index.modern.mjs.map +0 -1
- package/dist/zod/zod-resolver.d.ts +0 -35
- package/dist/zod/zod-resolver.d.ts.map +0 -1
- package/yup/package.json +0 -26
- package/zod/package.json +0 -27
package/dist/index.d.ts
CHANGED
@@ -1,19 +1,606 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
export
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
1
|
+
import * as React$1 from 'react';
|
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
|
+
import * as react_hook_form from 'react-hook-form';
|
6
|
+
import { RegisterOptions, FieldValues, FieldPath, UseFormProps, ResolverOptions, ResolverResult, WatchObserver, SubmitHandler, SubmitErrorHandler, UseFormReturn, UseFieldArrayReturn } from 'react-hook-form';
|
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, FormProvider, 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, useFormContext, useFormState, useWatch } from 'react-hook-form';
|
8
|
+
import { FocusableElement } from '@chakra-ui/utils';
|
9
|
+
import { MaybeRenderProp } from '@chakra-ui/react-utils';
|
10
|
+
import { UseStepperReturn, UseStepperProps, StepperStepsProps } from '@saas-ui/core';
|
11
|
+
|
12
|
+
interface NumberInputOptions {
|
13
|
+
/**
|
14
|
+
* Hide the stepper.
|
15
|
+
*/
|
16
|
+
hideStepper?: boolean;
|
17
|
+
/**
|
18
|
+
* Render a custom increment icon.
|
19
|
+
*/
|
20
|
+
incrementIcon?: React$1.ReactNode;
|
21
|
+
/**
|
22
|
+
* Render a custom decrement icon.
|
23
|
+
*/
|
24
|
+
decrementIcon?: React$1.ReactNode;
|
25
|
+
}
|
26
|
+
interface NumberInputProps extends NumberInputProps$1, NumberInputOptions {
|
27
|
+
}
|
28
|
+
|
29
|
+
interface PasswordOptions {
|
30
|
+
viewIcon?: React__default.ReactNode;
|
31
|
+
viewOffIcon?: React__default.ReactNode;
|
32
|
+
}
|
33
|
+
interface PasswordInputProps extends InputProps, PasswordOptions {
|
34
|
+
}
|
35
|
+
declare const PasswordInput: _chakra_ui_system_dist_system_types.ComponentWithAs<"div", PasswordInputProps>;
|
36
|
+
|
37
|
+
interface Option$3 extends RadioProps {
|
38
|
+
value: string;
|
39
|
+
label?: string;
|
40
|
+
}
|
41
|
+
interface RadioInputOptions {
|
42
|
+
options: Option$3[];
|
43
|
+
spacing?: SystemProps['margin'];
|
44
|
+
direction?: StackDirection;
|
45
|
+
}
|
46
|
+
interface RadioInputProps extends Omit<RadioGroupProps, 'children'>, RadioInputOptions {
|
47
|
+
}
|
48
|
+
|
49
|
+
interface Option$2 {
|
50
|
+
value: string;
|
51
|
+
label?: string;
|
52
|
+
}
|
53
|
+
interface SelectOptions {
|
54
|
+
/**
|
55
|
+
* An array of options
|
56
|
+
* If you leave this empty the children prop will be rendered.
|
57
|
+
*/
|
58
|
+
options?: Option$2[];
|
59
|
+
/**
|
60
|
+
* Props passed to the MenuList.
|
61
|
+
*/
|
62
|
+
menuListProps?: MenuListProps;
|
63
|
+
/**
|
64
|
+
* Customize how the value is rendered.
|
65
|
+
* @type (value?: string[]) => React.ReactElement
|
66
|
+
*/
|
67
|
+
renderValue?: (value?: string[]) => React$1.ReactElement | undefined;
|
68
|
+
/**
|
69
|
+
* Enable multiple select.
|
70
|
+
*/
|
71
|
+
multiple?: boolean;
|
72
|
+
}
|
73
|
+
interface SelectProps extends Omit<MenuProps, 'children'>, Pick<ButtonProps, 'isDisabled' | 'leftIcon' | 'rightIcon'>, Pick<MenuOptionGroupProps, 'onChange'>, SelectOptions {
|
74
|
+
}
|
75
|
+
declare const Select: _chakra_ui_system_dist_system_types.ComponentWithAs<"select", SelectProps>;
|
76
|
+
|
77
|
+
interface Option$1 {
|
78
|
+
value: string;
|
79
|
+
label?: string;
|
80
|
+
}
|
81
|
+
interface NativeSelectOptions {
|
82
|
+
options?: Option$1[];
|
83
|
+
}
|
84
|
+
interface NativeSelectProps extends SelectProps$1, NativeSelectOptions {
|
85
|
+
}
|
86
|
+
declare const NativeSelect: _chakra_ui_system_dist_system_types.ComponentWithAs<"select", NativeSelectProps>;
|
87
|
+
|
88
|
+
interface Option {
|
89
|
+
value: string;
|
90
|
+
label?: string;
|
91
|
+
[key: string]: unknown;
|
92
|
+
}
|
93
|
+
type FieldRules = Pick<RegisterOptions, 'required' | 'min' | 'max' | 'maxLength' | 'minLength' | 'pattern'>;
|
94
|
+
interface FieldProps<TFieldValues extends FieldValues = FieldValues, TName extends FieldPath<TFieldValues> = FieldPath<TFieldValues>> extends Omit<FormControlProps, 'label' | 'type'> {
|
95
|
+
/**
|
96
|
+
* The field name
|
97
|
+
*/
|
98
|
+
name: TName;
|
99
|
+
/**
|
100
|
+
* The field label
|
101
|
+
*/
|
102
|
+
label?: string;
|
103
|
+
/**
|
104
|
+
* Hide the field label
|
105
|
+
*/
|
106
|
+
hideLabel?: boolean;
|
107
|
+
/**
|
108
|
+
* Field help text
|
109
|
+
*/
|
110
|
+
help?: string;
|
111
|
+
/**
|
112
|
+
* React hook form rules
|
113
|
+
*/
|
114
|
+
rules?: Omit<RegisterOptions<TFieldValues, TName>, 'valueAsNumber' | 'valueAsDate' | 'setValueAs' | 'disabled'>;
|
115
|
+
/**
|
116
|
+
* Build-in types:
|
117
|
+
* - text
|
118
|
+
* - number
|
119
|
+
* - password
|
120
|
+
* - textarea
|
121
|
+
* - select
|
122
|
+
* - native-select
|
123
|
+
* - checkbox
|
124
|
+
* - radio
|
125
|
+
* - switch
|
126
|
+
* - pin
|
127
|
+
*
|
128
|
+
* Will default to a text field if there is no matching type.
|
129
|
+
*/
|
130
|
+
type?: string;
|
131
|
+
/**
|
132
|
+
* The input placeholder
|
133
|
+
*/
|
134
|
+
placeholder?: string;
|
135
|
+
}
|
136
|
+
declare const BaseField: React$1.FC<FieldProps>;
|
137
|
+
type As<Props = any> = React$1.ElementType<Props>;
|
138
|
+
type PropsOf<T extends As> = React$1.ComponentPropsWithoutRef<T> & {
|
139
|
+
type?: FieldTypes;
|
140
|
+
};
|
141
|
+
/**
|
142
|
+
* Build-in types:
|
143
|
+
* - text
|
144
|
+
* - number
|
145
|
+
* - password
|
146
|
+
* - textarea
|
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>>;
|
214
|
+
};
|
215
|
+
type FieldTypes = typeof fieldTypes;
|
216
|
+
type FieldType<Props = any> = React$1.ElementType<Props>;
|
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;
|
224
|
+
};
|
225
|
+
|
226
|
+
interface DisplayFieldProps extends FormControlProps, Omit<FieldProps, 'type' | 'label'> {
|
227
|
+
}
|
228
|
+
declare const DisplayField: React$1.FC<DisplayFieldProps>;
|
229
|
+
declare const FormValue: React$1.FC<{
|
230
|
+
name: string;
|
231
|
+
}>;
|
232
|
+
|
233
|
+
type FieldResolver = {
|
234
|
+
getFields(): FieldProps[];
|
235
|
+
getNestedFields(name: string): FieldProps[];
|
236
|
+
};
|
237
|
+
interface SchemaField extends FieldProps {
|
238
|
+
items?: SchemaField[];
|
239
|
+
properties?: Record<string, SchemaField>;
|
240
|
+
}
|
241
|
+
type ObjectSchema = Record<string, SchemaField>;
|
242
|
+
declare const objectFieldResolver: (schema: ObjectSchema) => FieldResolver;
|
243
|
+
|
244
|
+
interface FieldsProps {
|
245
|
+
schema: any;
|
246
|
+
fieldResolver?: FieldResolver;
|
247
|
+
focusFirstField?: boolean;
|
248
|
+
}
|
249
|
+
declare const Fields: React$1.FC<FieldsProps>;
|
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> {
|
281
|
+
}
|
282
|
+
declare const Form: (<TFieldValues extends FieldValues, TContext extends object = object, TSchema = any>(props: FormProps<TFieldValues, TContext, TSchema> & {
|
283
|
+
ref?: React$1.ForwardedRef<HTMLFormElement> | undefined;
|
284
|
+
}) => React$1.ReactElement) & {
|
285
|
+
displayName?: string | undefined;
|
286
|
+
getResolver?: GetResolver | undefined;
|
287
|
+
getFieldResolver: GetFieldResolver;
|
288
|
+
};
|
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
|
+
|
296
|
+
interface AutoFormOptions {
|
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;
|
315
|
+
}
|
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
|
+
/**
|
320
|
+
* FormLayout
|
321
|
+
*
|
322
|
+
* Renders form items in a `SimpleGrid`
|
323
|
+
* @see https://chakra-ui.com/docs/layout/simple-grid
|
324
|
+
*/
|
325
|
+
declare const FormLayout: {
|
326
|
+
({ children, ...props }: FormLayoutProps): JSX.Element;
|
327
|
+
displayName: string;
|
328
|
+
};
|
329
|
+
|
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
|
+
interface UseArrayFieldReturn extends UseFieldArrayReturn {
|
349
|
+
/**
|
350
|
+
* The array field name
|
351
|
+
*/
|
352
|
+
name: string;
|
353
|
+
/**
|
354
|
+
* The default value for new items
|
355
|
+
*/
|
356
|
+
defaultValue: Record<string, any>;
|
357
|
+
/**
|
358
|
+
* Min amount of items
|
359
|
+
*/
|
360
|
+
min?: number;
|
361
|
+
/**
|
362
|
+
* Max amount of items
|
363
|
+
*/
|
364
|
+
max?: number;
|
365
|
+
}
|
366
|
+
declare const ArrayFieldProvider: React$1.Provider<UseArrayFieldReturn>;
|
367
|
+
declare const useArrayFieldContext: () => UseArrayFieldReturn;
|
368
|
+
interface UseArrayFieldRowReturn {
|
369
|
+
/**
|
370
|
+
* Name of the array field including the index, eg 'field.0'
|
371
|
+
*/
|
372
|
+
name: string;
|
373
|
+
/**
|
374
|
+
* The field index
|
375
|
+
*/
|
376
|
+
index: number;
|
377
|
+
/**
|
378
|
+
* Remove this array item
|
379
|
+
*/
|
380
|
+
remove: () => void;
|
381
|
+
/**
|
382
|
+
* True if this is the first item
|
383
|
+
*/
|
384
|
+
isFirst: boolean;
|
385
|
+
/**
|
386
|
+
* True if this is the last item
|
387
|
+
*/
|
388
|
+
isLast: boolean;
|
389
|
+
}
|
390
|
+
declare const ArrayFieldRowProvider: React$1.Provider<UseArrayFieldRowReturn>;
|
391
|
+
declare const useArrayFieldRowContext: () => UseArrayFieldRowReturn;
|
392
|
+
interface ArrayFieldOptions {
|
393
|
+
/**
|
394
|
+
* The field name
|
395
|
+
*/
|
396
|
+
name: string;
|
397
|
+
/**
|
398
|
+
* Default value for new values in the array
|
399
|
+
*/
|
400
|
+
defaultValue?: Record<string, any>;
|
401
|
+
/**
|
402
|
+
* Default key name for rows, change this if your data uses a different 'id' field
|
403
|
+
* @default "id"
|
404
|
+
*/
|
405
|
+
keyName?: string;
|
406
|
+
min?: number;
|
407
|
+
max?: number;
|
408
|
+
}
|
409
|
+
declare const useArrayField: ({ name, defaultValue, keyName, min, max, }: ArrayFieldOptions) => {
|
410
|
+
name: string;
|
411
|
+
defaultValue: Record<string, any>;
|
412
|
+
min: number | undefined;
|
413
|
+
max: number | undefined;
|
414
|
+
swap: react_hook_form.UseFieldArraySwap;
|
415
|
+
move: react_hook_form.UseFieldArrayMove;
|
416
|
+
prepend: react_hook_form.UseFieldArrayPrepend<react_hook_form.FieldValues, string>;
|
417
|
+
append: react_hook_form.UseFieldArrayAppend<react_hook_form.FieldValues, string>;
|
418
|
+
remove: react_hook_form.UseFieldArrayRemove;
|
419
|
+
insert: react_hook_form.UseFieldArrayInsert<react_hook_form.FieldValues, string>;
|
420
|
+
update: react_hook_form.UseFieldArrayUpdate<react_hook_form.FieldValues, string>;
|
421
|
+
replace: react_hook_form.UseFieldArrayReplace<react_hook_form.FieldValues, string>;
|
422
|
+
fields: Record<string, string>[];
|
423
|
+
};
|
424
|
+
interface UseArrayFieldRowProps {
|
425
|
+
index: number;
|
426
|
+
}
|
427
|
+
declare const useArrayFieldRow: ({ index }: UseArrayFieldRowProps) => {
|
428
|
+
index: number;
|
429
|
+
isFirst: boolean;
|
430
|
+
isLast: boolean;
|
431
|
+
name: string;
|
432
|
+
remove: () => void;
|
433
|
+
};
|
434
|
+
declare const useArrayFieldRemoveButton: () => {
|
435
|
+
onClick: () => void;
|
436
|
+
isDisabled: boolean;
|
437
|
+
};
|
438
|
+
declare const useArrayFieldAddButton: () => {
|
439
|
+
onClick: () => void;
|
440
|
+
isDisabled: boolean;
|
441
|
+
};
|
442
|
+
|
443
|
+
interface ArrayFieldButtonProps extends ButtonProps {
|
444
|
+
}
|
445
|
+
interface ArrayFieldRowProps extends FormLayoutProps {
|
446
|
+
/**
|
447
|
+
* Amount of field columns
|
448
|
+
*/
|
449
|
+
columns?: ResponsiveValue<number>;
|
450
|
+
/**
|
451
|
+
* Spacing between fields
|
452
|
+
*/
|
453
|
+
spacing?: ResponsiveValue<string | number>;
|
454
|
+
/**
|
455
|
+
* The array index
|
456
|
+
*/
|
457
|
+
index: number;
|
458
|
+
/**
|
459
|
+
* The fields
|
460
|
+
*/
|
461
|
+
children: React$1.ReactNode;
|
462
|
+
}
|
463
|
+
declare const ArrayFieldRow: React$1.FC<ArrayFieldRowProps>;
|
464
|
+
interface ArrayFieldRowFieldsProps extends FormLayoutProps {
|
465
|
+
/**
|
466
|
+
* Amount of field columns
|
467
|
+
*/
|
468
|
+
columns?: ResponsiveValue<number>;
|
469
|
+
/**
|
470
|
+
* Spacing between fields
|
471
|
+
*/
|
472
|
+
spacing?: ResponsiveValue<string | number>;
|
473
|
+
/**
|
474
|
+
* The fields
|
475
|
+
*/
|
476
|
+
children: React$1.ReactNode;
|
477
|
+
}
|
478
|
+
declare const ArrayFieldRowFields: React$1.FC<ArrayFieldRowFieldsProps>;
|
479
|
+
declare const ArrayFieldRowContainer: React$1.FC<ArrayFieldRowProps>;
|
480
|
+
declare const ArrayFieldRemoveButton: React$1.FC<ArrayFieldButtonProps>;
|
481
|
+
declare const ArrayFieldAddButton: React$1.FC<ArrayFieldButtonProps>;
|
482
|
+
interface ArrayFieldProps extends ArrayFieldOptions, Omit<FieldProps, 'defaultValue'> {
|
483
|
+
}
|
484
|
+
interface ArrayField {
|
485
|
+
id: string;
|
486
|
+
[key: string]: unknown;
|
487
|
+
}
|
488
|
+
declare const ArrayField: ((props: ArrayFieldProps & {
|
489
|
+
ref?: React$1.ForwardedRef<UseArrayFieldReturn>;
|
490
|
+
}) => React$1.ReactElement) & {
|
491
|
+
displayName: string;
|
492
|
+
};
|
493
|
+
interface ArrayFieldRowsProps {
|
494
|
+
children: (fields: ArrayField[]) => React$1.ReactElement | null;
|
495
|
+
}
|
496
|
+
declare const ArrayFieldRows: {
|
497
|
+
({ children, }: ArrayFieldRowsProps): React$1.ReactElement | null;
|
498
|
+
displayName: string;
|
499
|
+
};
|
500
|
+
declare const ArrayFieldContainer: React$1.ForwardRefExoticComponent<ArrayFieldProps & React$1.RefAttributes<UseArrayFieldReturn>>;
|
501
|
+
|
502
|
+
interface ObjectFieldProps extends FieldProps {
|
503
|
+
name: string;
|
504
|
+
children: React$1.ReactNode;
|
505
|
+
columns?: ResponsiveValue<number>;
|
506
|
+
spacing?: ResponsiveValue<string | number>;
|
507
|
+
}
|
508
|
+
declare const FormLegend: (props: FormLabelProps) => JSX.Element;
|
509
|
+
declare const ObjectField: React$1.FC<ObjectFieldProps>;
|
510
|
+
|
511
|
+
interface DisplayIfProps<TFieldValues extends FieldValues = FieldValues> {
|
512
|
+
children: React$1.ReactElement;
|
513
|
+
name: string;
|
514
|
+
defaultValue?: unknown;
|
515
|
+
isDisabled?: boolean;
|
516
|
+
isExact?: boolean;
|
517
|
+
condition?: (value: unknown, context: UseFormReturn<TFieldValues>) => boolean;
|
518
|
+
}
|
519
|
+
declare const DisplayIf: {
|
520
|
+
<TFieldValues extends FieldValues = FieldValues>({ children, name, defaultValue, isDisabled, isExact, condition, }: DisplayIfProps<TFieldValues>): React$1.ReactElement<any, string | React$1.JSXElementConstructor<any>> | null;
|
521
|
+
displayName: string;
|
522
|
+
};
|
523
|
+
|
524
|
+
interface StepState {
|
525
|
+
name: string;
|
526
|
+
schema?: any;
|
527
|
+
resolver?: any;
|
528
|
+
isActive?: boolean;
|
529
|
+
isCompleted?: boolean;
|
530
|
+
onSubmit?: FormStepSubmitHandler;
|
531
|
+
}
|
532
|
+
type FormStepSubmitHandler<TFieldValues extends FieldValues = FieldValues> = (data: TFieldValues, stepper: UseStepperReturn) => Promise<void>;
|
533
|
+
interface StepFormContext extends UseStepperReturn {
|
534
|
+
updateStep(state: StepState): void;
|
535
|
+
steps: Record<string, StepState>;
|
536
|
+
}
|
537
|
+
declare const StepFormProvider: React$1.Provider<StepFormContext>;
|
538
|
+
declare const useStepFormContext: () => StepFormContext;
|
539
|
+
|
540
|
+
interface UseStepFormProps<TFieldValues extends FieldValues = FieldValues> extends Omit<UseStepperProps, 'onChange'>, Omit<FormProps<TFieldValues>, 'children'> {
|
541
|
+
children: MaybeRenderProp<UseStepFormReturn<TFieldValues>>;
|
542
|
+
}
|
543
|
+
interface UseStepFormReturn<TFieldValues extends FieldValues = FieldValues> extends UseStepperReturn {
|
544
|
+
getFormProps(): {
|
545
|
+
onSubmit: SubmitHandler<TFieldValues>;
|
546
|
+
schema?: any;
|
547
|
+
resolver?: any;
|
548
|
+
};
|
549
|
+
updateStep(step: any): void;
|
550
|
+
steps: Record<string, any>;
|
551
|
+
}
|
552
|
+
declare function useStepForm<TFieldValues extends FieldValues = FieldValues>(props: UseStepFormProps<TFieldValues>): UseStepFormReturn<TFieldValues>;
|
553
|
+
interface UseFormStepProps {
|
554
|
+
name: string;
|
555
|
+
schema?: any;
|
556
|
+
resolver?: any;
|
557
|
+
onSubmit?: FormStepSubmitHandler;
|
558
|
+
}
|
559
|
+
declare function useFormStep(props: UseFormStepProps): StepState;
|
560
|
+
|
561
|
+
interface StepFormProps<TFieldValues extends FieldValues = FieldValues, TContext extends object = object> extends UseStepFormProps<TFieldValues> {
|
562
|
+
}
|
563
|
+
declare const StepForm: <TFieldValues extends FieldValues>(props: StepFormProps<TFieldValues, object> & {
|
564
|
+
ref?: React$1.ForwardedRef<HTMLFormElement> | undefined;
|
565
|
+
}) => React$1.ReactElement;
|
566
|
+
interface FormStepOptions {
|
567
|
+
/**
|
568
|
+
* The step name
|
569
|
+
*/
|
570
|
+
name: string;
|
571
|
+
/**
|
572
|
+
* Schema
|
573
|
+
*/
|
574
|
+
schema?: any;
|
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;
|
590
|
+
label?: string;
|
591
|
+
}
|
592
|
+
declare const NextButton: React$1.FC<NextButtonProps>;
|
593
|
+
|
594
|
+
interface WatchFieldProps<Value = unknown, TFieldValues extends FieldValues = FieldValues> {
|
595
|
+
name: string;
|
596
|
+
defaultValue?: Value;
|
597
|
+
isDisabled?: boolean;
|
598
|
+
isExact?: boolean;
|
599
|
+
children: (value: Value, form: UseFormReturn<TFieldValues>) => React.ReactElement | void;
|
600
|
+
}
|
601
|
+
declare const WatchField: <Value = unknown, TFieldValues extends FieldValues = FieldValues>(props: WatchFieldProps<Value, TFieldValues>) => React$1.ReactElement<any, string | React$1.JSXElementConstructor<any>> | null;
|
602
|
+
|
603
|
+
type InputRightButtonProps = ButtonProps;
|
604
|
+
declare const InputRightButton: _chakra_ui_system_dist_system_types.ComponentWithAs<"div", ButtonProps>;
|
605
|
+
|
606
|
+
export { ArrayField, ArrayFieldAddButton, ArrayFieldButtonProps, ArrayFieldContainer, ArrayFieldOptions, ArrayFieldProps, ArrayFieldProvider, ArrayFieldRemoveButton, ArrayFieldRow, ArrayFieldRowContainer, ArrayFieldRowFields, ArrayFieldRowFieldsProps, ArrayFieldRowProvider, ArrayFieldRows, ArrayFieldRowsProps, As, AutoForm, AutoFormProps, BaseField, CheckboxField, CreateFormProps, DisplayField, DisplayFieldProps, DisplayIf, DisplayIfProps, Field, FieldProps, FieldResolver, FieldRules, Fields, FieldsProps, Form, FormLayout, FormLayoutProps, FormLegend, FormProps, FormStep, FormStepOptions, FormStepProps, FormStepSubmitHandler, FormStepper, FormStepperProps, FormValue, GetFieldResolver, GetResolver, InputField, InputFieldProps, InputRightButton, InputRightButtonProps, NativeSelect, NativeSelectField, NativeSelectProps, NextButton, NextButtonProps, NumberInputField, NumberInputFieldProps, ObjectField, ObjectFieldProps, ObjectSchema, Option, PasswordInput, PasswordInputField, PasswordInputProps, PinField, PinFieldProps, PrevButton, PropsOf, RadioField, RegisterFieldTypeOptions, Select, SelectField, SelectProps, StepForm, StepFormContext, StepFormProps, StepFormProvider, StepState, SubmitButton, SubmitButtonProps, SwitchField, TextareaField, UseArrayFieldReturn, UseArrayFieldRowProps, UseArrayFieldRowReturn, UseFormStepProps, UseStepFormProps, UseStepFormReturn, WatchField, WatchFieldProps, createForm, objectFieldResolver, registerFieldType, useArrayField, useArrayFieldAddButton, useArrayFieldContext, useArrayFieldRemoveButton, useArrayFieldRow, useArrayFieldRowContext, useFormStep, useStepForm, useStepFormContext, withControlledInput, withUncontrolledInput };
|