@saas-ui/forms 0.7.4 → 0.7.7

Sign up to get free protection for your applications and to get access to all the features.
Files changed (46) hide show
  1. package/CHANGELOG.md +19 -0
  2. package/dist/array-field.d.ts +4 -1
  3. package/dist/array-field.d.ts.map +1 -1
  4. package/dist/auto-form.d.ts +1 -0
  5. package/dist/auto-form.d.ts.map +1 -1
  6. package/dist/display-field.d.ts.map +1 -1
  7. package/dist/display-if.d.ts +4 -1
  8. package/dist/display-if.d.ts.map +1 -1
  9. package/dist/field.d.ts.map +1 -1
  10. package/dist/fields.d.ts.map +1 -1
  11. package/dist/form.d.ts +1 -0
  12. package/dist/form.d.ts.map +1 -1
  13. package/dist/index.js +1 -1
  14. package/dist/index.js.map +1 -1
  15. package/dist/index.modern.js +1 -1
  16. package/dist/index.modern.js.map +1 -1
  17. package/dist/layout.d.ts +4 -1
  18. package/dist/layout.d.ts.map +1 -1
  19. package/dist/object-field.d.ts.map +1 -1
  20. package/dist/step-form.d.ts +2 -1
  21. package/dist/step-form.d.ts.map +1 -1
  22. package/dist/submit-button.d.ts.map +1 -1
  23. package/dist/use-step-form.d.ts +8 -20
  24. package/dist/use-step-form.d.ts.map +1 -1
  25. package/dist/zod/index.js +1 -1
  26. package/dist/zod/index.js.map +1 -1
  27. package/dist/zod/index.modern.js +1 -1
  28. package/dist/zod/index.modern.js.map +1 -1
  29. package/dist/zod/{index.d.ts → zod/src/index.d.ts} +0 -0
  30. package/dist/zod/{index.d.ts.map → zod/src/index.d.ts.map} +0 -0
  31. package/dist/zod/zod-resolver.d.ts +1 -2
  32. package/dist/zod/zod-resolver.d.ts.map +1 -1
  33. package/package.json +2 -1
  34. package/src/array-field.tsx +33 -1
  35. package/src/auto-form.tsx +9 -1
  36. package/src/display-field.tsx +9 -0
  37. package/src/display-if.tsx +5 -0
  38. package/src/field.tsx +6 -0
  39. package/src/fields.tsx +5 -0
  40. package/src/form.tsx +8 -0
  41. package/src/layout.tsx +13 -1
  42. package/src/object-field.tsx +5 -0
  43. package/src/step-form.tsx +7 -2
  44. package/src/submit-button.tsx +5 -0
  45. package/src/use-step-form.tsx +21 -14
  46. package/zod/package.json +1 -0
@@ -6,6 +6,7 @@ import {
6
6
  ResponsiveValue,
7
7
  useStyles,
8
8
  } from '@chakra-ui/react'
9
+ import { __DEV__ } from '@chakra-ui/utils'
9
10
 
10
11
  import { FormLayout } from './layout'
11
12
  import { FieldProps } from './field'
@@ -37,3 +38,7 @@ export const ObjectField: React.FC<ObjectFieldProps> = (props) => {
37
38
  </FormControl>
38
39
  )
39
40
  }
41
+
42
+ if (__DEV__) {
43
+ ObjectField.displayName = 'ObjectField'
44
+ }
package/src/step-form.tsx CHANGED
@@ -28,11 +28,16 @@ import {
28
28
  useFormStep,
29
29
  StepFormProvider,
30
30
  UseStepFormProps,
31
+ UseStepFormReturn,
31
32
  } from './use-step-form'
32
33
 
33
34
  export interface StepFormProps<TFieldValues extends FieldValues = FieldValues>
34
35
  extends UseStepFormProps<TFieldValues>,
35
- FormProps<TFieldValues> {}
36
+ FormProps<TFieldValues> {
37
+ children:
38
+ | React.ReactNode
39
+ | ((stepper: UseStepFormReturn<TFieldValues>) => React.ReactElement)
40
+ }
36
41
 
