@saas-ui/forms 2.0.0-next.5 → 2.0.0-next.6
Sign up to get free protection for your applications and to get access to all the features.
- package/CHANGELOG.md +13 -0
- package/dist/ajv/index.d.ts +358 -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 +296 -194
- package/dist/index.js +373 -2613
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +373 -2607
- package/dist/index.mjs.map +1 -1
- package/dist/yup/index.d.ts +573 -106
- 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 +490 -14
- 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 +15 -8
- package/src/array-field.tsx +34 -17
- package/src/base-field.tsx +4 -9
- package/src/create-field.tsx +2 -1
- package/src/create-form.tsx +33 -10
- package/src/default-fields.tsx +21 -4
- package/src/display-field.tsx +1 -2
- package/src/display-if.tsx +14 -8
- package/src/field-resolver.ts +10 -8
- package/src/field.tsx +6 -3
- package/src/fields.tsx +16 -13
- package/src/form-context.tsx +84 -0
- package/src/form.tsx +44 -17
- package/src/index.ts +17 -15
- package/src/object-field.tsx +6 -2
- package/src/password-input/password-input.tsx +1 -1
- package/src/select/select-context.tsx +130 -0
- package/src/select/select.stories.tsx +116 -85
- package/src/select/select.tsx +152 -142
- package/src/types.ts +59 -6
- package/src/use-array-field.tsx +9 -3
- package/src/utils.ts +8 -1
- package/src/watch-field.tsx +2 -6
package/dist/index.d.ts
CHANGED
@@ -1,14 +1,37 @@
|
|
1
1
|
import * as React$1 from 'react';
|
2
2
|
import React__default from 'react';
|
3
|
-
import { NumberInputProps as NumberInputProps$1, InputProps, RadioProps, RadioGroupProps, SystemProps, StackDirection, MenuItemOptionProps, MenuProps, ButtonProps, MenuOptionGroupProps, MenuListProps, SelectProps as SelectProps$1, TextareaProps, SwitchProps, CheckboxProps, UsePinInputProps, HTMLChakraProps, FormControlProps, SimpleGridProps, ResponsiveValue, FormLabelProps, ThemingProps } from '@chakra-ui/react';
|
4
|
-
import { MaybeRenderProp } from '@chakra-ui/react-utils';
|
5
|
-
import * as react_hook_form from 'react-hook-form';
|
6
|
-
import { FieldValues, UseFormReturn, UseFormProps, ResolverOptions, ResolverResult, WatchObserver, SubmitHandler, SubmitErrorHandler, FieldPath, RegisterOptions, 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
3
|
import * as _chakra_ui_system_dist_system_types from '@chakra-ui/system/dist/system.types';
|
4
|
+
import { ButtonProps, NumberInputProps as NumberInputProps$1, InputProps, RadioProps, RadioGroupProps, SystemProps, StackDirection, MenuProps, MenuListProps, MenuItemOptionProps, SelectProps as SelectProps$1, TextareaProps, SwitchProps, CheckboxProps, UsePinInputProps, FormControlProps, SimpleGridProps, ResponsiveValue, FormLabelProps, HTMLChakraProps, ThemingProps } from '@chakra-ui/react';
|
5
|
+
import * as react_hook_form from 'react-hook-form';
|
6
|
+
import { FieldValues, FieldPath, RegisterOptions, UseFormReturn as UseFormReturn$1, UseFieldArrayReturn, UseFormProps, WatchObserver, SubmitHandler, SubmitErrorHandler, ResolverOptions, ResolverResult, FormProviderProps as FormProviderProps$1 } 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, 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';
|
8
|
+
import { MaybeRenderProp } from '@chakra-ui/react-utils';
|
9
9
|
import { FocusableElement } from '@chakra-ui/utils';
|
10
10
|
import { UseStepperReturn, UseStepperProps, StepperStepsProps } from '@saas-ui/core';
|
11
11
|
|
12
|
+
interface SubmitButtonProps extends ButtonProps {
|
13
|
+
/**
|
14
|
+
* Disable the submit button if the form is untouched.
|
15
|
+
*
|
16
|
+
* Change the default behavior by updating
|
17
|
+
* `SubmitButton.defaultProps.disableIfUntouched`
|
18
|
+
*/
|
19
|
+
disableIfUntouched?: boolean;
|
20
|
+
/**
|
21
|
+
* Disable the submit button if the form is invalid.
|
22
|
+
*
|
23
|
+
* Change the default behavior by updating
|
24
|
+
* `SubmitButton.defaultProps.disableIfInvalid`
|
25
|
+
*/
|
26
|
+
disableIfInvalid?: boolean;
|
27
|
+
}
|
28
|
+
/**
|
29
|
+
* A button with type submit and default color scheme primary and isLoading state when the form is submitting.
|
30
|
+
*
|
31
|
+
* @see Docs https://saas-ui.dev/docs/components/forms/form
|
32
|
+
*/
|
33
|
+
declare const SubmitButton: _chakra_ui_system_dist_system_types.ComponentWithAs<"button", SubmitButtonProps>;
|
34
|
+
|
12
35
|
interface NumberInputOptions {
|
13
36
|
/**
|
14
37
|
* Hide the stepper.
|
@@ -47,31 +70,81 @@ interface RadioInputProps extends Omit<RadioGroupProps, 'children'>, RadioInputO
|
|
47
70
|
}
|
48
71
|
declare const RadioInput: _chakra_ui_system_dist_system_types.ComponentWithAs<"div", RadioInputProps>;
|
49
72
|
|
50
|
-
interface SelectOption extends Omit<MenuItemOptionProps, 'value'>, FieldOption {
|
51
|
-
}
|
52
73
|
interface SelectOptions {
|
53
74
|
/**
|
54
|
-
*
|
55
|
-
* If you leave this empty the children prop will be rendered.
|
75
|
+
* The name of the input field in a native form.
|
56
76
|
*/
|
57
|
-
|
77
|
+
name: string;
|
78
|
+
/**
|
79
|
+
* The value of the select field.
|
80
|
+
*/
|
81
|
+
value?: string | string[];
|
82
|
+
/**
|
83
|
+
* The initial value of the select field.
|
84
|
+
*/
|
85
|
+
defaultValue?: string | string[];
|
86
|
+
/**
|
87
|
+
* The callback invoked when the value of the select field changes.
|
88
|
+
* @param value The value of the select field.
|
89
|
+
*/
|
90
|
+
onChange?: (value: string | string[]) => void;
|
91
|
+
/**
|
92
|
+
* The placeholder text when there's no value.
|
93
|
+
*/
|
94
|
+
placeholder?: string;
|
58
95
|
/**
|
59
|
-
*
|
96
|
+
* If `true`, the select will be disabled.
|
60
97
|
*/
|
61
|
-
|
98
|
+
isDisabled?: boolean;
|
62
99
|
/**
|
63
|
-
*
|
64
|
-
*
|
100
|
+
* An array of options
|
101
|
+
* If you leave this empty the children prop will be rendered.
|
65
102
|
*/
|
66
|
-
|
103
|
+
options?: FieldOptions<SelectOption>;
|
67
104
|
/**
|
68
105
|
* Enable multiple select.
|
69
106
|
*/
|
70
107
|
multiple?: boolean;
|
108
|
+
/**
|
109
|
+
* The function used to render the value of the select field.
|
110
|
+
* @param value The value of the select field.
|
111
|
+
* @returns The rendered value.
|
112
|
+
*/
|
113
|
+
renderValue?: (value: string | string[]) => React__default.ReactNode;
|
114
|
+
}
|
115
|
+
|
116
|
+
interface SelectProps extends Omit<MenuProps, 'children'>, SelectOptions {
|
71
117
|
}
|
72
|
-
interface
|
118
|
+
interface SelectButtonProps extends ButtonProps {
|
73
119
|
}
|
120
|
+
/**
|
121
|
+
* Button that opens the select menu and displays the selected value.
|
122
|
+
*
|
123
|
+
* @see https://saas-ui.dev/docs/components/forms/select
|
124
|
+
*/
|
125
|
+
declare const SelectButton: _chakra_ui_system_dist_system_types.ComponentWithAs<"button", SelectButtonProps>;
|
126
|
+
/**
|
127
|
+
* Allow users to select a value from a list of options.
|
128
|
+
*
|
129
|
+
* @see https://saas-ui.dev/docs/components/forms/select
|
130
|
+
*/
|
74
131
|
declare const Select: _chakra_ui_system_dist_system_types.ComponentWithAs<"select", SelectProps>;
|
132
|
+
interface SelectListProps extends MenuListProps {
|
133
|
+
}
|
134
|
+
/**
|
135
|
+
* The list of options to choose from.
|
136
|
+
*
|
137
|
+
* @see https://saas-ui.dev/docs/components/forms/select
|
138
|
+
*/
|
139
|
+
declare const SelectList: React$1.FC<SelectListProps>;
|
140
|
+
interface SelectOption extends Omit<MenuItemOptionProps, 'value'>, FieldOption {
|
141
|
+
}
|
142
|
+
/**
|
143
|
+
* An option in a select list
|
144
|
+
*
|
145
|
+
* @see https://saas-ui.dev/docs/components/forms/select
|
146
|
+
*/
|
147
|
+
declare const SelectOption: _chakra_ui_system_dist_system_types.ComponentWithAs<"button", MenuItemOptionProps>;
|
75
148
|
|
76
149
|
interface Option$1 {
|
77
150
|
value: string;
|
@@ -124,75 +197,22 @@ declare const defaultFieldTypes: {
|
|
124
197
|
};
|
125
198
|
type DefaultFields = typeof defaultFieldTypes;
|
126
199
|
|
127
|
-
type FieldResolver = {
|
128
|
-
getFields(): BaseFieldProps[];
|
129
|
-
getNestedFields(name: string): BaseFieldProps[];
|
130
|
-
};
|
131
|
-
interface SchemaField extends BaseFieldProps {
|
132
|
-
items?: SchemaField[];
|
133
|
-
properties?: Record<string, SchemaField>;
|
134
|
-
}
|
135
|
-
type ObjectSchema = Record<string, SchemaField>;
|
136
|
-
declare const objectFieldResolver: (schema: ObjectSchema) => FieldResolver;
|
137
|
-
|
138
|
-
interface FormRenderContext<TFieldValues extends FieldValues = FieldValues, TContext extends object = object, TFieldTypes = FieldProps<TFieldValues>> extends UseFormReturn<TFieldValues, TContext> {
|
139
|
-
Field: React$1.FC<TFieldTypes>;
|
140
|
-
}
|
141
|
-
interface FormOptions<TFieldValues extends FieldValues = FieldValues, TContext extends object = object, TSchema = any, TFieldTypes = FieldProps<TFieldValues>> {
|
142
|
-
/**
|
143
|
-
* The form schema, supports Yup, Zod, and AJV.
|
144
|
-
*/
|
145
|
-
schema?: TSchema;
|
146
|
-
/**
|
147
|
-
* Triggers when any of the field change.
|
148
|
-
*/
|
149
|
-
onChange?: WatchObserver<TFieldValues>;
|
150
|
-
/**
|
151
|
-
* The submit handler.
|
152
|
-
*/
|
153
|
-
onSubmit: SubmitHandler<TFieldValues>;
|
154
|
-
/**
|
155
|
-
* Triggers when there are validation errors.
|
156
|
-
*/
|
157
|
-
onError?: SubmitErrorHandler<TFieldValues>;
|
158
|
-
/**
|
159
|
-
* The Hook Form state ref.
|
160
|
-
*/
|
161
|
-
formRef?: React$1.RefObject<UseFormReturn<TFieldValues, TContext>>;
|
162
|
-
/**
|
163
|
-
* The form children, can be a render prop or a ReactNode.
|
164
|
-
*/
|
165
|
-
children?: MaybeRenderProp<FormRenderContext<TFieldValues, TContext, TFieldTypes>>;
|
166
|
-
}
|
167
|
-
interface FormProps<TFieldValues extends FieldValues = FieldValues, TContext extends object = object, TSchema = any, TFieldTypes = FieldProps<TFieldValues>> extends UseFormProps<TFieldValues, TContext>, Omit<HTMLChakraProps<'form'>, 'children' | 'onChange' | 'onSubmit' | 'onError'>, FormOptions<TFieldValues, TContext, TSchema, TFieldTypes> {
|
168
|
-
}
|
169
|
-
/**
|
170
|
-
* The wrapper component provides context, state, and focus management.
|
171
|
-
*
|
172
|
-
* @see Docs https://saas-ui.dev/docs/components/forms/form
|
173
|
-
*/
|
174
|
-
declare const Form: (<TFieldValues extends FieldValues, TContext extends object = object, TSchema = any, TFieldTypes = FieldProps<TFieldValues>>(props: FormProps<TFieldValues, TContext, TSchema, TFieldTypes> & {
|
175
|
-
ref?: React$1.ForwardedRef<HTMLFormElement> | undefined;
|
176
|
-
}) => React$1.ReactElement) & {
|
177
|
-
displayName?: string | undefined;
|
178
|
-
getResolver?: GetResolver | undefined;
|
179
|
-
getFieldResolver: GetFieldResolver;
|
180
|
-
};
|
181
|
-
type GetResolver = <TFieldValues extends FieldValues, TContext extends object>(schema: any) => (values: TFieldValues, context: TContext | undefined, options: ResolverOptions<TFieldValues>) => Promise<ResolverResult<TFieldValues>>;
|
182
|
-
type GetFieldResolver = (schema: any) => FieldResolver;
|
183
|
-
|
184
200
|
type FieldOption = {
|
185
|
-
label
|
201
|
+
label?: string;
|
186
202
|
value: string;
|
187
203
|
};
|
188
204
|
type FieldOptions<TOption extends FieldOption = FieldOption> = Array<string> | Array<TOption>;
|
189
205
|
type ValueOf<T> = T[keyof T];
|
190
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;
|
191
211
|
interface BaseFieldProps<TFieldValues extends FieldValues = FieldValues, TName extends FieldPath<TFieldValues> = FieldPath<TFieldValues>> extends Omit<FormControlProps, 'label' | 'type'> {
|
192
212
|
/**
|
193
213
|
* The field name
|
194
214
|
*/
|
195
|
-
name: TName
|
215
|
+
name: TName | ArrayFieldPath<TName>;
|
196
216
|
/**
|
197
217
|
* The field label
|
198
218
|
*/
|
@@ -221,90 +241,57 @@ interface BaseFieldProps<TFieldValues extends FieldValues = FieldValues, TName e
|
|
221
241
|
*/
|
222
242
|
placeholder?: string;
|
223
243
|
}
|
224
|
-
type
|
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<{
|
225
246
|
[K in keyof FieldDefs]: FieldDefs[K] extends React.FC<infer Props> ? {
|
226
247
|
type?: K;
|
227
|
-
} & ShallowMerge<Props, BaseFieldProps<TFieldValues>> : never;
|
248
|
+
} & ShallowMerge<Props, BaseFieldProps<TFieldValues, TName>> : never;
|
228
249
|
}>;
|
229
250
|
type FieldProps<TFieldValues extends FieldValues = FieldValues> = MergeFieldProps<DefaultFields, TFieldValues>;
|
230
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>>>;
|
231
|
-
type
|
232
|
-
|
252
|
+
type DefaultFieldOverrides = {
|
253
|
+
submit?: SubmitButtonProps;
|
254
|
+
[key: string]: any;
|
255
|
+
};
|
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'>;
|
258
|
+
};
|
259
|
+
type WithFields<TFormProps extends FormProps<any, any, any, any>, FieldDefs> = TFormProps extends FormProps<infer TFieldValues, infer TContext> ? Omit<TFormProps, 'children' | 'fields'> & {
|
260
|
+
children?: FormChildren<FieldDefs, TFieldValues, TContext>;
|
261
|
+
fields?: FieldOverrides<FieldDefs, TFieldValues> & {
|
262
|
+
submit?: SubmitButtonProps;
|
263
|
+
};
|
233
264
|
} : never;
|
234
265
|
|
235
|
-
|
236
|
-
|
237
|
-
|
238
|
-
*
|
239
|
-
*
|
240
|
-
* @see Docs https://saas-ui.dev/
|
241
|
-
*/
|
242
|
-
declare const DisplayField: React$1.FC<DisplayFieldProps>;
|
243
|
-
declare const FormValue: React$1.FC<{
|
244
|
-
name: string;
|
245
|
-
}>;
|
246
|
-
|
247
|
-
interface Option {
|
248
|
-
value: string;
|
249
|
-
label?: string;
|
250
|
-
[key: string]: unknown;
|
251
|
-
}
|
252
|
-
type FieldRules = Pick<RegisterOptions, 'required' | 'min' | 'max' | 'maxLength' | 'minLength' | 'pattern'>;
|
253
|
-
/**
|
254
|
-
* Form field component.
|
255
|
-
*
|
256
|
-
* Build-in types:
|
257
|
-
* text, number, password, textarea, select, native-select, checkbox, radio, switch, pin
|
258
|
-
*
|
259
|
-
* Will default to a text field if there is no matching type.
|
260
|
-
|
261
|
-
* @see Docs https://saas-ui.dev/docs/components/forms/field
|
262
|
-
*/
|
263
|
-
declare const Field: (<TFieldValues extends FieldValues>(props: FieldProps<TFieldValues> & {
|
264
|
-
ref?: React$1.ForwardedRef<FocusableElement> | undefined;
|
265
|
-
}) => React$1.ReactElement) & {
|
266
|
-
displayName?: string | undefined;
|
266
|
+
type FieldResolver = {
|
267
|
+
getFields(): BaseFieldProps[];
|
268
|
+
getNestedFields(name: string): BaseFieldProps[];
|
267
269
|
};
|
268
|
-
|
269
|
-
interface
|
270
|
-
|
271
|
-
|
272
|
-
focusFirstField?: boolean;
|
270
|
+
type GetFieldResolver<TSchema = any> = (schema: TSchema) => FieldResolver;
|
271
|
+
interface SchemaField extends BaseFieldProps {
|
272
|
+
items?: SchemaField[];
|
273
|
+
properties?: Record<string, SchemaField>;
|
273
274
|
}
|
274
|
-
|
275
|
-
|
276
|
-
declare const FieldsProvider: React__default.FC<{
|
277
|
-
value: Record<string, React__default.FC<any>>;
|
278
|
-
children: React__default.ReactNode;
|
279
|
-
}>;
|
280
|
-
declare const useField: (type: string) => React__default.FC<any>;
|
275
|
+
type ObjectSchema = Record<string, SchemaField>;
|
276
|
+
declare const objectFieldResolver: GetFieldResolver<ObjectSchema>;
|
281
277
|
|
282
|
-
interface
|
283
|
-
|
284
|
-
|
285
|
-
|
286
|
-
|
287
|
-
|
288
|
-
|
289
|
-
* The schema.
|
290
|
-
* Supports object schema, Zod, Yup or Ajv (JSON Schema).
|
291
|
-
* @see https://www.saas-ui.dev/docs/forms/auto-form
|
292
|
-
*/
|
293
|
-
schema: any;
|
294
|
-
/**
|
295
|
-
* The field resolver.
|
296
|
-
*/
|
297
|
-
fieldResolver?: any;
|
298
|
-
}
|
299
|
-
interface AutoFormProps<TFieldValues extends FieldValues, TContext extends object = object> extends Omit<FormProps<TFieldValues, TContext>, 'schema' | 'children'>, AutoFormOptions {
|
300
|
-
children?: React$1.ReactNode;
|
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;
|
301
285
|
}
|
302
286
|
/**
|
303
|
-
*
|
287
|
+
* Conditionally render parts of a form.
|
304
288
|
*
|
305
|
-
* @see Docs https://saas-ui.dev/docs/components/forms/
|
289
|
+
* @see Docs https://saas-ui.dev/docs/components/forms/form
|
306
290
|
*/
|
307
|
-
declare const
|
291
|
+
declare const DisplayIf: {
|
292
|
+
<TFieldValues extends FieldValues = FieldValues, TName extends react_hook_form.Path<TFieldValues> = react_hook_form.Path<TFieldValues>>({ children, name, defaultValue, isDisabled, isExact, condition, }: DisplayIfProps<TFieldValues, TName>): React$1.ReactElement<any, string | React$1.JSXElementConstructor<any>> | null;
|
293
|
+
displayName: string;
|
294
|
+
};
|
308
295
|
|
309
296
|
interface FormLayoutProps extends SimpleGridProps {
|
310
297
|
}
|
@@ -322,29 +309,6 @@ declare const FormLayout: {
|
|
322
309
|
displayName: string;
|
323
310
|
};
|
324
311
|
|
325
|
-
interface SubmitButtonProps extends ButtonProps {
|
326
|
-
/**
|
327
|
-
* Disable the submit button if the form is untouched.
|
328
|
-
*
|
329
|
-
* Change the default behavior by updating
|
330
|
-
* `SubmitButton.defaultProps.disableIfUntouched`
|
331
|
-
*/
|
332
|
-
disableIfUntouched?: boolean;
|
333
|
-
/**
|
334
|
-
* Disable the submit button if the form is invalid.
|
335
|
-
*
|
336
|
-
* Change the default behavior by updating
|
337
|
-
* `SubmitButton.defaultProps.disableIfInvalid`
|
338
|
-
*/
|
339
|
-
disableIfInvalid?: boolean;
|
340
|
-
}
|
341
|
-
/**
|
342
|
-
* A button with type submit and default color scheme primary and isLoading state when the form is submitting.
|
343
|
-
*
|
344
|
-
* @see Docs https://saas-ui.dev/docs/components/forms/form
|
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 {
|
@@ -504,7 +468,8 @@ declare const ArrayFieldRemoveButton: React$1.FC<ArrayFieldButtonProps>;
|
|
504
468
|
* @see Docs https://saas-ui.dev/docs/components/forms/array-field
|
505
469
|
*/
|
506
470
|
declare const ArrayFieldAddButton: React$1.FC<ArrayFieldButtonProps>;
|
507
|
-
interface ArrayFieldProps extends ArrayFieldOptions, Omit<BaseFieldProps, 'defaultValue'> {
|
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[]>;
|
508
473
|
}
|
509
474
|
interface ArrayField {
|
510
475
|
id: string;
|
@@ -527,15 +492,18 @@ declare const ArrayFieldRows: {
|
|
527
492
|
({ children, }: ArrayFieldRowsProps): React$1.ReactElement | null;
|
528
493
|
displayName: string;
|
529
494
|
};
|
495
|
+
interface ArrayFieldContainerProps extends Omit<ArrayFieldProps, 'children'> {
|
496
|
+
children: React$1.ReactNode;
|
497
|
+
}
|
530
498
|
/**
|
531
499
|
* The container component provides context and state management.
|
532
500
|
*
|
533
501
|
* @see Docs https://saas-ui.dev/docs/components/forms/array-field
|
534
502
|
*/
|
535
|
-
declare const ArrayFieldContainer: React$1.ForwardRefExoticComponent<
|
503
|
+
declare const ArrayFieldContainer: React$1.ForwardRefExoticComponent<ArrayFieldContainerProps & React$1.RefAttributes<UseArrayFieldReturn>>;
|
536
504
|
|
537
|
-
interface ObjectFieldProps extends BaseFieldProps {
|
538
|
-
name:
|
505
|
+
interface ObjectFieldProps<TFieldValues extends FieldValues = FieldValues, TName extends FieldPath<TFieldValues> = FieldPath<TFieldValues>> extends BaseFieldProps {
|
506
|
+
name: TName;
|
539
507
|
children: React$1.ReactNode;
|
540
508
|
columns?: ResponsiveValue<number>;
|
541
509
|
spacing?: ResponsiveValue<string | number>;
|
@@ -548,23 +516,106 @@ declare const FormLegend: (props: FormLabelProps) => JSX.Element;
|
|
548
516
|
*/
|
549
517
|
declare const ObjectField: React$1.FC<ObjectFieldProps>;
|
550
518
|
|
551
|
-
interface
|
552
|
-
|
553
|
-
|
554
|
-
|
555
|
-
|
556
|
-
|
557
|
-
|
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>;
|
521
|
+
DisplayIf: React$1.FC<DisplayIfProps<TFieldValues>>;
|
522
|
+
ArrayField: React$1.FC<ArrayFieldProps<TFieldValues>>;
|
523
|
+
ObjectField: React$1.FC<ObjectFieldProps<TFieldValues>>;
|
524
|
+
}
|
525
|
+
interface FormOptions<TFieldValues extends FieldValues = FieldValues, TContext extends object = object, TSchema = any, 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<TFieldValues extends FieldValues = FieldValues, TContext extends object = object, TSchema = any, TFieldTypes = FieldProps<TFieldValues>> extends UseFormProps<TFieldValues, TContext>, Omit<HTMLChakraProps<'form'>, 'children' | 'onChange' | 'onSubmit' | 'onError'>, FormOptions<TFieldValues, TContext, TSchema, TFieldTypes> {
|
558
560
|
}
|
559
561
|
/**
|
560
|
-
*
|
562
|
+
* The wrapper component provides context, state, and focus management.
|
561
563
|
*
|
562
564
|
* @see Docs https://saas-ui.dev/docs/components/forms/form
|
563
565
|
*/
|
564
|
-
declare const
|
565
|
-
|
566
|
-
|
566
|
+
declare const Form$1: (<TFieldValues extends FieldValues, TContext extends object = object, TSchema = any, TFieldTypes = FieldProps<TFieldValues>>(props: FormProps<TFieldValues, TContext, TSchema, TFieldTypes> & {
|
567
|
+
ref?: React$1.ForwardedRef<HTMLFormElement> | undefined;
|
568
|
+
}) => React$1.ReactElement) & {
|
569
|
+
displayName?: string | undefined;
|
567
570
|
};
|
571
|
+
type GetResolver = <TFieldValues extends FieldValues, TContext extends object>(schema: any) => (values: TFieldValues, context: TContext | undefined, options: ResolverOptions<TFieldValues>) => Promise<ResolverResult<TFieldValues>>;
|
572
|
+
|
573
|
+
interface DisplayFieldProps extends FormControlProps, Omit<FieldProps, 'type' | 'label'> {
|
574
|
+
}
|
575
|
+
/**
|
576
|
+
*
|
577
|
+
*
|
578
|
+
* @see Docs https://saas-ui.dev/
|
579
|
+
*/
|
580
|
+
declare const DisplayField: React$1.FC<DisplayFieldProps>;
|
581
|
+
declare const FormValue: React$1.FC<{
|
582
|
+
name: string;
|
583
|
+
}>;
|
584
|
+
|
585
|
+
interface Option {
|
586
|
+
value: string;
|
587
|
+
label?: string;
|
588
|
+
[key: string]: unknown;
|
589
|
+
}
|
590
|
+
type FieldRules = Pick<RegisterOptions, 'required' | 'min' | 'max' | 'maxLength' | 'minLength' | 'pattern'>;
|
591
|
+
/**
|
592
|
+
* Form field component.
|
593
|
+
*
|
594
|
+
* Build-in types:
|
595
|
+
* text, number, password, textarea, select, native-select, checkbox, radio, switch, pin
|
596
|
+
*
|
597
|
+
* Will default to a text field if there is no matching type.
|
598
|
+
|
599
|
+
* @see Docs https://saas-ui.dev/docs/components/forms/field
|
600
|
+
*/
|
601
|
+
declare const Field: (<TFieldValues extends FieldValues>(props: FieldProps<TFieldValues> & {
|
602
|
+
ref?: React$1.ForwardedRef<FocusableElement> | undefined;
|
603
|
+
}) => React$1.ReactElement) & {
|
604
|
+
displayName?: string | undefined;
|
605
|
+
};
|
606
|
+
|
607
|
+
interface FieldsProps<TSchema = any> {
|
608
|
+
schema?: TSchema;
|
609
|
+
fieldResolver?: FieldResolver;
|
610
|
+
focusFirstField?: boolean;
|
611
|
+
}
|
612
|
+
declare const AutoFields: React$1.FC<FieldsProps>;
|
613
|
+
|
614
|
+
declare const FieldsProvider: React__default.FC<{
|
615
|
+
value: Record<string, React__default.FC<any>>;
|
616
|
+
children: React__default.ReactNode;
|
617
|
+
}>;
|
618
|
+
declare const useField: (type: string) => React__default.FC<any>;
|
568
619
|
|
569
620
|
interface StepState {
|
570
621
|
name: string;
|
@@ -661,6 +712,38 @@ interface NextButtonProps extends Omit<ButtonProps, 'children'> {
|
|
661
712
|
*/
|
662
713
|
declare const NextButton: React$1.FC<NextButtonProps>;
|
663
714
|
|
715
|
+
type FormProviderProps<TFieldValues extends FieldValues = FieldValues, TContext = any, TSchema = any> = FormProviderProps$1<TFieldValues, TContext> & {
|
716
|
+
fieldResolver?: FieldResolver;
|
717
|
+
schema?: TSchema;
|
718
|
+
fields?: {
|
719
|
+
[key: string]: unknown;
|
720
|
+
};
|
721
|
+
};
|
722
|
+
declare const useFormContext: <TFieldValues extends FieldValues = FieldValues, TContext = any, TSchema = any>() => {
|
723
|
+
fieldResolver?: FieldResolver | undefined;
|
724
|
+
schema?: any;
|
725
|
+
fields?: {
|
726
|
+
[key: string]: unknown;
|
727
|
+
} | undefined;
|
728
|
+
watch: react_hook_form.UseFormWatch<FieldValues>;
|
729
|
+
getValues: react_hook_form.UseFormGetValues<FieldValues>;
|
730
|
+
getFieldState: react_hook_form.UseFormGetFieldState<FieldValues>;
|
731
|
+
setError: react_hook_form.UseFormSetError<FieldValues>;
|
732
|
+
clearErrors: react_hook_form.UseFormClearErrors<FieldValues>;
|
733
|
+
setValue: react_hook_form.UseFormSetValue<FieldValues>;
|
734
|
+
trigger: react_hook_form.UseFormTrigger<FieldValues>;
|
735
|
+
formState: react_hook_form.FormState<FieldValues>;
|
736
|
+
resetField: react_hook_form.UseFormResetField<FieldValues>;
|
737
|
+
reset: react_hook_form.UseFormReset<FieldValues>;
|
738
|
+
handleSubmit: react_hook_form.UseFormHandleSubmit<FieldValues>;
|
739
|
+
unregister: react_hook_form.UseFormUnregister<FieldValues>;
|
740
|
+
control: react_hook_form.Control<FieldValues, any>;
|
741
|
+
register: react_hook_form.UseFormRegister<FieldValues>;
|
742
|
+
setFocus: react_hook_form.UseFormSetFocus<FieldValues>;
|
743
|
+
};
|
744
|
+
type UseFormReturn<TFieldValues extends FieldValues = FieldValues, TContext = any, TSchema = any> = ReturnType<typeof useFormContext>;
|
745
|
+
declare const FormProvider: <TFieldValues extends FieldValues = FieldValues, TContext = any, TSchema = any>(props: FormProviderProps<TFieldValues, TContext, TSchema>) => JSX.Element;
|
746
|
+
|
664
747
|
interface WatchFieldProps<Value = unknown, TFieldValues extends FieldValues = FieldValues> {
|
665
748
|
name: string;
|
666
749
|
defaultValue?: Value;
|
@@ -681,11 +764,19 @@ declare const BaseField: React$1.FC<BaseFieldProps>;
|
|
681
764
|
|
682
765
|
interface CreateFormProps<FieldDefs> {
|
683
766
|
resolver?: GetResolver;
|
767
|
+
fieldResolver?: GetFieldResolver;
|
684
768
|
fields?: FieldDefs extends Record<string, React__default.FC<any>> ? FieldDefs : never;
|
685
769
|
}
|
686
|
-
declare function createForm<FieldDefs, Schema = any>({ resolver, fields, }?: CreateFormProps<FieldDefs>): <TFieldValues extends FieldValues, TContext extends object = object, TSchema extends Schema = Schema>(props: Omit<FormProps<TFieldValues, TContext, TSchema, FieldProps<TFieldValues>>, "children"> & {
|
687
|
-
children
|
688
|
-
|
770
|
+
declare function createForm<FieldDefs, Schema = any>({ resolver, fieldResolver, fields, }?: CreateFormProps<FieldDefs>): (<TFieldValues extends FieldValues, TContext extends object = object, TSchema extends Schema = Schema>(props: Omit<FormProps<TFieldValues, TContext, TSchema, FieldProps<TFieldValues>>, "children" | "fields"> & {
|
771
|
+
children?: FormChildren<FieldDefs, TFieldValues, TContext>;
|
772
|
+
fields?: (FieldOverrides<FieldDefs, TFieldValues, react_hook_form.Path<TFieldValues>> & {
|
773
|
+
submit?: SubmitButtonProps | undefined;
|
774
|
+
}) | undefined;
|
775
|
+
} & {
|
776
|
+
ref?: React__default.ForwardedRef<HTMLFormElement> | undefined;
|
777
|
+
}) => React__default.ReactElement) & {
|
778
|
+
displayName?: string | undefined;
|
779
|
+
};
|
689
780
|
|
690
781
|
interface CreateFieldOptions {
|
691
782
|
isControlled?: boolean;
|
@@ -702,4 +793,15 @@ interface CreateFieldOptions {
|
|
702
793
|
*/
|
703
794
|
declare const createField: <TProps extends object>(component: React$1.FC<TProps>, options?: CreateFieldOptions) => React$1.FC<TProps & BaseFieldProps<react_hook_form.FieldValues, string>>;
|
704
795
|
|
705
|
-
|
796
|
+
declare const Form: (<TFieldValues extends react_hook_form.FieldValues, TContext extends object = object, TSchema extends any = any>(props: Omit<FormProps<TFieldValues, TContext, TSchema, FieldProps<TFieldValues>>, "children" | "fields"> & {
|
797
|
+
children?: FormChildren<unknown, TFieldValues, TContext>;
|
798
|
+
fields?: (FieldOverrides<unknown, TFieldValues, react_hook_form.Path<TFieldValues>> & {
|
799
|
+
submit?: SubmitButtonProps | undefined;
|
800
|
+
}) | undefined;
|
801
|
+
} & {
|
802
|
+
ref?: React$1.ForwardedRef<HTMLFormElement> | undefined;
|
803
|
+
}) => React$1.ReactElement<any, string | React$1.JSXElementConstructor<any>>) & {
|
804
|
+
displayName?: string | undefined;
|
805
|
+
};
|
806
|
+
|
807
|
+
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, DefaultFields, DisplayField, DisplayFieldProps, DisplayIf, DisplayIfProps, Field, FieldOptions, FieldProps, FieldResolver, FieldRules, FieldsProps, FieldsProvider, Form, FormLayout, FormLayoutProps, FormLegend, FormProps, FormProvider, FormRenderContext, FormStep, FormStepOptions, FormStepProps, FormStepSubmitHandler, FormStepper, FormStepperProps, 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, SubmitButton, SubmitButtonProps, SwitchField, TextareaField, UseArrayFieldReturn, UseArrayFieldRowProps, UseArrayFieldRowReturn, UseFormStepProps, UseStepFormProps, UseStepFormReturn, WatchField, WatchFieldProps, WithFields, createField, createForm, defaultFieldTypes, objectFieldResolver, useArrayField, useArrayFieldAddButton, useArrayFieldContext, useArrayFieldRemoveButton, useArrayFieldRow, useArrayFieldRowContext, useField, useFormContext, useFormStep, useStepForm, useStepFormContext };
|