@saas-ui/forms 2.0.0-next.19 → 2.0.0-next.20
Sign up to get free protection for your applications and to get access to all the features.
- package/CHANGELOG.md +11 -0
- package/dist/index.d.ts +100 -60
- package/dist/index.js +44 -19
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +44 -20
- package/dist/index.mjs.map +1 -1
- package/dist/yup/index.d.ts +514 -9
- package/dist/yup/index.js +18 -5
- package/dist/yup/index.js.map +1 -1
- package/dist/yup/index.mjs +16 -4
- package/dist/yup/index.mjs.map +1 -1
- package/dist/zod/index.d.ts +516 -10
- package/dist/zod/index.js +12 -0
- package/dist/zod/index.js.map +1 -1
- package/dist/zod/index.mjs +13 -2
- package/dist/zod/index.mjs.map +1 -1
- package/package.json +5 -5
- package/src/create-step-form.tsx +44 -105
- package/src/index.ts +9 -2
- package/src/step-form.tsx +49 -81
- package/src/use-step-form.tsx +24 -7
package/CHANGELOG.md
CHANGED
package/dist/index.d.ts
CHANGED
@@ -4,7 +4,7 @@ import * as react_hook_form from 'react-hook-form';
|
|
4
4
|
import { FieldValues, FieldPath, RegisterOptions, UseFormReturn as UseFormReturn$1, UseFieldArrayReturn, 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
|
-
import { UseStepperReturn, UseStepperProps
|
7
|
+
import { StepsProps, StepsItemProps, UseStepperReturn, UseStepperProps } from '@saas-ui/core';
|
8
8
|
import { NumberInputProps as NumberInputProps$1, InputProps, RadioProps, RadioGroupProps, SystemProps, StackDirection, MenuProps, ButtonProps, MenuListProps, MenuItemOptionProps, SelectProps as SelectProps$1, TextareaProps, SwitchProps, CheckboxProps, UsePinInputProps, FormControlProps, SimpleGridProps, ResponsiveValue, FormLabelProps, 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';
|
@@ -571,6 +571,70 @@ type FormComponent = (<TSchema = unknown, TFieldValues extends FieldValues = Fie
|
|
571
571
|
};
|
572
572
|
type GetResolver = <TFieldValues extends FieldValues, TContext extends object>(schema: unknown) => (values: TFieldValues, context: TContext | undefined, options: ResolverOptions<TFieldValues>) => Promise<ResolverResult<TFieldValues>>;
|
573
573
|
|
574
|
+
type StepsOptions<TSchema, TName extends string = string> = {
|
575
|
+
/**
|
576
|
+
* The step name
|
577
|
+
*/
|
578
|
+
name: TName;
|
579
|
+
/**
|
580
|
+
* Schema
|
581
|
+
*/
|
582
|
+
schema?: TSchema;
|
583
|
+
}[];
|
584
|
+
interface StepFormProps<TSteps extends StepsOptions<any> = StepsOptions<any>, TFieldValues extends FieldValues = FieldValues, TContext extends object = object, TFieldTypes = FieldProps<TFieldValues>> extends UseStepFormProps<TSteps, TFieldValues, TContext, TFieldTypes> {
|
585
|
+
}
|
586
|
+
interface FormStepOptions<TName extends string = string> {
|
587
|
+
/**
|
588
|
+
* The step name
|
589
|
+
*/
|
590
|
+
name: TName;
|
591
|
+
/**
|
592
|
+
* Schema
|
593
|
+
*/
|
594
|
+
schema?: any;
|
595
|
+
/**
|
596
|
+
* Hook Form Resolver
|
597
|
+
*/
|
598
|
+
resolver?: any;
|
599
|
+
}
|
600
|
+
interface FormStepperProps extends StepsProps, ThemingProps<'Stepper'> {
|
601
|
+
render?: StepsItemProps['render'];
|
602
|
+
}
|
603
|
+
/**
|
604
|
+
* Renders a stepper that displays progress above the form.
|
605
|
+
*
|
606
|
+
* @see Docs https://saas-ui.dev/docs/components/forms/step-form
|
607
|
+
*/
|
608
|
+
declare const FormStepper: React$1.FC<FormStepperProps>;
|
609
|
+
interface FormStepProps<TName extends string = string> extends FormStepOptions<TName>, Omit<HTMLChakraProps<'div'>, 'onSubmit'> {
|
610
|
+
onSubmit?: FormStepSubmitHandler;
|
611
|
+
}
|
612
|
+
/**
|
613
|
+
* The form step containing fields for a specific step.
|
614
|
+
*
|
615
|
+
* @see Docs https://saas-ui.dev/docs/components/forms/step-form
|
616
|
+
*/
|
617
|
+
declare const FormStep: {
|
618
|
+
<TName extends string = string>(props: FormStepProps<TName>): JSX.Element | null;
|
619
|
+
displayName: string;
|
620
|
+
};
|
621
|
+
/**
|
622
|
+
* A button that this opens the previous step when clicked. Disabled on the first step.
|
623
|
+
*
|
624
|
+
* @see Docs https://saas-ui.dev/docs/components/forms/step-form
|
625
|
+
*/
|
626
|
+
declare const PrevButton: React$1.FC<ButtonProps>;
|
627
|
+
interface NextButtonProps extends Omit<ButtonProps, 'children'> {
|
628
|
+
submitLabel?: string;
|
629
|
+
label?: string;
|
630
|
+
}
|
631
|
+
/**
|
632
|
+
* A button that submits the active step.
|
633
|
+
*
|
634
|
+
* @see Docs https://saas-ui.dev/docs/components/forms/step-form
|
635
|
+
*/
|
636
|
+
declare const NextButton: React$1.FC<NextButtonProps>;
|
637
|
+
|
574
638
|
interface StepState {
|
575
639
|
name: string;
|
576
640
|
schema?: any;
|
@@ -587,14 +651,21 @@ interface StepFormContext extends UseStepperReturn {
|
|
587
651
|
declare const StepFormProvider: React$1.Provider<StepFormContext>;
|
588
652
|
declare const useStepFormContext: () => StepFormContext;
|
589
653
|
|
590
|
-
|
654
|
+
type StepName<T extends {
|
655
|
+
[k: number]: {
|
656
|
+
readonly name: string;
|
657
|
+
};
|
658
|
+
}> = T[number]['name'];
|
659
|
+
interface StepFormRenderContext<TSteps extends StepsOptions<any> = StepsOptions<any>, TFieldValues extends FieldValues = FieldValues, TContext extends object = object, TFieldTypes = FieldProps<TFieldValues>> extends UseStepFormReturn<TFieldValues> {
|
591
660
|
Field: React$1.FC<TFieldTypes & React$1.RefAttributes<FocusableElement>>;
|
661
|
+
FormStep: React$1.FC<FormStepProps<StepName<TSteps>>>;
|
592
662
|
DisplayIf: React$1.FC<DisplayIfProps<TFieldValues>>;
|
593
663
|
ArrayField: React$1.FC<ArrayFieldProps<TFieldValues> & React$1.RefAttributes<UseArrayFieldReturn>>;
|
594
664
|
ObjectField: React$1.FC<ObjectFieldProps<TFieldValues>>;
|
595
665
|
}
|
596
|
-
interface UseStepFormProps<TFieldValues extends FieldValues = FieldValues, TContext extends object = object, TFieldTypes = FieldProps<TFieldValues>> extends Omit<UseStepperProps, 'onChange'>, Omit<FormProps<any, TFieldValues, TContext, TFieldTypes>, 'children'> {
|
597
|
-
|
666
|
+
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'> {
|
667
|
+
steps?: TSteps;
|
668
|
+
children: MaybeRenderProp<StepFormRenderContext<TSteps, TFieldValues, TContext, TFieldTypes>>;
|
598
669
|
}
|
599
670
|
interface UseStepFormReturn<TFieldValues extends FieldValues = FieldValues> extends UseStepperReturn {
|
600
671
|
getFormProps(): {
|
@@ -605,7 +676,7 @@ interface UseStepFormReturn<TFieldValues extends FieldValues = FieldValues> exte
|
|
605
676
|
updateStep(step: any): void;
|
606
677
|
steps: Record<string, any>;
|
607
678
|
}
|
608
|
-
declare function useStepForm<TFieldValues extends FieldValues = FieldValues, TContext extends object = object, TFieldTypes = FieldProps<TFieldValues>>(props: UseStepFormProps<TFieldValues, TContext, TFieldTypes>): UseStepFormReturn<TFieldValues>;
|
679
|
+
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>;
|
609
680
|
interface UseFormStepProps {
|
610
681
|
name: string;
|
611
682
|
schema?: any;
|
@@ -614,7 +685,7 @@ interface UseFormStepProps {
|
|
614
685
|
}
|
615
686
|
declare function useFormStep(props: UseFormStepProps): StepState;
|
616
687
|
|
617
|
-
interface CreateFormProps<FieldDefs> {
|
688
|
+
interface CreateFormProps$1<FieldDefs> {
|
618
689
|
resolver?: GetResolver;
|
619
690
|
fieldResolver?: GetFieldResolver;
|
620
691
|
fields?: FieldDefs extends Record<string, React__default.FC<any>> ? FieldDefs : never;
|
@@ -625,7 +696,7 @@ type FormType<FieldDefs, ExtraProps = object, ExtraOverrides = object> = (<TSche
|
|
625
696
|
displayName?: string;
|
626
697
|
id?: string;
|
627
698
|
};
|
628
|
-
declare function createForm<FieldDefs>({ resolver, fieldResolver, fields, }?: CreateFormProps<FieldDefs>): FormType<FieldDefs, object, object>;
|
699
|
+
declare function createForm<FieldDefs>({ resolver, fieldResolver, fields, }?: CreateFormProps$1<FieldDefs>): FormType<FieldDefs, object, object>;
|
629
700
|
|
630
701
|
interface DisplayFieldProps extends FormControlProps, Omit<FieldProps, 'type' | 'label'> {
|
631
702
|
}
|
@@ -674,56 +745,6 @@ declare const FieldsProvider: React__default.FC<{
|
|
674
745
|
}>;
|
675
746
|
declare const useField: (type: string) => React__default.FC<any>;
|
676
747
|
|
677
|
-
interface StepFormProps<TFieldValues extends FieldValues = FieldValues, TContext extends object = object, TFieldTypes = FieldProps<TFieldValues>> extends UseStepFormProps<TFieldValues, TContext, TFieldTypes> {
|
678
|
-
}
|
679
|
-
interface FormStepOptions {
|
680
|
-
/**
|
681
|
-
* The step name
|
682
|
-
*/
|
683
|
-
name: string;
|
684
|
-
/**
|
685
|
-
* Schema
|
686
|
-
*/
|
687
|
-
schema?: any;
|
688
|
-
/**
|
689
|
-
* Hook Form Resolver
|
690
|
-
*/
|
691
|
-
resolver?: any;
|
692
|
-
}
|
693
|
-
interface FormStepperProps extends StepperStepsProps, ThemingProps<'Stepper'> {
|
694
|
-
}
|
695
|
-
/**
|
696
|
-
* Renders a stepper that displays progress above the form.
|
697
|
-
*
|
698
|
-
* @see Docs https://saas-ui.dev/docs/components/forms/step-form
|
699
|
-
*/
|
700
|
-
declare const FormStepper: React$1.FC<FormStepperProps>;
|
701
|
-
interface FormStepProps extends FormStepOptions, Omit<HTMLChakraProps<'div'>, 'onSubmit'> {
|
702
|
-
onSubmit?: FormStepSubmitHandler;
|
703
|
-
}
|
704
|
-
/**
|
705
|
-
* The form step containing fields for a specific step.
|
706
|
-
*
|
707
|
-
* @see Docs https://saas-ui.dev/docs/components/forms/step-form
|
708
|
-
*/
|
709
|
-
declare const FormStep: React$1.FC<FormStepProps>;
|
710
|
-
/**
|
711
|
-
* A button that this opens the previous step when clicked. Disabled on the first step.
|
712
|
-
*
|
713
|
-
* @see Docs https://saas-ui.dev/docs/components/forms/step-form
|
714
|
-
*/
|
715
|
-
declare const PrevButton: React$1.FC<ButtonProps>;
|
716
|
-
interface NextButtonProps extends Omit<ButtonProps, 'children'> {
|
717
|
-
submitLabel?: string;
|
718
|
-
label?: string;
|
719
|
-
}
|
720
|
-
/**
|
721
|
-
* A button that submits the active step.
|
722
|
-
*
|
723
|
-
* @see Docs https://saas-ui.dev/docs/components/forms/step-form
|
724
|
-
*/
|
725
|
-
declare const NextButton: React$1.FC<NextButtonProps>;
|
726
|
-
|
727
748
|
type FormProviderProps<TFieldValues extends FieldValues = FieldValues, TContext = any, TSchema = any> = FormProviderProps$1<TFieldValues, TContext> & {
|
728
749
|
fieldResolver?: FieldResolver;
|
729
750
|
schema?: TSchema;
|
@@ -789,17 +810,36 @@ interface CreateFieldOptions {
|
|
789
810
|
*/
|
790
811
|
declare const createField: <TProps extends object>(component: React$1.FC<TProps>, options?: CreateFieldOptions) => React$1.FC<TProps & BaseFieldProps<react_hook_form.FieldValues, string>>;
|
791
812
|
|
813
|
+
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> & {
|
814
|
+
ref?: React__default.ForwardedRef<HTMLFormElement>;
|
815
|
+
}) => React__default.ReactElement) & {
|
816
|
+
displayName?: string;
|
817
|
+
id?: string;
|
818
|
+
};
|
819
|
+
interface CreateFormProps<FieldDefs> {
|
820
|
+
resolver?: GetResolver;
|
821
|
+
fieldResolver?: GetFieldResolver;
|
822
|
+
fields?: FieldDefs extends Record<string, React__default.FC<any>> ? FieldDefs : never;
|
823
|
+
}
|
824
|
+
declare function createStepForm<FieldDefs = any, ExtraProps = object, ExtraOverrides = object>({ fields, resolver, fieldResolver }?: CreateFormProps<FieldDefs>): StepFormType<FieldDefs, ExtraProps, ExtraOverrides>;
|
825
|
+
|
826
|
+
/**
|
827
|
+
* Form component.
|
828
|
+
*
|
829
|
+
* @see Docs https://saas-ui.dev/docs/components/forms/form
|
830
|
+
*/
|
792
831
|
declare const Form: FormType<unknown, object, object>;
|
832
|
+
|
793
833
|
/**
|
794
|
-
*
|
834
|
+
* Multi-step form component.
|
795
835
|
*
|
796
836
|
* @see Docs https://saas-ui.dev/docs/components/forms/step-form
|
797
837
|
*/
|
798
|
-
declare const StepForm: (<TFieldValues extends react_hook_form.FieldValues = react_hook_form.FieldValues, TContext extends object = object, TFieldTypes = FieldProps<TFieldValues>>(props: UseStepFormProps<TFieldValues, TContext, TFieldTypes> & {
|
838
|
+
declare const StepForm: (<TSteps extends StepsOptions<any> = StepsOptions<any>, TFieldValues extends react_hook_form.FieldValues = react_hook_form.FieldValues, TContext extends object = object, TFieldTypes = FieldProps<TFieldValues>>(props: UseStepFormProps<TSteps, TFieldValues, TContext, TFieldTypes> & {
|
799
839
|
ref?: React$1.ForwardedRef<HTMLFormElement> | undefined;
|
800
840
|
}) => React$1.ReactElement<any, string | React$1.JSXElementConstructor<any>>) & {
|
801
841
|
displayName?: string | undefined;
|
802
842
|
id?: string | undefined;
|
803
843
|
};
|
804
844
|
|
805
|
-
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, 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, 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 };
|
845
|
+
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$1 as CreateFormProps, 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, StepState, StepsOptions, SubmitButton, SubmitButtonProps, SwitchField, TextareaField, UseArrayFieldReturn, UseArrayFieldRowProps, UseArrayFieldRowReturn, UseFormStepProps, UseStepFormProps, UseStepFormReturn, WatchField, WatchFieldProps, WithFields, createField, createForm, createStepForm, defaultFieldTypes, objectFieldResolver, useArrayField, useArrayFieldAddButton, useArrayFieldContext, useArrayFieldRemoveButton, useArrayFieldRow, useArrayFieldRowContext, useField, useFormContext, useFormStep, useStepForm, useStepFormContext };
|
package/dist/index.js
CHANGED
@@ -914,8 +914,9 @@ var [StepFormProvider, useStepFormContext] = reactUtils.createContext({
|
|
914
914
|
errorMessage: "useStepFormContext: `context` is undefined. Seems you forgot to wrap step form components in `<StepForm />`"
|
915
915
|
});
|
916
916
|
function useStepForm(props) {
|
917
|
-
const { onChange, ...rest } = props;
|
917
|
+
const { onChange, steps: stepsOptions, resolver, ...rest } = props;
|
918
918
|
const stepper = core.useStepper(rest);
|
919
|
+
const [options, setOptions] = React12__namespace.useState(stepsOptions);
|
919
920
|
const { activeStep, isLastStep, nextStep } = stepper;
|
920
921
|
const [steps, updateSteps] = React12__namespace.useState({});
|
921
922
|
const onSubmitStep = React12__namespace.useCallback(
|
@@ -944,19 +945,26 @@ function useStepForm(props) {
|
|
944
945
|
return {
|
945
946
|
onSubmit: onSubmitStep,
|
946
947
|
schema: step == null ? void 0 : step.schema,
|
947
|
-
resolver: step == null ? void 0 : step.
|
948
|
+
resolver: (step == null ? void 0 : step.schema) ? (
|
949
|
+
/* @todo fix resolver type */
|
950
|
+
resolver == null ? void 0 : resolver(step.schema)
|
951
|
+
) : void 0
|
948
952
|
};
|
949
953
|
}, [steps, onSubmitStep, activeStep]);
|
950
954
|
const updateStep = React12__namespace.useCallback(
|
951
955
|
(step) => {
|
956
|
+
const stepOptions = options == null ? void 0 : options.find((s) => s.name === step.name);
|
952
957
|
updateSteps((steps2) => {
|
953
958
|
return {
|
954
959
|
...steps2,
|
955
|
-
[step.name]:
|
960
|
+
[step.name]: {
|
961
|
+
...step,
|
962
|
+
schema: stepOptions == null ? void 0 : stepOptions.schema
|
963
|
+
}
|
956
964
|
};
|
957
965
|
});
|
958
966
|
},
|
959
|
-
[steps]
|
967
|
+
[steps, options]
|
960
968
|
);
|
961
969
|
return {
|
962
970
|
getFormProps,
|
@@ -979,13 +987,23 @@ function useFormStep(props) {
|
|
979
987
|
}
|
980
988
|
var FormStepper = (props) => {
|
981
989
|
const { activeIndex, setIndex } = core.useStepperContext();
|
982
|
-
const {
|
990
|
+
const {
|
991
|
+
children,
|
992
|
+
orientation,
|
993
|
+
variant,
|
994
|
+
colorScheme,
|
995
|
+
size,
|
996
|
+
onChange: onChangeProp,
|
997
|
+
render,
|
998
|
+
...rest
|
999
|
+
} = props;
|
983
1000
|
const elements = React12__namespace.Children.map(children, (child) => {
|
984
1001
|
if (React12__namespace.isValidElement(child) && (child == null ? void 0 : child.type) === FormStep) {
|
985
1002
|
const { isCompleted } = useFormStep(child.props);
|
986
1003
|
return /* @__PURE__ */ jsxRuntime.jsx(
|
987
|
-
core.
|
1004
|
+
core.StepsItem,
|
988
1005
|
{
|
1006
|
+
render,
|
989
1007
|
name: child.props.name,
|
990
1008
|
title: child.props.title,
|
991
1009
|
isCompleted,
|
@@ -998,9 +1016,10 @@ var FormStepper = (props) => {
|
|
998
1016
|
});
|
999
1017
|
const onChange = React12__namespace.useCallback((i) => {
|
1000
1018
|
setIndex(i);
|
1019
|
+
onChangeProp == null ? void 0 : onChangeProp(i);
|
1001
1020
|
}, []);
|
1002
1021
|
return /* @__PURE__ */ jsxRuntime.jsx(
|
1003
|
-
core.
|
1022
|
+
core.Steps,
|
1004
1023
|
{
|
1005
1024
|
orientation,
|
1006
1025
|
step: activeIndex,
|
@@ -1008,13 +1027,13 @@ var FormStepper = (props) => {
|
|
1008
1027
|
colorScheme,
|
1009
1028
|
size,
|
1010
1029
|
onChange,
|
1011
|
-
children:
|
1030
|
+
children: elements
|
1012
1031
|
}
|
1013
1032
|
);
|
1014
1033
|
};
|
1015
1034
|
var FormStep = (props) => {
|
1016
|
-
const { name,
|
1017
|
-
const step = useFormStep({ name,
|
1035
|
+
const { name, children, className, onSubmit, ...rest } = props;
|
1036
|
+
const step = useFormStep({ name, onSubmit });
|
1018
1037
|
const { isActive } = step;
|
1019
1038
|
return isActive ? /* @__PURE__ */ jsxRuntime.jsx(react.chakra.div, { ...rest, className: utils.cx("sui-form__step", className), children }) : null;
|
1020
1039
|
};
|
@@ -1191,25 +1210,30 @@ function createForm({
|
|
1191
1210
|
DefaultForm.id = "Form";
|
1192
1211
|
return DefaultForm;
|
1193
1212
|
}
|
1194
|
-
function createStepForm(
|
1213
|
+
function createStepForm({ fields, resolver, fieldResolver } = {}) {
|
1195
1214
|
const StepForm2 = react.forwardRef((props, ref) => {
|
1196
|
-
const { children, ...rest } = props;
|
1197
|
-
const stepper = useStepForm(
|
1215
|
+
const { children, steps, ...rest } = props;
|
1216
|
+
const stepper = useStepForm({
|
1217
|
+
resolver,
|
1218
|
+
fieldResolver,
|
1219
|
+
...props
|
1220
|
+
});
|
1198
1221
|
const { getFormProps, ...ctx } = stepper;
|
1199
1222
|
const context = React12.useMemo(() => ctx, [ctx]);
|
1200
|
-
return /* @__PURE__ */ jsxRuntime.jsx(core.StepperProvider, { value: context, children: /* @__PURE__ */ jsxRuntime.jsx(StepFormProvider, { value: context, children: /* @__PURE__ */ jsxRuntime.jsx(
|
1223
|
+
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(Form2, { ref, ...rest, ...getFormProps(), children: utils.runIfFn(children, {
|
1201
1224
|
...stepper,
|
1202
1225
|
Field,
|
1226
|
+
FormStep,
|
1203
1227
|
DisplayIf,
|
1204
1228
|
ArrayField,
|
1205
1229
|
ObjectField
|
1206
|
-
}) }) }) });
|
1230
|
+
}) }) }) }) });
|
1207
1231
|
});
|
1208
|
-
StepForm2.displayName = `Step${
|
1232
|
+
StepForm2.displayName = `Step${Form2.displayName || Form2.name}`;
|
1209
1233
|
return StepForm2;
|
1210
1234
|
}
|
1211
|
-
var
|
1212
|
-
var StepForm = createStepForm(
|
1235
|
+
var Form2 = createForm();
|
1236
|
+
var StepForm = createStepForm();
|
1213
1237
|
|
1214
1238
|
Object.defineProperty(exports, 'Controller', {
|
1215
1239
|
enumerable: true,
|
@@ -1257,7 +1281,7 @@ exports.DisplayField = DisplayField;
|
|
1257
1281
|
exports.DisplayIf = DisplayIf;
|
1258
1282
|
exports.Field = Field;
|
1259
1283
|
exports.FieldsProvider = FieldsProvider;
|
1260
|
-
exports.Form =
|
1284
|
+
exports.Form = Form2;
|
1261
1285
|
exports.FormLayout = FormLayout;
|
1262
1286
|
exports.FormLegend = FormLegend;
|
1263
1287
|
exports.FormProvider = FormProvider;
|
@@ -1290,6 +1314,7 @@ exports.TextareaField = TextareaField;
|
|
1290
1314
|
exports.WatchField = WatchField;
|
1291
1315
|
exports.createField = createField;
|
1292
1316
|
exports.createForm = createForm;
|
1317
|
+
exports.createStepForm = createStepForm;
|
1293
1318
|
exports.defaultFieldTypes = defaultFieldTypes;
|
1294
1319
|
exports.objectFieldResolver = objectFieldResolver;
|
1295
1320
|
exports.useArrayField = useArrayField;
|