@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/dist/index.mjs CHANGED
@@ -4,7 +4,7 @@ import { useFormContext as useFormContext$1, useForm, FormProvider as FormProvid
4
4
  export { Controller, appendErrors, useController, useFieldArray, useForm, useFormState, useWatch } from 'react-hook-form';
5
5
  import { jsxs, jsx, Fragment } from 'react/jsx-runtime';
6
6
  import { forwardRef, NumberInput as NumberInput$1, NumberInputField, NumberInputStepper, NumberIncrementStepper, NumberDecrementStepper, InputRightElement, Button, InputGroup, Input, RadioGroup, Stack, Radio, useMultiStyleConfig, useFormControlContext, MenuButton, omitThemingProps, Menu, chakra, MenuItemOption, Select as Select$1, Switch, Checkbox, HStack, PinInput, FormControl, FormLabel, Text, useControllableState, useFormControl, MenuList, MenuOptionGroup, Box, FormHelperText, FormErrorMessage, PinInputField, useTheme, SimpleGrid, useStyleConfig, useMergeRefs, Textarea } from '@chakra-ui/react';
7
- import { ChevronUpIcon, ChevronDownIcon, useStepper, useStep, useStepperContext, StepperStep, StepperContainer, StepperSteps, StepperProvider } from '@saas-ui/core';
7
+ import { ChevronUpIcon, ChevronDownIcon, useStepper, useStep, useStepperContext, StepsItem, Steps, StepperProvider } from '@saas-ui/core';
8
8
  import { ViewIcon, ViewOffIcon, MinusIcon, PlusIcon } from '@saas-ui/core/icons';
9
9
  import { dataAttr, cx, isFunction, runIfFn, callAllHandlers, get as get$1 } from '@chakra-ui/utils';
10
10
  import { createContext } from '@chakra-ui/react-utils';
@@ -894,8 +894,9 @@ var [StepFormProvider, useStepFormContext] = createContext({
894
894
  errorMessage: "useStepFormContext: `context` is undefined. Seems you forgot to wrap step form components in `<StepForm />`"
895
895
  });
896
896
  function useStepForm(props) {
897
- const { onChange, ...rest } = props;
897
+ const { onChange, steps: stepsOptions, resolver, ...rest } = props;
898
898
  const stepper = useStepper(rest);
899
+ const [options, setOptions] = React12.useState(stepsOptions);
899
900
  const { activeStep, isLastStep, nextStep } = stepper;
900
901
  const [steps, updateSteps] = React12.useState({});
901
902
  const onSubmitStep = React12.useCallback(
@@ -924,19 +925,26 @@ function useStepForm(props) {
924
925
  return {
925
926
  onSubmit: onSubmitStep,
926
927
  schema: step == null ? void 0 : step.schema,
927
- resolver: step == null ? void 0 : step.resolver
928
+ resolver: (step == null ? void 0 : step.schema) ? (
929
+ /* @todo fix resolver type */
930
+ resolver == null ? void 0 : resolver(step.schema)
931
+ ) : void 0
928
932
  };
929
933
  }, [steps, onSubmitStep, activeStep]);
930
934
  const updateStep = React12.useCallback(
931
935
  (step) => {
936
+ const stepOptions = options == null ? void 0 : options.find((s) => s.name === step.name);
932
937
  updateSteps((steps2) => {
933
938
  return {
934
939
  ...steps2,
935
- [step.name]: step
940
+ [step.name]: {
941
+ ...step,
942
+ schema: stepOptions == null ? void 0 : stepOptions.schema
943
+ }
936
944
  };
937
945
  });
938
946
  },
939
- [steps]
947
+ [steps, options]
940
948
  );
941
949
  return {
942
950
  getFormProps,
@@ -959,13 +967,23 @@ function useFormStep(props) {
959
967
  }
960
968
  var FormStepper = (props) => {
961
969
  const { activeIndex, setIndex } = useStepperContext();
962
- const { children, orientation, variant, colorScheme, size, ...rest } = props;
970
+ const {
971
+ children,
972
+ orientation,
973
+ variant,
974
+ colorScheme,
975
+ size,
976
+ onChange: onChangeProp,
977
+ render,
978
+ ...rest
979
+ } = props;
963
980
  const elements = React12.Children.map(children, (child) => {
964
981
  if (React12.isValidElement(child) && (child == null ? void 0 : child.type) === FormStep) {
965
982
  const { isCompleted } = useFormStep(child.props);
966
983
  return /* @__PURE__ */ jsx(
967
- StepperStep,
984
+ StepsItem,
968
985
  {
986
+ render,
969
987
  name: child.props.name,
970
988
  title: child.props.title,
971
989
  isCompleted,
@@ -978,9 +996,10 @@ var FormStepper = (props) => {
978
996
  });
979
997
  const onChange = React12.useCallback((i) => {
980
998
  setIndex(i);
999
+ onChangeProp == null ? void 0 : onChangeProp(i);
981
1000
  }, []);
982
1001
  return /* @__PURE__ */ jsx(
983
- StepperContainer,
1002
+ Steps,
984
1003
  {
985
1004
  orientation,
986
1005
  step: activeIndex,
@@ -988,13 +1007,13 @@ var FormStepper = (props) => {
988
1007
  colorScheme,
989
1008
  size,
990
1009
  onChange,
991
- children: /* @__PURE__ */ jsx(StepperSteps, { mb: "4", ...props, children: elements })
1010
+ children: elements
992
1011
  }
993
1012
  );
994
1013
  };
995
1014
  var FormStep = (props) => {
996
- const { name, schema, resolver, children, className, onSubmit, ...rest } = props;
997
- const step = useFormStep({ name, schema, resolver, onSubmit });
1015
+ const { name, children, className, onSubmit, ...rest } = props;
1016
+ const step = useFormStep({ name, onSubmit });
998
1017
  const { isActive } = step;
999
1018
  return isActive ? /* @__PURE__ */ jsx(chakra.div, { ...rest, className: cx("sui-form__step", className), children }) : null;
1000
1019
  };
@@ -1171,26 +1190,31 @@ function createForm({
1171
1190
  DefaultForm.id = "Form";
1172
1191
  return DefaultForm;
1173
1192
  }
1174
- function createStepForm(Form4) {
1193
+ function createStepForm({ fields, resolver, fieldResolver } = {}) {
1175
1194
  const StepForm2 = forwardRef((props, ref) => {
1176
- const { children, ...rest } = props;
1177
- const stepper = useStepForm(props);
1195
+ const { children, steps, ...rest } = props;
1196
+ const stepper = useStepForm({
1197
+ resolver,
1198
+ fieldResolver,
1199
+ ...props
1200
+ });
1178
1201
  const { getFormProps, ...ctx } = stepper;
1179
1202
  const context = useMemo(() => ctx, [ctx]);
1180
- return /* @__PURE__ */ jsx(StepperProvider, { value: context, children: /* @__PURE__ */ jsx(StepFormProvider, { value: context, children: /* @__PURE__ */ jsx(Form4, { ref, ...rest, ...getFormProps(), children: runIfFn(children, {
1203
+ return /* @__PURE__ */ jsx(StepperProvider, { value: context, children: /* @__PURE__ */ jsx(StepFormProvider, { value: context, children: /* @__PURE__ */ jsx(FieldsProvider, { value: fields || {}, children: /* @__PURE__ */ jsx(Form2, { ref, ...rest, ...getFormProps(), children: runIfFn(children, {
1181
1204
  ...stepper,
1182
1205
  Field,
1206
+ FormStep,
1183
1207
  DisplayIf,
1184
1208
  ArrayField,
1185
1209
  ObjectField
1186
- }) }) }) });
1210
+ }) }) }) }) });
1187
1211
  });
1188
- StepForm2.displayName = `Step${Form4.displayName || Form4.name}`;
1212
+ StepForm2.displayName = `Step${Form2.displayName || Form2.name}`;
1189
1213
  return StepForm2;
1190
1214
  }
1191
- var Form3 = createForm();
1192
- var StepForm = createStepForm(Form3);
1215
+ var Form2 = createForm();
1216
+ var StepForm = createStepForm();
1193
1217
 
1194
- export { ArrayField, ArrayFieldAddButton, ArrayFieldContainer, ArrayFieldProvider, ArrayFieldRemoveButton, ArrayFieldRow, ArrayFieldRowContainer, ArrayFieldRowFields, ArrayFieldRowProvider, ArrayFieldRows, AutoFields, BaseField, Form as BaseForm, CheckboxField, DisplayField, DisplayIf, Field, FieldsProvider, Form3 as Form, FormLayout, FormLegend, FormProvider, FormStep, FormStepper, FormValue, InputField, InputRightButton, NativeSelect, NativeSelectField, NextButton, NumberInputField2 as NumberInputField, ObjectField, PasswordInput, PasswordInputField, PinField, PrevButton, RadioField, RadioInput, Select, SelectButton, SelectField, SelectList, SelectOption, StepForm, StepFormProvider, SubmitButton, SwitchField, TextareaField, WatchField, createField, createForm, defaultFieldTypes, objectFieldResolver, useArrayField, useArrayFieldAddButton, useArrayFieldContext, useArrayFieldRemoveButton, useArrayFieldRow, useArrayFieldRowContext, useField, useFormContext, useFormStep, useStepForm, useStepFormContext };
1218
+ export { ArrayField, ArrayFieldAddButton, ArrayFieldContainer, ArrayFieldProvider, ArrayFieldRemoveButton, ArrayFieldRow, ArrayFieldRowContainer, ArrayFieldRowFields, ArrayFieldRowProvider, ArrayFieldRows, AutoFields, BaseField, Form as BaseForm, CheckboxField, DisplayField, DisplayIf, Field, FieldsProvider, Form2 as Form, FormLayout, FormLegend, FormProvider, FormStep, FormStepper, FormValue, InputField, InputRightButton, NativeSelect, NativeSelectField, NextButton, NumberInputField2 as NumberInputField, ObjectField, PasswordInput, PasswordInputField, PinField, PrevButton, RadioField, RadioInput, Select, SelectButton, SelectField, SelectList, SelectOption, StepForm, StepFormProvider, SubmitButton, SwitchField, TextareaField, WatchField, createField, createForm, createStepForm, defaultFieldTypes, objectFieldResolver, useArrayField, useArrayFieldAddButton, useArrayFieldContext, useArrayFieldRemoveButton, useArrayFieldRow, useArrayFieldRowContext, useField, useFormContext, useFormStep, useStepForm, useStepFormContext };
1195
1219
  //# sourceMappingURL=out.js.map
1196
1220
  //# sourceMappingURL=index.mjs.map