@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.
@@ -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
  }
@@ -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,EAAgB,MAAM,GAAG,CAAA;AAEjD,OAAO,EAIL,gBAAgB,EACjB,MAAM,iBAAiB,CAAA;AAExB,MAAM,WAAW,aAAa,CAAC,YAAY,SAAS,WAAW,GAAG,WAAW,CAC3E,SAAQ,gBAAgB,CAAC,YAAY,CAAC,EACpC,SAAS,CAAC,YAAY,CAAC;CAAG;AAE9B,eAAO,MAAM,QAAQ;;MA2BhB,MAAM,YAAY,CAAA;AAEvB,MAAM,WAAW,eAAe;IAC9B;;OAEG;IACH,IAAI,EAAE,MAAM,CAAA;IACZ;;OAEG;IACH,MAAM,CAAC,EAAE,GAAG,CAAA;CACb;AAED,eAAO,MAAM,WAAW,EAAE,KAAK,CAAC,EAAE,CAAC,iBAAiB,CA4BnD,CAAA;AAED,MAAM,WAAW,aACf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AAC,KAAK,CAAC;CAAG;AAE7B,eAAO,MAAM,QAAQ,EAAE,KAAK,CAAC,EAAE,CAAC,aAAa,CAW5C,CAAA;AAMD,eAAO,MAAM,UAAU,EAAE,KAAK,CAAC,EAAE,CAAC,WAAW,CAY5C,CAAA;AAMD,MAAM,WAAW,eAAgB,SAAQ,WAAW;IAClD,WAAW,CAAC,EAAE,MAAM,CAAA;CACrB;AAED,eAAO,MAAM,UAAU,EAAE,KAAK,CAAC,EAAE,CAAC,eAAe,CAYhD,CAAA"}
@@ -52,7 +52,7 @@ export interface ArrayFieldOptions {
52
52
  */
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.0",
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",
@@ -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: React.FC<ArrayFieldProps> = (props) => {
141
- const { children, ...containerProps } = props
142
-
143
- return (
144
- <ArrayFieldContainer {...containerProps}>
145
- <ArrayFieldRows>
146
- {(fields: ArrayField[]) => (
147
- <>
148
- {fields.map(({ id }, index: number) => (
149
- <ArrayFieldRow key={id} index={index}>
150
- {children}
151
- </ArrayFieldRow>
152
- ))}
153
- </>
154
- )}
155
- </ArrayFieldRows>
156
- <ArrayFieldAddButton />
157
- </ArrayFieldContainer>
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: React.FC<ArrayFieldProps> = ({
173
- name,
174
- defaultValue,
175
- keyName,
176
- min,
177
- max,
178
- children,
179
- ...fieldProps
180
- }) => {
181
- const context = useArrayField({
182
- name,
183
- defaultValue,
184
- keyName,
185
- min,
186
- max,
187
- })
188
-
189
- return (
190
- <ArrayFieldProvider value={context}>
191
- <BaseField name={name} {...fieldProps}>
192
- {children}
193
- </BaseField>
194
- </ArrayFieldProvider>
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 forwareded ref
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, SubmitButton } from '.'
23
+ import { Form, FormProps } from './form'
24
+ import { SubmitButton } from './submit-button'
24
25
 
25
26
  import {
26
27
  useStepForm,
@@ -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
@@ -113,6 +113,6 @@ export function useFormStep(props: UseFormStepProps): StepState {
113
113
 
114
114
  return {
115
115
  ...step,
116
- ...(steps[name] || {}),
116
+ ...(steps[name] || { name, schema }),
117
117
  }
118
118
  }