37
42
  export const StepForm = React.forwardRef(
38
43
  <TFieldValues extends FieldValues = FieldValues>(
@@ -50,7 +55,7 @@ export const StepForm = React.forwardRef(
50
55
  return (
51
56
  <StepperProvider value={context}>
52
57
  <StepFormProvider value={context}>
53
- <Form ref={ref} {...rest} {...getFormProps(props)}>
58
+ <Form ref={ref} {...rest} {...getFormProps()}>
54
59
  {runIfFn(children, stepper)}
55
60
  </Form>
56
61
  </StepFormProvider>
@@ -5,6 +5,7 @@ import { useFormContext } from 'react-hook-form'
5
5
  import { Button, ButtonProps } from '@saas-ui/button'
6
6
 
7
7
  import { forwardRef } from '@chakra-ui/system'
8
+ import { __DEV__ } from '@chakra-ui/utils'
8
9
 
9
10
  export interface SubmitButtonProps extends ButtonProps {
10
11
  /**
@@ -52,3 +53,7 @@ SubmitButton.defaultProps = {
52
53
  disableIfUntouched: false,
53
54
  disableIfInvalid: false,
54
55
  }
56
+
57
+ if (__DEV__) {
58
+ SubmitButton.displayName = 'SubmitButton'
59
+ }
@@ -35,9 +35,21 @@ export interface UseStepFormProps<
35
35
  > extends UseStepperProps,
36
36
  FormProps<TFieldValues> {}
37
37
 
38
+ export interface UseStepFormReturn<
39
+ TFieldValues extends FieldValues = FieldValues
40
+ > extends UseStepperReturn {
41
+ getFormProps(): {
42
+ onSubmit: SubmitHandler<TFieldValues>
43
+ schema?: any
44
+ resolver?: any
45
+ }
46
+ updateStep(step: any): void
47
+ steps: Record<string, any>
48
+ }
49
+
38
50
  export function useStepForm<TFieldValues extends FieldValues = FieldValues>(
39
51
  props: UseStepFormProps<TFieldValues>
40
- ) {
52
+ ): UseStepFormReturn<TFieldValues> {
41
53
  const stepper = useStepper(props)
42
54
 
43
55
  const { activeStep, isLastStep, nextStep } = stepper
@@ -64,17 +76,14 @@ export function useStepForm<TFieldValues extends FieldValues = FieldValues>(
64
76
  [activeStep, isLastStep]
65
77
  )
66
78
 
67
- const getFormProps = React.useCallback(
68
- (props) => {
69
- const step = steps[activeStep]
70
- return {
71
- onSubmit: onSubmitStep,
72
- schema: step?.schema,
73
- resolver: step?.resolver,
74
- }
75
- },
76
- [steps, onSubmitStep, activeStep]
77
- )
79
+ const getFormProps = React.useCallback(() => {
80
+ const step = steps[activeStep]
81
+ return {
82
+ onSubmit: onSubmitStep,
83
+ schema: step?.schema,
84
+ resolver: step?.resolver,
85
+ }
86
+ }, [steps, onSubmitStep, activeStep])
78
87
 
79
88
  const updateStep = React.useCallback(
80
89
  (step) => {
@@ -96,8 +105,6 @@ export function useStepForm<TFieldValues extends FieldValues = FieldValues>(
96
105
  }
97
106
  }
98
107
 
99
- export type UseStepFormReturn = ReturnType<typeof useStepForm>
100
-
101
108
  export interface UseFormStepProps {
102
109
  name: string
103
110
  schema?: any
package/zod/package.json CHANGED
@@ -21,6 +21,7 @@
21
21
  "author": "Eelco Wiersma <eelco@appulse.nl>",
22
22
  "license": "MIT",
23
23
  "peerDependencies": {
24
+ "@chakra-ui/utils": "^1.10.4",
24
25
  "@hookform/resolvers": "^2.8.3",
25
26
  "react-hook-form": "^7.22.0",
26
27
  "zod": "^3.14.4"