@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.
- package/CHANGELOG.md +19 -0
- package/dist/array-field.d.ts +4 -1
- package/dist/array-field.d.ts.map +1 -1
- package/dist/auto-form.d.ts +1 -0
- package/dist/auto-form.d.ts.map +1 -1
- package/dist/display-field.d.ts.map +1 -1
- package/dist/display-if.d.ts +4 -1
- package/dist/display-if.d.ts.map +1 -1
- package/dist/field.d.ts.map +1 -1
- package/dist/fields.d.ts.map +1 -1
- package/dist/form.d.ts +1 -0
- package/dist/form.d.ts.map +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/index.modern.js +1 -1
- package/dist/index.modern.js.map +1 -1
- package/dist/layout.d.ts +4 -1
- package/dist/layout.d.ts.map +1 -1
- package/dist/object-field.d.ts.map +1 -1
- package/dist/step-form.d.ts +2 -1
- package/dist/step-form.d.ts.map +1 -1
- package/dist/submit-button.d.ts.map +1 -1
- package/dist/use-step-form.d.ts +8 -20
- package/dist/use-step-form.d.ts.map +1 -1
- package/dist/zod/index.js +1 -1
- package/dist/zod/index.js.map +1 -1
- package/dist/zod/index.modern.js +1 -1
- package/dist/zod/index.modern.js.map +1 -1
- package/dist/zod/{index.d.ts → zod/src/index.d.ts} +0 -0
- package/dist/zod/{index.d.ts.map → zod/src/index.d.ts.map} +0 -0
- package/dist/zod/zod-resolver.d.ts +1 -2
- package/dist/zod/zod-resolver.d.ts.map +1 -1
- package/package.json +2 -1
- package/src/array-field.tsx +33 -1
- package/src/auto-form.tsx +9 -1
- package/src/display-field.tsx +9 -0
- package/src/display-if.tsx +5 -0
- package/src/field.tsx +6 -0
- package/src/fields.tsx +5 -0
- package/src/form.tsx +8 -0
- package/src/layout.tsx +13 -1
- package/src/object-field.tsx +5 -0
- package/src/step-form.tsx +7 -2
- package/src/submit-button.tsx +5 -0
- package/src/use-step-form.tsx +21 -14
- package/zod/package.json +1 -0
package/src/object-field.tsx
CHANGED
@@ -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(
|
58
|
+
<Form ref={ref} {...rest} {...getFormProps()}>
|
54
59
|
{runIfFn(children, stepper)}
|
55
60
|
</Form>
|
56
61
|
</StepFormProvider>
|
package/src/submit-button.tsx
CHANGED
@@ -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
|
+
}
|
package/src/use-step-form.tsx
CHANGED
@@ -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
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
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
|