@saas-ui/forms 2.0.0-rc.26 → 2.0.0-rc.27
Sign up to get free protection for your applications and to get access to all the features.
- package/CHANGELOG.md +8 -0
- package/dist/index.d.ts +109 -100
- package/dist/index.js.map +1 -1
- package/dist/index.mjs.map +1 -1
- package/dist/yup/index.d.ts +96 -69
- package/dist/yup/index.js +242 -3
- package/dist/yup/index.js.map +1 -1
- package/dist/yup/index.mjs +220 -4
- package/dist/yup/index.mjs.map +1 -1
- package/dist/zod/index.d.ts +92 -63
- package/dist/zod/index.js +242 -5
- package/dist/zod/index.js.map +1 -1
- package/dist/zod/index.mjs +220 -5
- package/dist/zod/index.mjs.map +1 -1
- package/package.json +2 -2
- package/src/default-fields.tsx +2 -0
- package/src/types.ts +30 -9
package/CHANGELOG.md
CHANGED
package/dist/index.d.ts
CHANGED
@@ -1,11 +1,11 @@
|
|
1
1
|
import * as React$1 from 'react';
|
2
2
|
import React__default from 'react';
|
3
3
|
import * as react_hook_form from 'react-hook-form';
|
4
|
-
import { FieldValues, FieldPath, RegisterOptions, UseFormReturn as UseFormReturn$1,
|
4
|
+
import { FieldValues, FieldPath, UseFieldArrayReturn, RegisterOptions, UseFormReturn as UseFormReturn$1, UseFormProps, WatchObserver, SubmitHandler, SubmitErrorHandler, ResolverOptions, ResolverResult, FormProviderProps as FormProviderProps$1 } from 'react-hook-form';
|
5
5
|
export { BatchFieldArrayUpdate, ChangeHandler, Control, Controller, ControllerFieldState, ControllerProps, ControllerRenderProps, CriteriaMode, CustomElement, DeepMap, DeepPartial, DeepPartialSkipArrayKey, DefaultValues, DelayCallback, EmptyObject, ErrorOption, EventType, FieldArray, FieldArrayMethodProps, FieldArrayWithId, Field as FieldDef, FieldElement, FieldError, FieldErrors, FieldName, FieldNamesMarkedBoolean, FieldRefs, FieldValue, FieldValues, FormProviderProps, FormState, FormStateProxy, FormStateSubjectRef, GetIsDirty, InternalFieldErrors, InternalFieldName, InternalNameSet, IsAny, IsFlatObject, KeepStateOptions, LiteralUnion, Message, Mode, MultipleFieldErrors, Names, NativeFieldValue, NestedValue, NonUndefined, Noop, Primitive, ReadFormState, Ref, RefCallBack, RegisterOptions, Resolver, ResolverError, ResolverOptions, ResolverResult, ResolverSuccess, SetFieldValue, SetValueConfig, Subjects, SubmitErrorHandler, SubmitHandler, TriggerConfig, UnpackNestedValue, UseControllerProps, UseControllerReturn, UseFieldArrayProps, UseFieldArrayReturn, UseFormClearErrors, UseFormGetValues, UseFormHandleSubmit, UseFormProps, UseFormRegister, UseFormRegisterReturn, UseFormReset, UseFormResetField, UseFormReturn, UseFormSetError, UseFormSetFocus, UseFormSetValue, UseFormStateProps, UseFormStateReturn, UseFormTrigger, UseFormUnregister, UseFormWatch, UseWatchProps, Validate, ValidateResult, ValidationMode, ValidationRule, ValidationValue, ValidationValueMessage, WatchInternal, WatchObserver, appendErrors, useController, useFieldArray, useForm, useFormState, useWatch } from 'react-hook-form';
|
6
6
|
import { MaybeRenderProp } from '@chakra-ui/react-utils';
|
7
7
|
import { StepsProps, StepsItemProps, UseStepperReturn, UseStepperProps } from '@saas-ui/core';
|
8
|
-
import { NumberInputProps as NumberInputProps$1, InputProps, RadioProps, RadioGroupProps, SystemProps, StackDirection, MenuProps, ButtonProps, MenuListProps, MenuItemOptionProps, SelectProps as SelectProps$1, TextareaProps, SwitchProps, CheckboxProps, UsePinInputProps,
|
8
|
+
import { NumberInputProps as NumberInputProps$1, InputProps, RadioProps, RadioGroupProps, SystemProps, StackDirection, MenuProps, ButtonProps, MenuListProps, MenuItemOptionProps, SelectProps as SelectProps$1, TextareaProps, SwitchProps, CheckboxProps, UsePinInputProps, ResponsiveValue, FormLabelProps, SimpleGridProps, FormControlProps, HTMLChakraProps, ThemingProps } from '@chakra-ui/react';
|
9
9
|
import { FocusableElement } from '@chakra-ui/utils';
|
10
10
|
import * as _chakra_ui_system_dist_system_types from '@chakra-ui/system/dist/system.types';
|
11
11
|
|
@@ -197,101 +197,19 @@ interface SubmitButtonProps extends ButtonProps {
|
|
197
197
|
*/
|
198
198
|
declare const SubmitButton: _chakra_ui_system_dist_system_types.ComponentWithAs<"button", SubmitButtonProps>;
|
199
199
|
|
200
|
-
|
201
|
-
label?: string;
|
202
|
-
value: string;
|
203
|
-
};
|
204
|
-
type FieldOptions<TOption extends FieldOption = FieldOption> = Array<string> | Array<TOption>;
|
205
|
-
type ValueOf<T> = T[keyof T];
|
206
|
-
type ShallowMerge<A, B> = Omit<A, keyof B> & B;
|
207
|
-
type Split<S extends string, D extends string> = string extends S ? string[] : S extends '' ? [] : S extends `${infer T}${D}${infer U}` ? [T, ...Split<U, D>] : [S];
|
208
|
-
type MapPath<T extends string[]> = T extends [infer U, ...infer R] ? U extends string ? `${U extends `${number}` ? '$' : U}${R[0] extends string ? '.' : ''}${R extends string[] ? MapPath<R> : ''}` : '' : '';
|
209
|
-
type TransformPath<T extends string> = MapPath<Split<T, '.'>>;
|
210
|
-
type ArrayFieldPath<Name extends string> = Name extends string ? TransformPath<Name> : never;
|
211
|
-
interface BaseFieldProps<TFieldValues extends FieldValues = FieldValues, TName extends FieldPath<TFieldValues> = FieldPath<TFieldValues>> extends Omit<FormControlProps, 'label' | 'type'> {
|
212
|
-
/**
|
213
|
-
* The field name
|
214
|
-
*/
|
215
|
-
name: TName | ArrayFieldPath<TName>;
|
216
|
-
/**
|
217
|
-
* The field label
|
218
|
-
*/
|
219
|
-
label?: string;
|
220
|
-
/**
|
221
|
-
* Hide the field label
|
222
|
-
*/
|
223
|
-
hideLabel?: boolean;
|
224
|
-
/**
|
225
|
-
* Field help text
|
226
|
-
*/
|
227
|
-
help?: string;
|
228
|
-
/**
|
229
|
-
* React hook form rules
|
230
|
-
*/
|
231
|
-
rules?: Omit<RegisterOptions<TFieldValues, TName>, 'valueAsNumber' | 'valueAsDate' | 'setValueAs' | 'disabled'>;
|
232
|
-
/**
|
233
|
-
* Build-in types:
|
234
|
-
* text, number, password, textarea, select, native-select, checkbox, radio, switch, pin
|
235
|
-
*
|
236
|
-
* Will default to a text field if there is no matching type.
|
237
|
-
*/
|
238
|
-
type?: string;
|
239
|
-
/**
|
240
|
-
* The input placeholder
|
241
|
-
*/
|
242
|
-
placeholder?: string;
|
243
|
-
}
|
244
|
-
type FieldPathWithArray<TFieldValues extends FieldValues, TName extends FieldPath<TFieldValues> = FieldPath<TFieldValues>> = TName | ArrayFieldPath<TName>;
|
245
|
-
type MergeFieldProps<FieldDefs, TFieldValues extends FieldValues = FieldValues, TName extends FieldPath<TFieldValues> = FieldPath<TFieldValues>> = ValueOf<{
|
246
|
-
[K in keyof FieldDefs]: FieldDefs[K] extends React.FC<infer Props> ? {
|
247
|
-
type?: K;
|
248
|
-
} & ShallowMerge<Props, BaseFieldProps<TFieldValues, TName>> : never;
|
249
|
-
}>;
|
250
|
-
type FieldProps<TFieldValues extends FieldValues = FieldValues> = MergeFieldProps<DefaultFields, TFieldValues>;
|
251
|
-
type FormChildren<FieldDefs, TFieldValues extends FieldValues = FieldValues, TContext extends object = object> = MaybeRenderProp<FormRenderContext<TFieldValues, TContext, MergeFieldProps<FieldDefs extends never ? DefaultFields : ShallowMerge<DefaultFields, FieldDefs>, TFieldValues>>>;
|
252
|
-
type DefaultFieldOverrides = {
|
253
|
-
submit?: SubmitButtonProps;
|
254
|
-
[key: string]: any;
|
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, ExtraOverrides = object> = TFormProps extends FormProps<infer TSchema, infer TFieldValues, infer TContext> ? Omit<TFormProps, 'children' | 'fields'> & {
|
260
|
-
children?: FormChildren<FieldDefs, TFieldValues, TContext>;
|
261
|
-
fields?: FieldOverrides<FieldDefs, TFieldValues> & {
|
262
|
-
submit?: SubmitButtonProps;
|
263
|
-
} & ExtraOverrides;
|
264
|
-
} : never;
|
265
|
-
|
266
|
-
type FieldResolver = {
|
267
|
-
getFields(): BaseFieldProps[];
|
268
|
-
getNestedFields(name: string): BaseFieldProps[];
|
269
|
-
};
|
270
|
-
type GetFieldResolver<TSchema = any> = (schema: TSchema) => FieldResolver;
|
271
|
-
interface SchemaField extends BaseFieldProps {
|
272
|
-
items?: SchemaField[];
|
273
|
-
properties?: Record<string, SchemaField>;
|
274
|
-
}
|
275
|
-
type ObjectSchema = Record<string, SchemaField>;
|
276
|
-
declare const objectFieldResolver: GetFieldResolver<ObjectSchema>;
|
277
|
-
|
278
|
-
interface DisplayIfProps<TFieldValues extends FieldValues = FieldValues, TName extends FieldPath<TFieldValues> = FieldPath<TFieldValues>> {
|
279
|
-
children: React$1.ReactElement;
|
200
|
+
interface ObjectFieldProps<TFieldValues extends FieldValues = FieldValues, TName extends FieldPath<TFieldValues> = FieldPath<TFieldValues>> extends BaseFieldProps {
|
280
201
|
name: TName;
|
281
|
-
|
282
|
-
|
283
|
-
|
284
|
-
condition?: (value: unknown, context: UseFormReturn$1<TFieldValues>) => boolean;
|
202
|
+
children: React$1.ReactNode;
|
203
|
+
columns?: ResponsiveValue<number>;
|
204
|
+
spacing?: ResponsiveValue<string | number>;
|
285
205
|
}
|
206
|
+
declare const FormLegend: (props: FormLabelProps) => JSX.Element;
|
286
207
|
/**
|
287
|
-
*
|
208
|
+
* The object field component.
|
288
209
|
*
|
289
|
-
* @see Docs https://saas-ui.dev/docs/components/forms/
|
210
|
+
* @see Docs https://saas-ui.dev/docs/components/forms/object-field
|
290
211
|
*/
|
291
|
-
declare const
|
292
|
-
<TFieldValues extends FieldValues = FieldValues, TName extends FieldPath<TFieldValues> = FieldPath<TFieldValues>>({ children, name, defaultValue, isDisabled, isExact, condition, }: DisplayIfProps<TFieldValues, TName>): React$1.ReactElement<any, string | React$1.JSXElementConstructor<any>> | null;
|
293
|
-
displayName: string;
|
294
|
-
};
|
212
|
+
declare const ObjectField: React$1.FC<ObjectFieldProps>;
|
295
213
|
|
296
214
|
interface FormLayoutProps extends SimpleGridProps {
|
297
215
|
}
|
@@ -502,19 +420,110 @@ interface ArrayFieldContainerProps extends Omit<ArrayFieldProps, 'children'> {
|
|
502
420
|
*/
|
503
421
|
declare const ArrayFieldContainer: React$1.ForwardRefExoticComponent<ArrayFieldContainerProps & React$1.RefAttributes<UseArrayFieldReturn>>;
|
504
422
|
|
505
|
-
|
423
|
+
type FieldOption = {
|
424
|
+
label?: string;
|
425
|
+
value: string;
|
426
|
+
};
|
427
|
+
type FieldOptions<TOption extends FieldOption = FieldOption> = Array<string> | Array<TOption>;
|
428
|
+
type ValueOf<T> = T[keyof T];
|
429
|
+
type ShallowMerge<A, B> = Omit<A, keyof B> & B;
|
430
|
+
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];
|
431
|
+
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> : ''}` : '' : '';
|
432
|
+
type TransformPath<T extends string> = MapPath<Split<T, '.'>>;
|
433
|
+
type ArrayFieldPath<Name extends string> = Name extends string ? TransformPath<Name> : never;
|
434
|
+
interface BaseFieldProps<TFieldValues extends FieldValues = FieldValues, TName extends FieldPath<TFieldValues> = FieldPath<TFieldValues>> extends Omit<FormControlProps, 'label' | 'type'> {
|
435
|
+
/**
|
436
|
+
* The field name
|
437
|
+
*/
|
438
|
+
name: TName | ArrayFieldPath<TName>;
|
439
|
+
/**
|
440
|
+
* The field label
|
441
|
+
*/
|
442
|
+
label?: string;
|
443
|
+
/**
|
444
|
+
* Hide the field label
|
445
|
+
*/
|
446
|
+
hideLabel?: boolean;
|
447
|
+
/**
|
448
|
+
* Field help text
|
449
|
+
*/
|
450
|
+
help?: string;
|
451
|
+
/**
|
452
|
+
* React hook form rules
|
453
|
+
*/
|
454
|
+
rules?: Omit<RegisterOptions<TFieldValues, TName>, 'valueAsNumber' | 'valueAsDate' | 'setValueAs' | 'disabled'>;
|
455
|
+
/**
|
456
|
+
* Build-in types:
|
457
|
+
* text, number, password, textarea, select, native-select, checkbox, radio, switch, pin
|
458
|
+
*
|
459
|
+
* Will default to a text field if there is no matching type.
|
460
|
+
*/
|
461
|
+
type?: string;
|
462
|
+
/**
|
463
|
+
* The input placeholder
|
464
|
+
*/
|
465
|
+
placeholder?: string;
|
466
|
+
}
|
467
|
+
type FieldPathWithArray<TFieldValues extends FieldValues, TName extends FieldPath<TFieldValues> = FieldPath<TFieldValues>> = TName | ArrayFieldPath<TName>;
|
468
|
+
type MergeFieldProps<FieldDefs, TFieldValues extends FieldValues = FieldValues, TName extends FieldPath<TFieldValues> = FieldPath<TFieldValues>> = ValueOf<{
|
469
|
+
[K in keyof FieldDefs]: FieldDefs[K] extends React.FC<infer Props> ? {
|
470
|
+
type?: K;
|
471
|
+
} & ShallowMerge<Props, BaseFieldProps<TFieldValues, TName>> : never;
|
472
|
+
}>;
|
473
|
+
type FieldProps<TFieldValues extends FieldValues = FieldValues> = MergeFieldProps<DefaultFields, TFieldValues>;
|
474
|
+
type FormChildren<FieldDefs, TFieldValues extends FieldValues = FieldValues, TContext extends object = object> = MaybeRenderProp<FormRenderContext<TFieldValues, TContext, MergeFieldProps<FieldDefs extends never ? DefaultFields : ShallowMerge<DefaultFields, FieldDefs>, TFieldValues>>>;
|
475
|
+
type DefaultFieldOverrides = {
|
476
|
+
submit?: SubmitButtonProps;
|
477
|
+
[key: string]: any;
|
478
|
+
};
|
479
|
+
type MergeOverrideFieldProps<FieldDefs, TFieldValues extends FieldValues = FieldValues, TName extends FieldPath<TFieldValues> = FieldPath<TFieldValues>> = ValueOf<{
|
480
|
+
[K in keyof FieldDefs]: FieldDefs[K] extends React.FC<infer Props> ? {
|
481
|
+
type?: K;
|
482
|
+
} & Omit<ShallowMerge<Props, BaseFieldProps<TFieldValues, TName>>, 'name'> : never;
|
483
|
+
}>;
|
484
|
+
type FieldOverrides<FieldDefs, TFieldValues extends FieldValues = FieldValues, TName extends FieldPath<TFieldValues> = FieldPath<TFieldValues>> = {
|
485
|
+
[K in FieldPathWithArray<TFieldValues, TName>]?: MergeOverrideFieldProps<FieldDefs extends never ? DefaultFields : ShallowMerge<DefaultFields, FieldDefs>, TFieldValues> | ({
|
486
|
+
type?: 'object';
|
487
|
+
} & Omit<ObjectFieldProps<TFieldValues>, 'name' | 'children'>) | ({
|
488
|
+
type?: 'array';
|
489
|
+
} & Omit<ArrayFieldProps<TFieldValues>, 'name' | 'children'>);
|
490
|
+
};
|
491
|
+
type WithFields<TFormProps extends FormProps<any, any, any, any>, FieldDefs, ExtraOverrides = object> = TFormProps extends FormProps<infer TSchema, infer TFieldValues, infer TContext> ? Omit<TFormProps, 'children' | 'fields'> & {
|
492
|
+
children?: FormChildren<FieldDefs, TFieldValues, TContext>;
|
493
|
+
fields?: FieldOverrides<FieldDefs, TFieldValues> & {
|
494
|
+
submit?: SubmitButtonProps;
|
495
|
+
} & ExtraOverrides;
|
496
|
+
} : never;
|
497
|
+
|
498
|
+
type FieldResolver = {
|
499
|
+
getFields(): BaseFieldProps[];
|
500
|
+
getNestedFields(name: string): BaseFieldProps[];
|
501
|
+
};
|
502
|
+
type GetFieldResolver<TSchema = any> = (schema: TSchema) => FieldResolver;
|
503
|
+
interface SchemaField extends BaseFieldProps {
|
504
|
+
items?: SchemaField[];
|
505
|
+
properties?: Record<string, SchemaField>;
|
506
|
+
}
|
507
|
+
type ObjectSchema = Record<string, SchemaField>;
|
508
|
+
declare const objectFieldResolver: GetFieldResolver<ObjectSchema>;
|
509
|
+
|
510
|
+
interface DisplayIfProps<TFieldValues extends FieldValues = FieldValues, TName extends FieldPath<TFieldValues> = FieldPath<TFieldValues>> {
|
511
|
+
children: React$1.ReactElement;
|
506
512
|
name: TName;
|
507
|
-
|
508
|
-
|
509
|
-
|
513
|
+
defaultValue?: unknown;
|
514
|
+
isDisabled?: boolean;
|
515
|
+
isExact?: boolean;
|
516
|
+
condition?: (value: unknown, context: UseFormReturn$1<TFieldValues>) => boolean;
|
510
517
|
}
|
511
|
-
declare const FormLegend: (props: FormLabelProps) => JSX.Element;
|
512
518
|
/**
|
513
|
-
*
|
519
|
+
* Conditionally render parts of a form.
|
514
520
|
*
|
515
|
-
* @see Docs https://saas-ui.dev/docs/components/forms/
|
521
|
+
* @see Docs https://saas-ui.dev/docs/components/forms/form
|
516
522
|
*/
|
517
|
-
declare const
|
523
|
+
declare const DisplayIf: {
|
524
|
+
<TFieldValues extends FieldValues = FieldValues, TName extends FieldPath<TFieldValues> = FieldPath<TFieldValues>>({ children, name, defaultValue, isDisabled, isExact, condition, }: DisplayIfProps<TFieldValues, TName>): React$1.ReactElement<any, string | React$1.JSXElementConstructor<any>> | null;
|
525
|
+
displayName: string;
|
526
|
+
};
|
518
527
|
|
519
528
|
interface FormRenderContext<TFieldValues extends FieldValues = FieldValues, TContext extends object = object, TFieldTypes = FieldProps<TFieldValues>> extends UseFormReturn$1<TFieldValues, TContext> {
|
520
529
|
Field: React$1.FC<TFieldTypes & React$1.RefAttributes<FocusableElement>>;
|