@saas-ui/forms 2.0.0-next.3 → 2.0.0-next.5

Sign up to get free protection for your applications and to get access to all the features.
Files changed (49) hide show
  1. package/CHANGELOG.md +30 -0
  2. package/README.md +53 -6
  3. package/dist/ajv/index.d.ts +1 -1
  4. package/dist/ajv/index.js.map +1 -1
  5. package/dist/ajv/index.mjs.map +1 -1
  6. package/dist/index.d.ts +265 -166
  7. package/dist/index.js +2821 -556
  8. package/dist/index.js.map +1 -1
  9. package/dist/index.mjs +2814 -555
  10. package/dist/index.mjs.map +1 -1
  11. package/dist/yup/index.d.ts +98 -6
  12. package/dist/yup/index.js.map +1 -1
  13. package/dist/yup/index.mjs.map +1 -1
  14. package/dist/zod/index.d.ts +97 -4
  15. package/dist/zod/index.js.map +1 -1
  16. package/dist/zod/index.mjs.map +1 -1
  17. package/package.json +5 -3
  18. package/src/array-field.tsx +50 -30
  19. package/src/auto-form.tsx +7 -3
  20. package/src/base-field.tsx +59 -0
  21. package/src/create-field.tsx +143 -0
  22. package/src/create-form.tsx +31 -0
  23. package/src/default-fields.tsx +146 -0
  24. package/src/display-field.tsx +8 -9
  25. package/src/display-if.tsx +6 -5
  26. package/src/field-resolver.ts +1 -1
  27. package/src/field.tsx +14 -444
  28. package/src/fields-context.tsx +23 -0
  29. package/src/fields.tsx +18 -8
  30. package/src/form.tsx +27 -37
  31. package/src/index.ts +38 -0
  32. package/src/input-right-button/input-right-button.stories.tsx +1 -1
  33. package/src/input-right-button/input-right-button.tsx +0 -2
  34. package/src/layout.tsx +16 -11
  35. package/src/number-input/number-input.tsx +9 -5
  36. package/src/object-field.tsx +8 -7
  37. package/src/password-input/password-input.stories.tsx +23 -2
  38. package/src/password-input/password-input.tsx +5 -5
  39. package/src/pin-input/pin-input.tsx +1 -5
  40. package/src/radio/radio-input.stories.tsx +1 -1
  41. package/src/radio/radio-input.tsx +12 -10
  42. package/src/select/native-select.tsx +1 -4
  43. package/src/select/select.test.tsx +1 -1
  44. package/src/select/select.tsx +18 -14
  45. package/src/step-form.tsx +29 -11
  46. package/src/submit-button.tsx +5 -1
  47. package/src/types.ts +91 -0
  48. package/src/utils.ts +15 -0
  49. /package/src/radio/{radio.test.tsx → radio-input.test.tsx} +0 -0
package/dist/index.d.ts CHANGED
@@ -1,12 +1,12 @@
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';
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
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';
6
+ import { FieldValues, UseFormReturn, UseFormProps, ResolverOptions, ResolverResult, WatchObserver, SubmitHandler, SubmitErrorHandler, FieldPath, RegisterOptions, UseFieldArrayReturn } from 'react-hook-form';
7
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 * as _chakra_ui_system_dist_system_types from '@chakra-ui/system/dist/system.types';
8
9
  import { FocusableElement } from '@chakra-ui/utils';
9
- import { MaybeRenderProp } from '@chakra-ui/react-utils';
10
10
  import { UseStepperReturn, UseStepperProps, StepperStepsProps } from '@saas-ui/core';
11
11
 
