@saas-ui/forms 2.0.2 → 2.0.4
Sign up to get free protection for your applications and to get access to all the features.
- package/CHANGELOG.md +12 -0
- package/dist/index.d.ts +75 -73
- package/dist/index.js +2 -2
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +2 -2
- package/dist/index.mjs.map +1 -1
- package/dist/yup/index.d.ts +102 -37
- package/dist/yup/index.js.map +1 -1
- package/dist/yup/index.mjs.map +1 -1
- package/dist/zod/index.d.ts +105 -40
- package/dist/zod/index.js.map +1 -1
- package/dist/zod/index.mjs.map +1 -1
- package/package.json +1 -1
- package/src/create-step-form.tsx +16 -22
- package/src/index.ts +2 -2
- package/src/step-form.tsx +2 -4
- package/src/types.ts +40 -1
- package/src/use-step-form.tsx +9 -13
package/CHANGELOG.md
CHANGED
@@ -1,5 +1,17 @@
|
|
1
1
|
# @saas-ui/forms
|
2
2
|
|
3
|
+
## 2.0.4
|
4
|
+
|
5
|
+
### Patch Changes
|
6
|
+
|
7
|
+
- 3b5567c6: Fixed issue where StepForm would not render custom fields
|
8
|
+
|
9
|
+
## 2.0.3
|
10
|
+
|
11
|
+
### Patch Changes
|
12
|
+
|
13
|
+
- 8c7ee0be: Fixed issue where custom StepForm field types would not propagate.
|
14
|
+
|
3
15
|
## 2.0.2
|
4
16
|
|
5
17
|
### Patch Changes
|
package/dist/index.d.ts
CHANGED
@@ -3,10 +3,10 @@ import React__default from 'react';
|
|
3
3
|
import * as react_hook_form from 'react-hook-form';
|
4
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
|
-
import { MaybeRenderProp } from '@chakra-ui/react-utils';
|
7
|
-
import { StepsProps, StepsItemProps, UseStepperReturn, UseStepperProps } from '@saas-ui/core';
|
8
6
|
import { NumberInputProps as NumberInputProps$1, InputProps, RadioProps, RadioGroupProps, SystemProps, StackDirection, MenuProps, ThemingProps, ButtonProps, MenuListProps, MenuItemOptionProps, SelectProps as SelectProps$1, TextareaProps, SwitchProps, CheckboxProps, UsePinInputProps, ResponsiveValue, FormLabelProps, SimpleGridProps, FormControlProps, HTMLChakraProps } from '@chakra-ui/react';
|
7
|
+
import { UseStepperReturn, UseStepperProps, StepsProps, StepsItemProps } from '@saas-ui/core';
|
9
8
|
import { FocusableElement } from '@chakra-ui/utils';
|
9
|
+
import { MaybeRenderProp } from '@chakra-ui/react-utils';
|
10
10
|
import * as _chakra_ui_system_dist_system_types from '@chakra-ui/system/dist/system.types';
|
11
11
|
|
12
12
|
interface NumberInputOptions {
|
@@ -494,6 +494,13 @@ type WithFields<TFormProps extends FormProps<any, any, any, any>, FieldDefs, Ext
|
|
494
494
|
submit?: SubmitButtonProps;
|
495
495
|
} & ExtraOverrides;
|
496
496
|
} : never;
|
497
|
+
type StepFormChildren<FieldDefs, TSteps extends StepsOptions<any> = StepsOptions<any>, TFieldValues extends FieldValues = FieldValues, TContext extends object = object> = MaybeRenderProp<StepFormRenderContext<TSteps, TFieldValues, TContext, MergeFieldProps<FieldDefs extends never ? DefaultFields : ShallowMerge<DefaultFields, FieldDefs>, TFieldValues>>>;
|
498
|
+
type WithStepFields<TStepFormProps extends UseStepFormProps<any, any, any>, FieldDefs, ExtraOverrides = object> = TStepFormProps extends UseStepFormProps<infer TSteps, infer TFieldValues, infer TContext> ? Omit<TStepFormProps, 'children' | 'fields'> & {
|
499
|
+
children?: StepFormChildren<FieldDefs, TSteps, TFieldValues, TContext>;
|
500
|
+
fields?: FieldOverrides<FieldDefs, TFieldValues> & {
|
501
|
+
submit?: SubmitButtonProps;
|
502
|
+
} & ExtraOverrides;
|
503
|
+
} : never;
|
497
504
|
|
498
505
|
type FieldResolver = {
|
499
506
|
getFields(): BaseFieldProps[];
|
@@ -580,6 +587,56 @@ type FormComponent = (<TSchema = unknown, TFieldValues extends FieldValues = Fie
|
|
580
587
|
};
|
581
588
|
type GetResolver = <TFieldValues extends FieldValues, TContext extends object>(schema: unknown) => (values: TFieldValues, context: TContext | undefined, options: ResolverOptions<TFieldValues>) => Promise<ResolverResult<TFieldValues>>;
|
582
589
|
|
590
|
+
interface StepState {
|
591
|
+
name: string;
|
592
|
+
schema?: any;
|
593
|
+
resolver?: any;
|
594
|
+
isActive?: boolean;
|
595
|
+
isCompleted?: boolean;
|
596
|
+
onSubmit?: FormStepSubmitHandler;
|
597
|
+
}
|
598
|
+
type FormStepSubmitHandler<TFieldValues extends FieldValues = FieldValues> = (data: TFieldValues, stepper: UseStepperReturn) => Promise<void>;
|
599
|
+
interface StepFormContext extends UseStepperReturn {
|
600
|
+
updateStep(state: StepState): void;
|
601
|
+
steps: Record<string, StepState>;
|
602
|
+
}
|
603
|
+
declare const StepFormProvider: React$1.Provider<StepFormContext>;
|
604
|
+
declare const useStepFormContext: () => StepFormContext;
|
605
|
+
|
606
|
+
type StepName<T extends {
|
607
|
+
[k: number]: {
|
608
|
+
readonly name: string;
|
609
|
+
};
|
610
|
+
}> = T[number]['name'];
|
611
|
+
interface StepFormRenderContext<TSteps extends StepsOptions<any> = StepsOptions<any>, TFieldValues extends FieldValues = FieldValues, TContext extends object = object, TFieldTypes = FieldProps<TFieldValues>> extends UseStepFormReturn<TFieldValues> {
|
612
|
+
Field: React$1.FC<TFieldTypes & React$1.RefAttributes<FocusableElement>>;
|
613
|
+
FormStep: React$1.FC<FormStepProps<StepName<TSteps>>>;
|
614
|
+
DisplayIf: React$1.FC<DisplayIfProps<TFieldValues>>;
|
615
|
+
ArrayField: React$1.FC<ArrayFieldProps<TFieldValues> & React$1.RefAttributes<UseArrayFieldReturn>>;
|
616
|
+
ObjectField: React$1.FC<ObjectFieldProps<TFieldValues>>;
|
617
|
+
}
|
618
|
+
interface UseStepFormProps<TSteps extends StepsOptions<any> = StepsOptions<any>, TFieldValues extends FieldValues = FieldValues, TContext extends object = object> extends Omit<UseStepperProps, 'onChange'>, Omit<FormProps<any, TFieldValues, TContext>, 'children'> {
|
619
|
+
steps?: TSteps;
|
620
|
+
children: StepFormChildren<any, TSteps, TFieldValues, TContext>;
|
621
|
+
}
|
622
|
+
interface UseStepFormReturn<TFieldValues extends FieldValues = FieldValues> extends UseStepperReturn {
|
623
|
+
getFormProps(): {
|
624
|
+
onSubmit: SubmitHandler<TFieldValues>;
|
625
|
+
schema?: any;
|
626
|
+
resolver?: any;
|
627
|
+
};
|
628
|
+
updateStep(step: any): void;
|
629
|
+
steps: Record<string, any>;
|
630
|
+
}
|
631
|
+
declare function useStepForm<TSteps extends StepsOptions<any> = StepsOptions<any>, TFieldValues extends FieldValues = FieldValues, TContext extends object = object>(props: UseStepFormProps<TSteps, TFieldValues, TContext>): UseStepFormReturn<TFieldValues>;
|
632
|
+
interface UseFormStepProps {
|
633
|
+
name: string;
|
634
|
+
schema?: any;
|
635
|
+
resolver?: any;
|
636
|
+
onSubmit?: FormStepSubmitHandler;
|
637
|
+
}
|
638
|
+
declare function useFormStep(props: UseFormStepProps): StepState;
|
639
|
+
|
583
640
|
type StepsOptions<TSchema, TName extends string = string> = {
|
584
641
|
/**
|
585
642
|
* The step name
|
@@ -590,7 +647,7 @@ type StepsOptions<TSchema, TName extends string = string> = {
|
|
590
647
|
*/
|
591
648
|
schema?: TSchema;
|
592
649
|
}[];
|
593
|
-
interface StepFormProps<TSteps extends StepsOptions<any> = StepsOptions<any>, TFieldValues extends FieldValues = FieldValues, TContext extends object = object
|
650
|
+
interface StepFormProps<TSteps extends StepsOptions<any> = StepsOptions<any>, TFieldValues extends FieldValues = FieldValues, TContext extends object = object> extends UseStepFormProps<TSteps, TFieldValues, TContext> {
|
594
651
|
}
|
595
652
|
interface FormStepOptions<TName extends string = string> {
|
596
653
|
/**
|
@@ -644,57 +701,20 @@ interface NextButtonProps extends Omit<ButtonProps, 'children'> {
|
|
644
701
|
*/
|
645
702
|
declare const NextButton: React$1.FC<NextButtonProps>;
|
646
703
|
|
647
|
-
|
648
|
-
|
649
|
-
|
650
|
-
|
651
|
-
|
652
|
-
|
653
|
-
|
654
|
-
|
655
|
-
|
656
|
-
|
657
|
-
updateStep(state: StepState): void;
|
658
|
-
steps: Record<string, StepState>;
|
659
|
-
}
|
660
|
-
declare const StepFormProvider: React$1.Provider<StepFormContext>;
|
661
|
-
declare const useStepFormContext: () => StepFormContext;
|
662
|
-
|
663
|
-
type StepName<T extends {
|
664
|
-
[k: number]: {
|
665
|
-
readonly name: string;
|
666
|
-
};
|
667
|
-
}> = T[number]['name'];
|
668
|
-
interface StepFormRenderContext<TSteps extends StepsOptions<any> = StepsOptions<any>, TFieldValues extends FieldValues = FieldValues, TContext extends object = object, TFieldTypes = FieldProps<TFieldValues>> extends UseStepFormReturn<TFieldValues> {
|
669
|
-
Field: React$1.FC<TFieldTypes & React$1.RefAttributes<FocusableElement>>;
|
670
|
-
FormStep: React$1.FC<FormStepProps<StepName<TSteps>>>;
|
671
|
-
DisplayIf: React$1.FC<DisplayIfProps<TFieldValues>>;
|
672
|
-
ArrayField: React$1.FC<ArrayFieldProps<TFieldValues> & React$1.RefAttributes<UseArrayFieldReturn>>;
|
673
|
-
ObjectField: React$1.FC<ObjectFieldProps<TFieldValues>>;
|
674
|
-
}
|
675
|
-
interface UseStepFormProps<TSteps extends StepsOptions<any> = StepsOptions<any>, TFieldValues extends FieldValues = FieldValues, TContext extends object = object, TFieldTypes = FieldProps<TFieldValues>> extends Omit<UseStepperProps, 'onChange'>, Omit<FormProps<any, TFieldValues, TContext, TFieldTypes>, 'children'> {
|
676
|
-
steps?: TSteps;
|
677
|
-
children: MaybeRenderProp<StepFormRenderContext<TSteps, TFieldValues, TContext, TFieldTypes>>;
|
678
|
-
}
|
679
|
-
interface UseStepFormReturn<TFieldValues extends FieldValues = FieldValues> extends UseStepperReturn {
|
680
|
-
getFormProps(): {
|
681
|
-
onSubmit: SubmitHandler<TFieldValues>;
|
682
|
-
schema?: any;
|
683
|
-
resolver?: any;
|
684
|
-
};
|
685
|
-
updateStep(step: any): void;
|
686
|
-
steps: Record<string, any>;
|
687
|
-
}
|
688
|
-
declare function useStepForm<TSteps extends StepsOptions<any> = StepsOptions<any>, TFieldValues extends FieldValues = FieldValues, TContext extends object = object, TFieldTypes = FieldProps<TFieldValues>>(props: UseStepFormProps<TSteps, TFieldValues, TContext, TFieldTypes>): UseStepFormReturn<TFieldValues>;
|
689
|
-
interface UseFormStepProps {
|
690
|
-
name: string;
|
691
|
-
schema?: any;
|
692
|
-
resolver?: any;
|
693
|
-
onSubmit?: FormStepSubmitHandler;
|
704
|
+
type StepFormType<FieldDefs, ExtraProps = object, ExtraOverrides = object> = (<TSteps extends StepsOptions<any> = StepsOptions<any>, TFieldValues extends FieldValues = FieldValues, TContext extends object = object, TFieldTypes = FieldProps<TFieldValues>>(props: WithStepFields<UseStepFormProps<TSteps, TFieldValues, TContext>, FieldDefs, ExtraOverrides> & {
|
705
|
+
ref?: React__default.ForwardedRef<HTMLFormElement>;
|
706
|
+
} & ExtraProps) => React__default.ReactElement) & {
|
707
|
+
displayName?: string;
|
708
|
+
id?: string;
|
709
|
+
};
|
710
|
+
interface CreateStepFormProps<FieldDefs> {
|
711
|
+
resolver?: GetResolver;
|
712
|
+
fieldResolver?: GetFieldResolver;
|
713
|
+
fields?: FieldDefs extends Record<string, React__default.FC<any>> ? FieldDefs : never;
|
694
714
|
}
|
695
|
-
declare function
|
715
|
+
declare function createStepForm<FieldDefs, ExtraProps = object, ExtraOverrides = object>({ fields, resolver, fieldResolver }?: CreateStepFormProps<FieldDefs>): StepFormType<FieldDefs, ExtraProps, ExtraOverrides>;
|
696
716
|
|
697
|
-
interface CreateFormProps
|
717
|
+
interface CreateFormProps<FieldDefs> {
|
698
718
|
resolver?: GetResolver;
|
699
719
|
fieldResolver?: GetFieldResolver;
|
700
720
|
fields?: FieldDefs extends Record<string, React__default.FC<any>> ? FieldDefs : never;
|
@@ -705,7 +725,7 @@ type FormType<FieldDefs, ExtraProps = object, ExtraOverrides = object> = (<TSche
|
|
705
725
|
displayName?: string;
|
706
726
|
id?: string;
|
707
727
|
};
|
708
|
-
declare function createForm<FieldDefs>({ resolver, fieldResolver, fields, }?: CreateFormProps
|
728
|
+
declare function createForm<FieldDefs>({ resolver, fieldResolver, fields, }?: CreateFormProps<FieldDefs>): FormType<FieldDefs, object, object>;
|
709
729
|
|
710
730
|
interface DisplayFieldProps extends FormControlProps, Omit<FieldProps, 'type' | 'label'> {
|
711
731
|
}
|
@@ -819,19 +839,6 @@ interface CreateFieldOptions {
|
|
819
839
|
*/
|
820
840
|
declare const createField: <TProps extends object>(component: React$1.FC<TProps>, options?: CreateFieldOptions) => React$1.FC<TProps & BaseFieldProps<react_hook_form.FieldValues, string>>;
|
821
841
|
|
822
|
-
type StepFormType<FieldDefs, ExtraProps = object, ExtraOverrides = object> = (<TSteps extends StepsOptions<any> = StepsOptions<any>, TFieldValues extends FieldValues = FieldValues, TContext extends object = object, TFieldTypes = FieldProps<TFieldValues>>(props: UseStepFormProps<TSteps, TFieldValues, TContext, TFieldTypes> & {
|
823
|
-
ref?: React__default.ForwardedRef<HTMLFormElement>;
|
824
|
-
}) => React__default.ReactElement) & {
|
825
|
-
displayName?: string;
|
826
|
-
id?: string;
|
827
|
-
};
|
828
|
-
interface CreateFormProps<FieldDefs> {
|
829
|
-
resolver?: GetResolver;
|
830
|
-
fieldResolver?: GetFieldResolver;
|
831
|
-
fields?: FieldDefs extends Record<string, React__default.FC<any>> ? FieldDefs : never;
|
832
|
-
}
|
833
|
-
declare function createStepForm<FieldDefs = any, ExtraProps = object, ExtraOverrides = object>({ fields, resolver, fieldResolver }?: CreateFormProps<FieldDefs>): StepFormType<FieldDefs, ExtraProps, ExtraOverrides>;
|
834
|
-
|
835
842
|
/**
|
836
843
|
* Form component.
|
837
844
|
*
|
@@ -844,11 +851,6 @@ declare const Form: FormType<unknown, object, object>;
|
|
844
851
|
*
|
845
852
|
* @see Docs https://saas-ui.dev/docs/components/forms/step-form
|
846
853
|
*/
|
847
|
-
declare const StepForm:
|
848
|
-
ref?: React$1.ForwardedRef<HTMLFormElement> | undefined;
|
849
|
-
}) => React$1.ReactElement<any, string | React$1.JSXElementConstructor<any>>) & {
|
850
|
-
displayName?: string | undefined;
|
851
|
-
id?: string | undefined;
|
852
|
-
};
|
854
|
+
declare const StepForm: StepFormType<unknown, object, object>;
|
853
855
|
|
854
|
-
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
|
856
|
+
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, CreateStepFormProps, DefaultFieldOverrides, DefaultFields, DisplayField, DisplayFieldProps, DisplayIf, DisplayIfProps, Field, FieldOptions, FieldProps, FieldResolver, FieldRules, FieldsProps, FieldsProvider, Form, FormComponent, FormLayout, FormLayoutProps, FormLegend, FormProps, FormProvider, FormRenderContext, FormStep, FormStepOptions, FormStepProps, FormStepSubmitHandler, FormStepper, FormStepperProps, FormType, FormValue, GetFieldResolver, InputField, InputFieldProps, InputRightButton, InputRightButtonProps, NativeSelect, NativeSelectField, NativeSelectProps, NextButton, NextButtonProps, NumberInputField, NumberInputFieldProps, ObjectField, ObjectFieldProps, ObjectSchema, Option, PasswordInput, PasswordInputField, PasswordInputProps, PinField, PinFieldProps, PrevButton, RadioField, RadioInput, RadioInputProps, RadioOption, RadioOptions, Select, SelectButton, SelectButtonProps, SelectField, SelectList, SelectListProps, SelectOption, SelectProps, StepForm, StepFormContext, StepFormProps, StepFormProvider, StepFormRenderContext, StepState, StepsOptions, SubmitButton, SubmitButtonProps, SwitchField, TextareaField, UseArrayFieldReturn, UseArrayFieldRowProps, UseArrayFieldRowReturn, UseFormStepProps, UseStepFormProps, UseStepFormReturn, WatchField, WatchFieldProps, WithFields, WithStepFields, createField, createForm, createStepForm, defaultFieldTypes, objectFieldResolver, useArrayField, useArrayFieldAddButton, useArrayFieldContext, useArrayFieldRemoveButton, useArrayFieldRow, useArrayFieldRowContext, useField, useFormContext, useFormStep, useStepForm, useStepFormContext };
|
package/dist/index.js
CHANGED
@@ -1236,7 +1236,7 @@ function createStepForm({ fields, resolver, fieldResolver } = {}) {
|
|
1236
1236
|
});
|
1237
1237
|
const { getFormProps, ...ctx } = stepper;
|
1238
1238
|
const context = React11.useMemo(() => ctx, [ctx]);
|
1239
|
-
return /* @__PURE__ */ jsxRuntime.jsx(core.StepperProvider, { value: context, children: /* @__PURE__ */ jsxRuntime.jsx(StepFormProvider, { value: context, children: /* @__PURE__ */ jsxRuntime.jsx(FieldsProvider, { value: fields || {}, children: /* @__PURE__ */ jsxRuntime.jsx(
|
1239
|
+
return /* @__PURE__ */ jsxRuntime.jsx(core.StepperProvider, { value: context, children: /* @__PURE__ */ jsxRuntime.jsx(StepFormProvider, { value: context, children: /* @__PURE__ */ jsxRuntime.jsx(FieldsProvider, { value: fields || {}, children: /* @__PURE__ */ jsxRuntime.jsx(Form, { ref, ...rest, ...getFormProps(), children: utils.runIfFn(children, {
|
1240
1240
|
...stepper,
|
1241
1241
|
Field,
|
1242
1242
|
FormStep,
|
@@ -1245,7 +1245,7 @@ function createStepForm({ fields, resolver, fieldResolver } = {}) {
|
|
1245
1245
|
ObjectField
|
1246
1246
|
}) }) }) }) });
|
1247
1247
|
});
|
1248
|
-
StepForm2.displayName = `Step${
|
1248
|
+
StepForm2.displayName = `Step${Form.displayName || Form.name}`;
|
1249
1249
|
return StepForm2;
|
1250
1250
|
}
|
1251
1251
|
var Form2 = createForm();
|