@saas-ui/forms 0.5.0 → 0.5.2
Sign up to get free protection for your applications and to get access to all the features.
- package/CHANGELOG.md +13 -0
- package/dist/array-field.d.ts +3 -3
- package/dist/array-field.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/step-form.d.ts +1 -1
- package/dist/step-form.d.ts.map +1 -1
- package/dist/use-array-field.d.ts +1 -1
- package/package.json +2 -1
- package/src/array-field.tsx +56 -45
- package/src/form.tsx +1 -1
- package/src/step-form.tsx +2 -1
- package/src/use-array-field.tsx +1 -1
- package/src/use-step-form.tsx +1 -1
package/dist/step-form.d.ts
CHANGED
@@ -3,7 +3,7 @@ import { FieldValues, UseFormReturn } from 'react-hook-form';
|
|
3
3
|
import { HTMLChakraProps } from '@chakra-ui/system';
|
4
4
|
import { StepperStepsProps } from '@saas-ui/stepper';
|
5
5
|
import { ButtonProps } from '@saas-ui/button';
|
6
|
-
import { FormProps } from '
|
6
|
+
import { FormProps } from './form';
|
7
7
|
import { UseStepFormProps } from './use-step-form';
|
8
8
|
export interface StepFormProps<TFieldValues extends FieldValues = FieldValues> extends UseStepFormProps<TFieldValues>, FormProps<TFieldValues> {
|
9
9
|
}
|
package/dist/step-form.d.ts.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"step-form.d.ts","sourceRoot":"","sources":["../src/step-form.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAA;AAE9B,OAAO,EAAE,WAAW,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAA;AAE5D,OAAO,EAEL,eAAe,EAGhB,MAAM,mBAAmB,CAAA;AAI1B,OAAO,EAGL,iBAAiB,EAGlB,MAAM,kBAAkB,CAAA;AACzB,OAAO,EAAU,WAAW,EAAE,MAAM,iBAAiB,CAAA;AAErD,OAAO,EAAQ,SAAS,
|
1
|
+
{"version":3,"file":"step-form.d.ts","sour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53
53
|
defaultValue?: Record<string, any>;
|
54
54
|
/**
|
55
|
-
* Default key name for rows, change this if your data uses 'id'
|
55
|
+
* Default key name for rows, change this if your data uses a different 'id' field
|
56
56
|
* @default "id"
|
57
57
|
*/
|
58
58
|
keyName?: string;
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@saas-ui/forms",
|
3
|
-
"version": "0.5.
|
3
|
+
"version": "0.5.2",
|
4
4
|
"description": "Theme and components agnostic SaasProvider",
|
5
5
|
"source": "src/index.ts",
|
6
6
|
"exports": {
|
@@ -64,6 +64,7 @@
|
|
64
64
|
"dependencies": {
|
65
65
|
"@chakra-ui/icons": "^1.1.1",
|
66
66
|
"@chakra-ui/react-utils": "^1.2.1",
|
67
|
+
"@chakra-ui/utils": "^1.10.4",
|
67
68
|
"@hookform/resolvers": "^2.8.3",
|
68
69
|
"@saas-ui/button": "0.3.0",
|
69
70
|
"@saas-ui/input-right-button": "0.3.0",
|
package/src/array-field.tsx
CHANGED
@@ -20,6 +20,7 @@ import {
|
|
20
20
|
useArrayFieldRowContext,
|
21
21
|
useArrayFieldRemoveButton,
|
22
22
|
useArrayFieldAddButton,
|
23
|
+
UseArrayFieldReturn,
|
23
24
|
} from './use-array-field'
|
24
25
|
|
25
26
|
interface ArrayField {
|
@@ -137,26 +138,28 @@ export interface ArrayFieldProps
|
|
137
138
|
extends ArrayFieldOptions,
|
138
139
|
Omit<FieldProps, 'defaultValue'> {}
|
139
140
|
|
140
|
-
export const ArrayField
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
<
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
{
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
141
|
+
export const ArrayField = React.forwardRef(
|
142
|
+
(props: ArrayFieldProps, ref: React.ForwardedRef<UseArrayFieldReturn>) => {
|
143
|
+
const { children, ...containerProps } = props
|
144
|
+
|
145
|
+
return (
|
146
|
+
<ArrayFieldContainer ref={ref} {...containerProps}>
|
147
|
+
<ArrayFieldRows>
|
148
|
+
{(fields: ArrayField[]) => (
|
149
|
+
<>
|
150
|
+
{fields.map(({ id }, index: number) => (
|
151
|
+
<ArrayFieldRow key={id} index={index}>
|
152
|
+
{children}
|
153
|
+
</ArrayFieldRow>
|
154
|
+
))}
|
155
|
+
</>
|
156
|
+
)}
|
157
|
+
</ArrayFieldRows>
|
158
|
+
<ArrayFieldAddButton />
|
159
|
+
</ArrayFieldContainer>
|
160
|
+
)
|
161
|
+
}
|
162
|
+
)
|
160
163
|
|
161
164
|
export interface ArrayFieldRowsProps {
|
162
165
|
children: (fields: ArrayField[]) => React.ReactElement | null
|
@@ -169,28 +172,36 @@ export const ArrayFieldRows = ({
|
|
169
172
|
return children(fields)
|
170
173
|
}
|
171
174
|
|
172
|
-
export const ArrayFieldContainer
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
175
|
+
export const ArrayFieldContainer = React.forwardRef(
|
176
|
+
(
|
177
|
+
{
|
178
|
+
name,
|
179
|
+
defaultValue,
|
180
|
+
keyName,
|
181
|
+
min,
|
182
|
+
max,
|
183
|
+
children,
|
184
|
+
...fieldProps
|
185
|
+
}: ArrayFieldProps,
|
186
|
+
ref: React.ForwardedRef<UseArrayFieldReturn>
|
187
|
+
) => {
|
188
|
+
const context = useArrayField({
|
189
|
+
name,
|
190
|
+
defaultValue,
|
191
|
+
keyName,
|
192
|
+
min,
|
193
|
+
max,
|
194
|
+
})
|
195
|
+
|
196
|
+
// This exposes the useArrayField api through the forwarded ref
|
197
|
+
React.useImperativeHandle(ref, () => context, [ref, context])
|
198
|
+
|
199
|
+
return (
|
200
|
+
<ArrayFieldProvider value={context}>
|
201
|
+
<BaseField name={name} {...fieldProps}>
|
202
|
+
{children}
|
203
|
+
</BaseField>
|
204
|
+
</ArrayFieldProvider>
|
205
|
+
)
|
206
|
+
}
|
207
|
+
)
|
package/src/form.tsx
CHANGED
@@ -87,7 +87,7 @@ export const Form = forwardRef(
|
|
87
87
|
const methods = useForm<TFieldValues>(form)
|
88
88
|
const { handleSubmit } = methods
|
89
89
|
|
90
|
-
// This exposes the useForm api through the
|
90
|
+
// This exposes the useForm api through the forwarded ref
|
91
91
|
React.useImperativeHandle(ref, () => methods, [ref, methods])
|
92
92
|
|
93
93
|
return (
|
package/src/step-form.tsx
CHANGED
@@ -20,7 +20,8 @@ import {
|
|
20
20
|
} from '@saas-ui/stepper'
|
21
21
|
import { Button, ButtonProps } from '@saas-ui/button'
|
22
22
|
|
23
|
-
import { Form, FormProps
|
23
|
+
import { Form, FormProps } from './form'
|
24
|
+
import { SubmitButton } from './submit-button'
|
24
25
|
|
25
26
|
import {
|
26
27
|
useStepForm,
|
package/src/use-array-field.tsx
CHANGED
@@ -69,7 +69,7 @@ export interface ArrayFieldOptions {
|
|
69
69
|
*/
|
70
70
|
defaultValue?: Record<string, any>
|
71
71
|
/**
|
72
|
-
* Default key name for rows, change this if your data uses 'id'
|
72
|
+
* Default key name for rows, change this if your data uses a different 'id' field
|
73
73
|
* @default "id"
|
74
74
|
*/
|
75
75
|
keyName?: string
|