12
12
  interface NumberInputOptions {
@@ -29,33 +29,32 @@ 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 Option$3 extends RadioProps {
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: Option$3[];
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;
50
+ interface SelectOption extends Omit<MenuItemOptionProps, 'value'>, FieldOption {
52
51
  }
53
52
  interface SelectOptions {
54
53
  /**
55
54
  * An array of options
56
55
  * If you leave this empty the children prop will be rendered.
57
56
  */
58
- options?: Option$2[];
57
+ options?: FieldOptions<SelectOption>;
59
58
  /**
60
59
  * Props passed to the MenuList.
61
60
  */
@@ -85,173 +84,61 @@ interface NativeSelectProps extends SelectProps$1, NativeSelectOptions {
85
84
  }
86
85
  declare const NativeSelect: _chakra_ui_system_dist_system_types.ComponentWithAs<"select", NativeSelectProps>;
87
86
 
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
87
  interface InputFieldProps extends InputProps {
178
88
  type?: string;
179
89
  leftAddon?: React$1.ReactNode;
180
90
  rightAddon?: React$1.ReactNode;
181
91
  }
182
- declare const InputField: React$1.FC<InputFieldProps & FieldProps<FieldValues, string>>;
92
+ declare const InputField: React$1.FC<InputFieldProps & BaseFieldProps<react_hook_form.FieldValues, string>>;
183
93
  interface NumberInputFieldProps extends NumberInputProps {
184
94
  type: 'number';
185
95
  }
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>>;
96
+ declare const NumberInputField: React$1.FC<NumberInputFieldProps & BaseFieldProps<react_hook_form.FieldValues, string>>;
97
+ declare const PasswordInputField: React$1.FC<PasswordInputProps & BaseFieldProps<react_hook_form.FieldValues, string>>;
98
+ declare const TextareaField: React$1.FC<TextareaProps & BaseFieldProps<react_hook_form.FieldValues, string>>;
99
+ declare const SwitchField: React$1.FC<SwitchProps & BaseFieldProps<react_hook_form.FieldValues, string>>;
100
+ declare const SelectField: React$1.FC<SelectProps & BaseFieldProps<react_hook_form.FieldValues, string>>;
101
+ declare const CheckboxField: React$1.FC<CheckboxProps & BaseFieldProps<react_hook_form.FieldValues, string>>;
102
+ declare const RadioField: React$1.FC<RadioInputProps & BaseFieldProps<react_hook_form.FieldValues, string>>;
103
+ declare const NativeSelectField: React$1.FC<NativeSelectProps & BaseFieldProps<react_hook_form.FieldValues, string>>;
194
104
  interface PinFieldProps extends Omit<UsePinInputProps, 'type'> {
195
105
  pinLength?: number;
196
106
  pinType?: 'alphanumeric' | 'number';
197
107
  spacing?: SystemProps['margin'];
198
108
  }
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;
109
+ declare const PinField: React$1.FC<PinFieldProps & BaseFieldProps<react_hook_form.FieldValues, string>>;
110
+ declare const defaultFieldTypes: {
111
+ text: React$1.FC<InputFieldProps & BaseFieldProps<react_hook_form.FieldValues, string>>;
112
+ email: React$1.FC<InputFieldProps & BaseFieldProps<react_hook_form.FieldValues, string>>;
113
+ url: React$1.FC<InputFieldProps & BaseFieldProps<react_hook_form.FieldValues, string>>;
114
+ phone: React$1.FC<InputFieldProps & BaseFieldProps<react_hook_form.FieldValues, string>>;
115
+ number: React$1.FC<NumberInputFieldProps & BaseFieldProps<react_hook_form.FieldValues, string>>;
116
+ password: React$1.FC<PasswordInputProps & BaseFieldProps<react_hook_form.FieldValues, string>>;
117
+ textarea: React$1.FC<TextareaProps & BaseFieldProps<react_hook_form.FieldValues, string>>;
118
+ switch: React$1.FC<SwitchProps & BaseFieldProps<react_hook_form.FieldValues, string>>;
119
+ select: React$1.FC<SelectProps & BaseFieldProps<react_hook_form.FieldValues, string>>;
120
+ checkbox: React$1.FC<CheckboxProps & BaseFieldProps<react_hook_form.FieldValues, string>>;
121
+ radio: React$1.FC<RadioInputProps & BaseFieldProps<react_hook_form.FieldValues, string>>;
122
+ pin: React$1.FC<PinFieldProps & BaseFieldProps<react_hook_form.FieldValues, string>>;
123
+ 'native-select': React$1.FC<NativeSelectProps & BaseFieldProps<react_hook_form.FieldValues, string>>;
224
124
  };
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
- }>;
125
+ type DefaultFields = typeof defaultFieldTypes;
232
126
 
233
127
  type FieldResolver = {
234
- getFields(): FieldProps[];
235
- getNestedFields(name: string): FieldProps[];
128
+ getFields(): BaseFieldProps[];
129
+ getNestedFields(name: string): BaseFieldProps[];
236
130
  };
237
- interface SchemaField extends FieldProps {
131
+ interface SchemaField extends BaseFieldProps {
238
132
  items?: SchemaField[];
239
133
  properties?: Record<string, SchemaField>;
240
134
  }
241
135
  type ObjectSchema = Record<string, SchemaField>;
242
136
  declare const objectFieldResolver: (schema: ObjectSchema) => FieldResolver;
243
137
 
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>>;
138
+ interface FormRenderContext<TFieldValues extends FieldValues = FieldValues, TContext extends object = object, TFieldTypes = FieldProps<TFieldValues>> extends UseFormReturn<TFieldValues, TContext> {
139
+ Field: React$1.FC<TFieldTypes>;
253
140
  }
254
- interface FormOptions<TFieldValues extends FieldValues = FieldValues, TContext extends object = object, TSchema = any> {
141
+ interface FormOptions<TFieldValues extends FieldValues = FieldValues, TContext extends object = object, TSchema = any, TFieldTypes = FieldProps<TFieldValues>> {
255
142
  /**
256
143
  * The form schema, supports Yup, Zod, and AJV.
257
144
  */
@@ -275,11 +162,16 @@ interface FormOptions<TFieldValues extends FieldValues = FieldValues, TContext e
275
162
  /**
276
163
  * The form children, can be a render prop or a ReactNode.
277
164
  */
278
- children?: MaybeRenderProp<FormRenderContext<TFieldValues, TContext>>;
165
+ children?: MaybeRenderProp<FormRenderContext<TFieldValues, TContext, TFieldTypes>>;
279
166
  }
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> {
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> {
281
168
  }
282
- declare const Form: (<TFieldValues extends FieldValues, TContext extends object = object, TSchema = any>(props: FormProps<TFieldValues, TContext, TSchema> & {
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> & {
283
175
  ref?: React$1.ForwardedRef<HTMLFormElement> | undefined;
284
176
  }) => React$1.ReactElement) & {
285
177
  displayName?: string | undefined;
@@ -288,10 +180,104 @@ declare const Form: (<TFieldValues extends FieldValues, TContext extends object
288
180
  };
289
181
  type GetResolver = <TFieldValues extends FieldValues, TContext extends object>(schema: any) => (values: TFieldValues, context: TContext | undefined, options: ResolverOptions<TFieldValues>) => Promise<ResolverResult<TFieldValues>>;
290
182
  type GetFieldResolver = (schema: any) => FieldResolver;
291
- interface CreateFormProps {
292
- resolver?: GetResolver;
183
+
184
+ type FieldOption = {
185
+ label: string;
186
+ value: string;
187
+ };
188
+ type FieldOptions<TOption extends FieldOption = FieldOption> = Array<string> | Array<TOption>;
189
+ type ValueOf<T> = T[keyof T];
190
+ type ShallowMerge<A, B> = Omit<A, keyof B> & B;
191
+ interface BaseFieldProps<TFieldValues extends FieldValues = FieldValues, TName extends FieldPath<TFieldValues> = FieldPath<TFieldValues>> extends Omit<FormControlProps, 'label' | 'type'> {
192
+ /**
193
+ * The field name
194
+ */
195
+ name: TName;
196
+ /**
197
+ * The field label
198
+ */
199
+ label?: string;
200
+ /**
201
+ * Hide the field label
202
+ */
203
+ hideLabel?: boolean;
204
+ /**
205
+ * Field help text
206
+ */
207
+ help?: string;
208
+ /**
209
+ * React hook form rules
210
+ */
211
+ rules?: Omit<RegisterOptions<TFieldValues, TName>, 'valueAsNumber' | 'valueAsDate' | 'setValueAs' | 'disabled'>;
212
+ /**
213
+ * Build-in types:
214
+ * text, number, password, textarea, select, native-select, checkbox, radio, switch, pin
215
+ *
216
+ * Will default to a text field if there is no matching type.
217
+ */
218
+ type?: string;
219
+ /**
220
+ * The input placeholder
221
+ */
222
+ placeholder?: string;
293
223
  }
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;
224
+ type MergeFieldProps<FieldDefs, TFieldValues extends FieldValues = FieldValues> = ValueOf<{
225
+ [K in keyof FieldDefs]: FieldDefs[K] extends React.FC<infer Props> ? {
226
+ type?: K;
227
+ } & ShallowMerge<Props, BaseFieldProps<TFieldValues>> : never;
228
+ }>;
229
+ type FieldProps<TFieldValues extends FieldValues = FieldValues> = MergeFieldProps<DefaultFields, TFieldValues>;
230
+ 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 WithFields<TFormProps extends FormProps<any, any, any, any>, FieldDefs> = TFormProps extends FormProps<infer TFieldValues, infer TContext> ? Omit<TFormProps, 'children'> & {
232
+ children: FormChildren<FieldDefs, TFieldValues, TContext>;
233
+ } : never;
234
+
235
+ interface DisplayFieldProps extends FormControlProps, Omit<FieldProps, 'type' | 'label'> {
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;
267
+ };
268
+
269
+ interface FieldsProps {
270
+ schema: any;
271
+ fieldResolver?: FieldResolver;
272
+ focusFirstField?: boolean;
273
+ }
274
+ declare const AutoFields: React$1.FC<FieldsProps>;
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>;
295
281
 
296
282
  interface AutoFormOptions {
297
283
  /**
@@ -313,14 +299,23 @@ interface AutoFormOptions {
313
299
  interface AutoFormProps<TFieldValues extends FieldValues, TContext extends object = object> extends Omit<FormProps<TFieldValues, TContext>, 'schema' | 'children'>, AutoFormOptions {
314
300
  children?: React$1.ReactNode;
315
301
  }
302
+ /**
303
+ * The wrapper component that manages context and state.
304
+ *
305
+ * @see Docs https://saas-ui.dev/docs/components/forms/auto-form
306
+ */
316
307
  declare const AutoForm: _chakra_ui_system_dist_system_types.ComponentWithAs<_chakra_ui_system_dist_system_types.As<any>, AutoFormProps<FieldValues, object>>;
317
308
 
318
- type FormLayoutProps = SimpleGridProps;
309
+ interface FormLayoutProps extends SimpleGridProps {
310
+ }
319
311
  /**
320
- * FormLayout
312
+ * Create consistent field spacing and positioning.
313
+ *
321
314
  *
322
315
  * Renders form items in a `SimpleGrid`
323
316
  * @see https://chakra-ui.com/docs/layout/simple-grid
317
+ *
318
+ * @see https://saas-ui.dev/docs/components/forms/form
324
319
  */
325
320
  declare const FormLayout: {
326
321
  ({ children, ...props }: FormLayoutProps): JSX.Element;
@@ -343,6 +338,11 @@ interface SubmitButtonProps extends ButtonProps {
343
338
  */
344
339
  disableIfInvalid?: boolean;
345
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
346
  declare const SubmitButton: _chakra_ui_system_dist_system_types.ComponentWithAs<"button", SubmitButtonProps>;
347
347
 
348
348
  interface UseArrayFieldReturn extends UseFieldArrayReturn {
@@ -460,6 +460,11 @@ interface ArrayFieldRowProps extends FormLayoutProps {
460
460
  */
461
461
  children: React$1.ReactNode;
462
462
  }
463
+ /**
464
+ * Render prop component, to get access to the internal fields state. Must be a child of ArrayFieldContainer.
465
+ *
466
+ * @see Docs https://saas-ui.dev/docs/components/forms/array-field
467
+ */
463
468
  declare const ArrayFieldRow: React$1.FC<ArrayFieldRowProps>;
464
469
  interface ArrayFieldRowFieldsProps extends FormLayoutProps {
465
470
  /**
@@ -475,16 +480,41 @@ interface ArrayFieldRowFieldsProps extends FormLayoutProps {
475
480
  */
476
481
  children: React$1.ReactNode;
477
482
  }
483
+ /**
484
+ * Add the name prefix to the fields and acts as a horizontal form layout by default.
485
+ *
486
+ * @see Docs https://saas-ui.dev/docs/components/forms/array-field
487
+ */
478
488
  declare const ArrayFieldRowFields: React$1.FC<ArrayFieldRowFieldsProps>;
489
+ /**
490
+ * The row container component providers row context.
491
+ *
492
+ * @see Docs https://saas-ui.dev/docs/components/forms/array-field
493
+ */
479
494
  declare const ArrayFieldRowContainer: React$1.FC<ArrayFieldRowProps>;
495
+ /**
496
+ * The default remove button.
497
+ *
498
+ * @see Docs https://saas-ui.dev/docs/components/forms/array-field
499
+ */
480
500
  declare const ArrayFieldRemoveButton: React$1.FC<ArrayFieldButtonProps>;
501
+ /**
502
+ * The default add button.
503
+ *
504
+ * @see Docs https://saas-ui.dev/docs/components/forms/array-field
505
+ */
481
506
  declare const ArrayFieldAddButton: React$1.FC<ArrayFieldButtonProps>;
482
- interface ArrayFieldProps extends ArrayFieldOptions, Omit<FieldProps, 'defaultValue'> {
507
+ interface ArrayFieldProps extends ArrayFieldOptions, Omit<BaseFieldProps, 'defaultValue'> {
483
508
  }
484
509
  interface ArrayField {
485
510
  id: string;
486
511
  [key: string]: unknown;
487
512
  }
513
+ /**
514
+ * The wrapper component that composes the default ArrayField functionality.
515
+ *
516
+ * @see Docs https://saas-ui.dev/docs/components/forms/array-field
517
+ */
488
518
  declare const ArrayField: ((props: ArrayFieldProps & {
489
519
  ref?: React$1.ForwardedRef<UseArrayFieldReturn>;
490
520
  }) => React$1.ReactElement) & {
@@ -497,15 +527,25 @@ declare const ArrayFieldRows: {
497
527
  ({ children, }: ArrayFieldRowsProps): React$1.ReactElement | null;
498
528
  displayName: string;
499
529
  };
530
+ /**
531
+ * The container component provides context and state management.
532
+ *
533
+ * @see Docs https://saas-ui.dev/docs/components/forms/array-field
534
+ */
500
535
  declare const ArrayFieldContainer: React$1.ForwardRefExoticComponent<ArrayFieldProps & React$1.RefAttributes<UseArrayFieldReturn>>;
501
536
 
502
- interface ObjectFieldProps extends FieldProps {
537
+ interface ObjectFieldProps extends BaseFieldProps {
503
538
  name: string;
504
539
  children: React$1.ReactNode;
505
540
  columns?: ResponsiveValue<number>;
506
541
  spacing?: ResponsiveValue<string | number>;
507
542
  }
508
543
  declare const FormLegend: (props: FormLabelProps) => JSX.Element;
544
+ /**
545
+ * The object field component.
546
+ *
547
+ * @see Docs https://saas-ui.dev/docs/components/forms/object-field
548
+ */
509
549
  declare const ObjectField: React$1.FC<ObjectFieldProps>;
510
550
 
511
551
  interface DisplayIfProps<TFieldValues extends FieldValues = FieldValues> {
@@ -516,6 +556,11 @@ interface DisplayIfProps<TFieldValues extends FieldValues = FieldValues> {
516
556
  isExact?: boolean;
517
557
  condition?: (value: unknown, context: UseFormReturn<TFieldValues>) => boolean;
518
558
  }
559
+ /**
560
+ * Conditionally render parts of a form.
561
+ *
562
+ * @see Docs https://saas-ui.dev/docs/components/forms/form
563
+ */
519
564
  declare const DisplayIf: {
520
565
  <TFieldValues extends FieldValues = FieldValues>({ children, name, defaultValue, isDisabled, isExact, condition, }: DisplayIfProps<TFieldValues>): React$1.ReactElement<any, string | React$1.JSXElementConstructor<any>> | null;
521
566
  displayName: string;
@@ -560,6 +605,11 @@ declare function useFormStep(props: UseFormStepProps): StepState;
560
605
 
561
606
  interface StepFormProps<TFieldValues extends FieldValues = FieldValues, TContext extends object = object> extends UseStepFormProps<TFieldValues> {
562
607
  }
608
+ /**
609
+ * The wrapper component provides context, state, and focus management.
610
+ *
611
+ * @see Docs https://saas-ui.dev/docs/components/forms/step-form
612
+ */
563
613
  declare const StepForm: <TFieldValues extends FieldValues>(props: StepFormProps<TFieldValues, object> & {
564
614
  ref?: React$1.ForwardedRef<HTMLFormElement> | undefined;
565
615
  }) => React$1.ReactElement;
@@ -579,16 +629,36 @@ interface FormStepOptions {
579
629
  }
580
630
  interface FormStepperProps extends StepperStepsProps, ThemingProps<'Stepper'> {
581
631
  }
632
+ /**
633
+ * Renders a stepper that displays progress above the form.
634
+ *
635
+ * @see Docs https://saas-ui.dev/docs/components/forms/step-form
636
+ */
582
637
  declare const FormStepper: React$1.FC<FormStepperProps>;
583
638
  interface FormStepProps extends FormStepOptions, Omit<HTMLChakraProps<'div'>, 'onSubmit'> {
584
639
  onSubmit?: FormStepSubmitHandler;
585
640
  }
641
+ /**
642
+ * The form step containing fields for a specific step.
643
+ *
644
+ * @see Docs https://saas-ui.dev/docs/components/forms/step-form
645
+ */
586
646
  declare const FormStep: React$1.FC<FormStepProps>;
647
+ /**
648
+ * A button that this opens the previous step when clicked. Disabled on the first step.
649
+ *
650
+ * @see Docs https://saas-ui.dev/docs/components/forms/step-form
651
+ */
587
652
  declare const PrevButton: React$1.FC<ButtonProps>;
588
653
  interface NextButtonProps extends Omit<ButtonProps, 'children'> {
589
654
  submitLabel?: string;
590
655
  label?: string;
591
656
  }
657
+ /**
658
+ * A button that submits the active step.
659
+ *
660
+ * @see Docs https://saas-ui.dev/docs/components/forms/step-form
661
+ */
592
662
  declare const NextButton: React$1.FC<NextButtonProps>;
593
663
 
594
664
  interface WatchFieldProps<Value = unknown, TFieldValues extends FieldValues = FieldValues> {
@@ -603,4 +673,33 @@ declare const WatchField: <Value = unknown, TFieldValues extends FieldValues = F
603
673
  type InputRightButtonProps = ButtonProps;
604
674
  declare const InputRightButton: _chakra_ui_system_dist_system_types.ComponentWithAs<"div", ButtonProps>;
605
675
 
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 };
676
+ /**
677
+ * The default BaseField component
678
+ * Composes the Chakra UI FormControl component, with FormLabel, FormHelperText and FormErrorMessage.
679
+ */
680
+ declare const BaseField: React$1.FC<BaseFieldProps>;
681
+
682
+ interface CreateFormProps<FieldDefs> {
683
+ resolver?: GetResolver;
684
+ fields?: FieldDefs extends Record<string, React__default.FC<any>> ? FieldDefs : never;
685
+ }
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: FormChildren<FieldDefs, TFieldValues, TContext>;
688
+ }) => JSX.Element;
689
+
690
+ interface CreateFieldOptions {
691
+ isControlled?: boolean;
692
+ hideLabel?: boolean;
693
+ BaseField?: React$1.FC<any>;
694
+ }
695
+ /**
696
+ * Register a new field type
697
+ * @param type The name for this field in kebab-case, eg `email` or `array-field`
698
+ * @param component The React component
699
+ * @param options
700
+ * @param options.isControlled Set this to true if this is a controlled field.
701
+ * @param options.hideLabel Hide the field label, for example for the checkbox field.
702
+ */
703
+ declare const createField: <TProps extends object>(component: React$1.FC<TProps>, options?: CreateFieldOptions) => React$1.FC<TProps & BaseFieldProps<react_hook_form.FieldValues, string>>;
704
+
705
+ export { ArrayField, ArrayFieldAddButton, ArrayFieldButtonProps, ArrayFieldContainer, ArrayFieldOptions, ArrayFieldProps, ArrayFieldProvider, ArrayFieldRemoveButton, ArrayFieldRow, ArrayFieldRowContainer, ArrayFieldRowFields, ArrayFieldRowFieldsProps, ArrayFieldRowProvider, ArrayFieldRows, ArrayFieldRowsProps, AutoFields, AutoForm, AutoFormProps, BaseField, BaseFieldProps, CheckboxField, CreateFieldOptions, CreateFormProps, DefaultFields, DisplayField, DisplayFieldProps, DisplayIf, DisplayIfProps, Field, FieldOptions, FieldProps, FieldResolver, FieldRules, FieldsProps, FieldsProvider, Form, FormLayout, FormLayoutProps, FormLegend, FormProps, FormRenderContext, 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, RadioField, RadioInput, RadioInputProps, RadioOption, RadioOptions, Select, SelectField, 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, useFormStep, useStepForm, useStepFormContext };