@vritti/quantum-ui 0.1.22 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/Button.d.ts +10 -3
- package/dist/Button.js +21 -36
- package/dist/Button.js.map +1 -1
- package/dist/Button2.js +42 -0
- package/dist/Button2.js.map +1 -0
- package/dist/Card.d.ts +8 -8
- package/dist/Card.js.map +1 -1
- package/dist/Checkbox.d.ts +5 -8
- package/dist/Checkbox.js +38 -278
- package/dist/Checkbox.js.map +1 -1
- package/dist/DatePicker.d.ts +68 -0
- package/dist/DatePicker.js +12038 -0
- package/dist/DatePicker.js.map +1 -0
- package/dist/Form.d.ts +70 -88
- package/dist/Form.js +34 -30
- package/dist/Form.js.map +1 -1
- package/dist/Label.js +40 -0
- package/dist/Label.js.map +1 -0
- package/dist/OTPField.js +2 -12
- package/dist/OTPField.js.map +1 -1
- package/dist/PasswordField.js.map +1 -1
- package/dist/PhoneField.js +6 -12
- package/dist/PhoneField.js.map +1 -1
- package/dist/Skeleton.d.ts +6 -0
- package/dist/Skeleton.js +9 -0
- package/dist/Skeleton.js.map +1 -0
- package/dist/Spinner.d.ts +14 -0
- package/dist/Spinner.js +31 -0
- package/dist/Spinner.js.map +1 -0
- package/dist/TextArea.js +4 -10
- package/dist/TextArea.js.map +1 -1
- package/dist/TextField.js.map +1 -1
- package/dist/ThemeToggle.js.map +1 -1
- package/dist/Typography.js.map +1 -1
- package/dist/assets/quantum-ui.css +66 -44
- package/dist/axios.d.ts +11 -6
- package/dist/axios.js +186 -147
- package/dist/axios.js.map +1 -1
- package/dist/components/Button.d.ts +7 -0
- package/dist/components/Button.js +2 -1
- package/dist/components/Button.js.map +1 -1
- package/dist/components/Card.d.ts +7 -0
- package/dist/components/Checkbox.d.ts +7 -0
- package/dist/components/DatePicker.d.ts +9 -0
- package/dist/components/DatePicker.js +2 -0
- package/dist/components/DatePicker.js.map +1 -0
- package/dist/components/Form.d.ts +7 -0
- package/dist/components/Form.js +1 -1
- package/dist/components/OTPField.d.ts +7 -0
- package/dist/components/PasswordField.d.ts +7 -0
- package/dist/components/PhoneField.d.ts +7 -0
- package/dist/components/Progress.d.ts +7 -0
- package/dist/components/Progress.js +2 -5
- package/dist/components/Progress.js.map +1 -1
- package/dist/components/Skeleton.d.ts +9 -0
- package/dist/components/Skeleton.js +2 -0
- package/dist/components/Skeleton.js.map +1 -0
- package/dist/components/Spinner.d.ts +9 -0
- package/dist/components/Spinner.js +2 -0
- package/dist/components/Spinner.js.map +1 -0
- package/dist/components/TextArea.d.ts +7 -0
- package/dist/components/TextField.d.ts +7 -0
- package/dist/components/ThemeToggle.d.ts +7 -0
- package/dist/components/Typography.d.ts +7 -0
- package/dist/createLucideIcon.js.map +1 -1
- package/dist/field.js +26 -177
- package/dist/field.js.map +1 -1
- package/dist/index.d.ts +146 -142
- package/dist/index.js +10 -7
- package/dist/index.js.map +1 -1
- package/dist/index2.js +54 -116
- package/dist/index2.js.map +1 -1
- package/dist/index3.js +103 -1
- package/dist/index3.js.map +1 -1
- package/dist/index4.js +31 -55
- package/dist/index4.js.map +1 -1
- package/dist/index5.js +90 -3
- package/dist/index5.js.map +1 -1
- package/dist/index6.js +246 -0
- package/dist/index6.js.map +1 -0
- package/dist/shadcn/shadcnField.d.ts +7 -0
- package/dist/utils/axios.d.ts +21 -6
- package/dist/utils/axios.js +1 -1
- package/dist/utils.js.map +1 -1
- package/package.json +33 -17
- package/dist/AuthProvider.d.ts +0 -34
- package/dist/OnboardingProvider.js +0 -113
- package/dist/OnboardingProvider.js.map +0 -1
- package/dist/context/AuthProvider.d.ts +0 -2
- package/dist/context/AuthProvider.js +0 -2
- package/dist/context/AuthProvider.js.map +0 -1
package/dist/Form.d.ts
CHANGED
|
@@ -1,19 +1,19 @@
|
|
|
1
1
|
import { Controller } from 'react-hook-form';
|
|
2
|
-
import { default as default_2 } from 'react';
|
|
3
2
|
import { FieldValues } from 'react-hook-form';
|
|
4
3
|
import { JSX } from 'react/jsx-runtime';
|
|
5
4
|
import * as LabelPrimitive from '@radix-ui/react-label';
|
|
6
5
|
import * as React_2 from 'react';
|
|
7
6
|
import { UseFormReturn } from 'react-hook-form';
|
|
7
|
+
import { UseMutationResult } from '@tanstack/react-query';
|
|
8
8
|
import { VariantProps } from 'class-variance-authority';
|
|
9
9
|
|
|
10
10
|
export { Controller }
|
|
11
11
|
|
|
12
12
|
export declare function Field({
|
|
13
13
|
className,
|
|
14
|
-
orientation =
|
|
14
|
+
orientation = 'vertical',
|
|
15
15
|
...props
|
|
16
|
-
}: React.ComponentProps<
|
|
16
|
+
}: React.ComponentProps<'div'> & VariantProps<typeof fieldVariants>) {
|
|
17
17
|
return (
|
|
18
18
|
<div
|
|
19
19
|
role="group"
|
|
@@ -22,35 +22,32 @@ export declare function Field({
|
|
|
22
22
|
className={cn(fieldVariants({ orientation }), className)}
|
|
23
23
|
{...props}
|
|
24
24
|
/>
|
|
25
|
-
)
|
|
25
|
+
);
|
|
26
26
|
}
|
|
27
27
|
|
|
28
|
-
export declare function FieldContent({ className, ...props }: React.ComponentProps<
|
|
28
|
+
export declare function FieldContent({ className, ...props }: React.ComponentProps<'div'>) {
|
|
29
29
|
return (
|
|
30
30
|
<div
|
|
31
31
|
data-slot="field-content"
|
|
32
|
-
className={cn(
|
|
33
|
-
"group/field-content flex flex-1 flex-col gap-1.5 leading-snug",
|
|
34
|
-
className
|
|
35
|
-
)}
|
|
32
|
+
className={cn('group/field-content flex flex-1 flex-col gap-1.5 leading-snug', className)}
|
|
36
33
|
{...props}
|
|
37
34
|
/>
|
|
38
|
-
)
|
|
35
|
+
);
|
|
39
36
|
}
|
|
40
37
|
|
|
41
|
-
export declare function FieldDescription({ className, ...props }: React.ComponentProps<
|
|
38
|
+
export declare function FieldDescription({ className, ...props }: React.ComponentProps<'p'>) {
|
|
42
39
|
return (
|
|
43
40
|
<p
|
|
44
41
|
data-slot="field-description"
|
|
45
42
|
className={cn(
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
className
|
|
43
|
+
'text-muted-foreground text-sm leading-normal font-normal group-has-[[data-orientation=horizontal]]/field:text-balance',
|
|
44
|
+
'last:mt-0 nth-last-2:-mt-1 [[data-variant=legend]+&]:-mt-1.5',
|
|
45
|
+
'[&>a:hover]:text-primary [&>a]:underline [&>a]:underline-offset-4',
|
|
46
|
+
className,
|
|
50
47
|
)}
|
|
51
48
|
{...props}
|
|
52
49
|
/>
|
|
53
|
-
)
|
|
50
|
+
);
|
|
54
51
|
}
|
|
55
52
|
|
|
56
53
|
export declare function FieldError({
|
|
@@ -58,97 +55,86 @@ export declare function FieldError({
|
|
|
58
55
|
children,
|
|
59
56
|
errors,
|
|
60
57
|
...props
|
|
61
|
-
}: React.ComponentProps<
|
|
62
|
-
errors?: Array<{ message?: string } | undefined
|
|
58
|
+
}: React.ComponentProps<'div'> & {
|
|
59
|
+
errors?: Array<{ message?: string } | undefined>;
|
|
63
60
|
}) {
|
|
64
61
|
const content = useMemo(() => {
|
|
65
62
|
if (children) {
|
|
66
|
-
return children
|
|
63
|
+
return children;
|
|
67
64
|
}
|
|
68
65
|
|
|
69
66
|
if (!errors?.length) {
|
|
70
|
-
return null
|
|
67
|
+
return null;
|
|
71
68
|
}
|
|
72
69
|
|
|
73
|
-
if (errors?.length
|
|
74
|
-
return errors[0]?.message
|
|
70
|
+
if (errors?.length === 1) {
|
|
71
|
+
return errors[0]?.message;
|
|
75
72
|
}
|
|
76
73
|
|
|
77
74
|
return (
|
|
78
75
|
<ul className="ml-4 flex list-disc flex-col gap-1">
|
|
79
|
-
{errors.map(
|
|
80
|
-
(error, index) =>
|
|
81
|
-
error?.message && <li key={index}>{error.message}</li>
|
|
82
|
-
)}
|
|
76
|
+
{errors.map((error) => error?.message && <li key={error.message}>{error.message}</li>)}
|
|
83
77
|
</ul>
|
|
84
|
-
)
|
|
85
|
-
}, [children, errors])
|
|
78
|
+
);
|
|
79
|
+
}, [children, errors]);
|
|
86
80
|
|
|
87
81
|
if (!content) {
|
|
88
|
-
return null
|
|
82
|
+
return null;
|
|
89
83
|
}
|
|
90
84
|
|
|
91
85
|
return (
|
|
92
86
|
<div
|
|
93
87
|
role="alert"
|
|
94
88
|
data-slot="field-error"
|
|
95
|
-
className={cn(
|
|
89
|
+
className={cn('text-destructive text-sm font-normal', className)}
|
|
96
90
|
{...props}
|
|
97
91
|
>
|
|
98
92
|
{content}
|
|
99
93
|
</div>
|
|
100
|
-
)
|
|
94
|
+
);
|
|
101
95
|
}
|
|
102
96
|
|
|
103
|
-
export declare function FieldGroup({ className, ...props }: React.ComponentProps<
|
|
97
|
+
export declare function FieldGroup({ className, ...props }: React.ComponentProps<'div'>) {
|
|
104
98
|
return (
|
|
105
99
|
<div
|
|
106
100
|
data-slot="field-group"
|
|
107
101
|
className={cn(
|
|
108
|
-
|
|
109
|
-
className
|
|
102
|
+
'group/field-group @container/field-group flex w-full flex-col gap-2 data-[slot=checkbox-group]:gap-1 [&>[data-slot=field-group]]:gap-2',
|
|
103
|
+
className,
|
|
110
104
|
)}
|
|
111
105
|
{...props}
|
|
112
106
|
/>
|
|
113
|
-
)
|
|
107
|
+
);
|
|
114
108
|
}
|
|
115
109
|
|
|
116
|
-
export declare function FieldLabel({
|
|
117
|
-
className,
|
|
118
|
-
...props
|
|
119
|
-
}: React.ComponentProps<typeof Label>) {
|
|
110
|
+
export declare function FieldLabel({ className, ...props }: React.ComponentProps<typeof Label>) {
|
|
120
111
|
return (
|
|
121
112
|
<Label
|
|
122
113
|
data-slot="field-label"
|
|
123
114
|
className={cn(
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
className
|
|
115
|
+
'group/field-label peer/field-label flex w-fit gap-2 leading-snug group-data-[disabled=true]/field:opacity-50',
|
|
116
|
+
'has-[>[data-slot=field]]:w-full has-[>[data-slot=field]]:flex-col has-[>[data-slot=field]]:rounded-md has-[>[data-slot=field]]:border [&>*]:data-[slot=field]:p-4',
|
|
117
|
+
'has-data-[state=checked]:bg-primary/5 has-data-[state=checked]:border-primary dark:has-data-[state=checked]:bg-primary/10',
|
|
118
|
+
className,
|
|
128
119
|
)}
|
|
129
120
|
{...props}
|
|
130
121
|
/>
|
|
131
|
-
)
|
|
122
|
+
);
|
|
132
123
|
}
|
|
133
124
|
|
|
134
125
|
export declare function FieldLegend({
|
|
135
126
|
className,
|
|
136
|
-
variant =
|
|
127
|
+
variant = 'legend',
|
|
137
128
|
...props
|
|
138
|
-
}: React.ComponentProps<
|
|
129
|
+
}: React.ComponentProps<'legend'> & { variant?: 'legend' | 'label' }) {
|
|
139
130
|
return (
|
|
140
131
|
<legend
|
|
141
132
|
data-slot="field-legend"
|
|
142
133
|
data-variant={variant}
|
|
143
|
-
className={cn(
|
|
144
|
-
"mb-3 font-medium",
|
|
145
|
-
"data-[variant=legend]:text-base",
|
|
146
|
-
"data-[variant=label]:text-sm",
|
|
147
|
-
className
|
|
148
|
-
)}
|
|
134
|
+
className={cn('mb-3 font-medium', 'data-[variant=legend]:text-base', 'data-[variant=label]:text-sm', className)}
|
|
149
135
|
{...props}
|
|
150
136
|
/>
|
|
151
|
-
)
|
|
137
|
+
);
|
|
152
138
|
}
|
|
153
139
|
|
|
154
140
|
declare interface FieldMapping {
|
|
@@ -159,17 +145,14 @@ export declare function FieldSeparator({
|
|
|
159
145
|
children,
|
|
160
146
|
className,
|
|
161
147
|
...props
|
|
162
|
-
}: React.ComponentProps<
|
|
163
|
-
children?: React.ReactNode
|
|
148
|
+
}: React.ComponentProps<'div'> & {
|
|
149
|
+
children?: React.ReactNode;
|
|
164
150
|
}) {
|
|
165
151
|
return (
|
|
166
152
|
<div
|
|
167
153
|
data-slot="field-separator"
|
|
168
154
|
data-content={!!children}
|
|
169
|
-
className={cn(
|
|
170
|
-
"relative -my-2 h-5 text-sm group-data-[variant=outline]/field-group:-mb-2",
|
|
171
|
-
className
|
|
172
|
-
)}
|
|
155
|
+
className={cn('relative -my-2 h-5 text-sm group-data-[variant=outline]/field-group:-mb-2', className)}
|
|
173
156
|
{...props}
|
|
174
157
|
>
|
|
175
158
|
<Separator className="absolute inset-0 top-1/2" />
|
|
@@ -182,83 +165,82 @@ export declare function FieldSeparator({
|
|
|
182
165
|
</span>
|
|
183
166
|
)}
|
|
184
167
|
</div>
|
|
185
|
-
)
|
|
168
|
+
);
|
|
186
169
|
}
|
|
187
170
|
|
|
188
|
-
export declare function FieldSet({ className, ...props }: React.ComponentProps<
|
|
171
|
+
export declare function FieldSet({ className, ...props }: React.ComponentProps<'fieldset'>) {
|
|
189
172
|
return (
|
|
190
173
|
<fieldset
|
|
191
174
|
data-slot="field-set"
|
|
192
175
|
className={cn(
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
className
|
|
176
|
+
'flex flex-col gap-4',
|
|
177
|
+
'has-[>[data-slot=checkbox-group]]:gap-3 has-[>[data-slot=radio-group]]:gap-3',
|
|
178
|
+
className,
|
|
196
179
|
)}
|
|
197
180
|
{...props}
|
|
198
181
|
/>
|
|
199
|
-
)
|
|
182
|
+
);
|
|
200
183
|
}
|
|
201
184
|
|
|
202
|
-
export declare function FieldTitle({ className, ...props }: React.ComponentProps<
|
|
185
|
+
export declare function FieldTitle({ className, ...props }: React.ComponentProps<'div'>) {
|
|
203
186
|
return (
|
|
204
187
|
<div
|
|
205
188
|
data-slot="field-label"
|
|
206
189
|
className={cn(
|
|
207
|
-
|
|
208
|
-
className
|
|
190
|
+
'flex w-fit items-center gap-2 text-sm leading-snug font-medium group-data-[disabled=true]/field:opacity-50',
|
|
191
|
+
className,
|
|
209
192
|
)}
|
|
210
193
|
{...props}
|
|
211
194
|
/>
|
|
212
|
-
)
|
|
195
|
+
);
|
|
213
196
|
}
|
|
214
197
|
|
|
215
|
-
declare const fieldVariants = cva(
|
|
216
|
-
"group/field flex w-full gap-2 data-[invalid=true]:text-destructive",
|
|
217
|
-
{
|
|
198
|
+
declare const fieldVariants = cva('group/field flex w-full gap-2 data-[invalid=true]:text-destructive', {
|
|
218
199
|
variants: {
|
|
219
200
|
orientation: {
|
|
220
|
-
vertical: [
|
|
201
|
+
vertical: ['flex-col [&>*]:w-full [&>.sr-only]:w-auto'],
|
|
221
202
|
horizontal: [
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
203
|
+
'flex-row items-center',
|
|
204
|
+
'[&>[data-slot=field-label]]:flex-auto',
|
|
205
|
+
'has-[>[data-slot=field-content]]:items-start has-[>[data-slot=field-content]]:[&>[role=checkbox],[role=radio]]:mt-px',
|
|
225
206
|
],
|
|
226
207
|
responsive: [
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
208
|
+
'flex-col [&>*]:w-full [&>.sr-only]:w-auto @md/field-group:flex-row @md/field-group:items-center @md/field-group:[&>*]:w-auto',
|
|
209
|
+
'@md/field-group:[&>[data-slot=field-label]]:flex-auto',
|
|
210
|
+
'@md/field-group:has-[>[data-slot=field-content]]:items-start @md/field-group:has-[>[data-slot=field-content]]:[&>[role=checkbox],[role=radio]]:mt-px',
|
|
230
211
|
],
|
|
231
212
|
},
|
|
232
213
|
},
|
|
233
214
|
defaultVariants: {
|
|
234
|
-
orientation:
|
|
215
|
+
orientation: 'vertical',
|
|
235
216
|
},
|
|
236
|
-
}
|
|
237
|
-
);
|
|
217
|
+
});
|
|
238
218
|
|
|
239
|
-
export declare function Form<TFieldValues extends FieldValues = FieldValues, TContext = any, TTransformedValues extends FieldValues | undefined = TFieldValues>({ form, onSubmit, children, showRootError, rootErrorPosition, rootErrorClassName, fieldMapping, ...props }: FormProps<TFieldValues, TContext, TTransformedValues>): JSX.Element;
|
|
219
|
+
export declare function Form<TFieldValues extends FieldValues = FieldValues, TContext = any, TTransformedValues extends FieldValues | undefined = TFieldValues, TMutationData = unknown, TMutationError = Error, TMutationVariables = any>({ form, onSubmit, children, showRootError, rootErrorPosition, rootErrorClassName, fieldMapping, mutation, transformSubmit, ...props }: FormProps<TFieldValues, TContext, TTransformedValues, TMutationData, TMutationError, TMutationVariables>): JSX.Element;
|
|
240
220
|
|
|
241
221
|
export declare namespace Form {
|
|
242
222
|
var displayName: string;
|
|
243
223
|
}
|
|
244
224
|
|
|
245
|
-
export declare interface FormProps<TFieldValues extends FieldValues = FieldValues, TContext = any, TTransformedValues extends FieldValues | undefined = TFieldValues> extends Omit<
|
|
225
|
+
export declare interface FormProps<TFieldValues extends FieldValues = FieldValues, TContext = any, TTransformedValues extends FieldValues | undefined = TFieldValues, TMutationData = unknown, TMutationError = Error, TMutationVariables = any> extends Omit<React_2.FormHTMLAttributes<HTMLFormElement>, 'onSubmit'> {
|
|
246
226
|
form: UseFormReturn<TFieldValues, TContext, TTransformedValues>;
|
|
247
|
-
onSubmit
|
|
248
|
-
children:
|
|
227
|
+
onSubmit?: Parameters<UseFormReturn<TFieldValues, TContext, TTransformedValues>['handleSubmit']>[0];
|
|
228
|
+
children: React_2.ReactNode;
|
|
249
229
|
showRootError?: boolean;
|
|
250
230
|
rootErrorPosition?: 'top' | 'bottom';
|
|
251
231
|
rootErrorClassName?: string;
|
|
252
232
|
fieldMapping?: FieldMapping;
|
|
233
|
+
mutation?: UseMutationResult<TMutationData, TMutationError, TMutationVariables, unknown>;
|
|
234
|
+
transformSubmit?: (data: TTransformedValues extends undefined ? TFieldValues : TTransformedValues) => TMutationVariables;
|
|
253
235
|
}
|
|
254
236
|
|
|
255
237
|
declare function Label({ className, ...props }: React_2.ComponentProps<typeof LabelPrimitive.Root>) {
|
|
256
238
|
return (
|
|
257
239
|
<LabelPrimitive.Root
|
|
258
|
-
data-slot=
|
|
240
|
+
data-slot="label"
|
|
259
241
|
className={cn(
|
|
260
242
|
'flex items-center gap-2 text-sm leading-none font-medium select-none group-data-[disabled=true]:pointer-events-none group-data-[disabled=true]:opacity-50 peer-disabled:cursor-not-allowed peer-disabled:opacity-50',
|
|
261
|
-
className
|
|
243
|
+
className,
|
|
262
244
|
)}
|
|
263
245
|
{...props}
|
|
264
246
|
/>
|
package/dist/Form.js
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
import { jsx, jsxs } from 'react/jsx-runtime';
|
|
2
|
+
import * as React from 'react';
|
|
2
3
|
import React__default from 'react';
|
|
3
4
|
import { c as FieldError } from './field.js';
|
|
4
5
|
import { c as cn } from './utils.js';
|
|
6
|
+
import { B as Button } from './Button.js';
|
|
5
7
|
import { C as Checkbox } from './Checkbox.js';
|
|
6
8
|
|
|
7
9
|
var isCheckBoxInput = (element) => element.type === 'checkbox';
|
|
@@ -603,10 +605,7 @@ function useController(props) {
|
|
|
603
605
|
const Controller = (props) => props.render(useController(props));
|
|
604
606
|
|
|
605
607
|
function mapApiErrorsToForm(error, form, options = {}) {
|
|
606
|
-
const {
|
|
607
|
-
fieldMapping = {},
|
|
608
|
-
setRootError = true
|
|
609
|
-
} = options;
|
|
608
|
+
const { fieldMapping = {}, setRootError = true } = options;
|
|
610
609
|
if (!error || typeof error !== "object") {
|
|
611
610
|
if (setRootError) {
|
|
612
611
|
form.setError("root", {
|
|
@@ -645,13 +644,13 @@ function mapApiErrorsToForm(error, form, options = {}) {
|
|
|
645
644
|
}
|
|
646
645
|
}
|
|
647
646
|
|
|
648
|
-
function processChildren(children, control) {
|
|
649
|
-
return
|
|
650
|
-
if (!
|
|
647
|
+
function processChildren(children, control, isSubmitting) {
|
|
648
|
+
return React.Children.map(children, (child) => {
|
|
649
|
+
if (!React.isValidElement(child)) {
|
|
651
650
|
return child;
|
|
652
651
|
}
|
|
653
652
|
const childProps = child.props;
|
|
654
|
-
const isFragment = child.type ===
|
|
653
|
+
const isFragment = child.type === React.Fragment;
|
|
655
654
|
if (!isFragment && childProps.name && typeof childProps.name === "string") {
|
|
656
655
|
const name = childProps.name;
|
|
657
656
|
return /* @__PURE__ */ jsx(
|
|
@@ -667,7 +666,7 @@ function processChildren(children, control) {
|
|
|
667
666
|
onBlur: field.onBlur,
|
|
668
667
|
ref: field.ref
|
|
669
668
|
} : field;
|
|
670
|
-
return
|
|
669
|
+
return React.cloneElement(child, {
|
|
671
670
|
...childProps,
|
|
672
671
|
...fieldProps,
|
|
673
672
|
error: fieldState.error?.message || (fieldState.error ? "Invalid" : void 0),
|
|
@@ -679,13 +678,22 @@ function processChildren(children, control) {
|
|
|
679
678
|
name
|
|
680
679
|
);
|
|
681
680
|
}
|
|
681
|
+
if (childProps.type === "submit") {
|
|
682
|
+
const isButtonElement = child.type === Button || typeof child.type === "function" && child.type.displayName === "Button";
|
|
683
|
+
if (isButtonElement) {
|
|
684
|
+
return React.cloneElement(child, {
|
|
685
|
+
...childProps,
|
|
686
|
+
isLoading: isSubmitting
|
|
687
|
+
});
|
|
688
|
+
}
|
|
689
|
+
}
|
|
682
690
|
if (isFragment) {
|
|
683
|
-
return processChildren(childProps.children, control);
|
|
691
|
+
return processChildren(childProps.children, control, isSubmitting);
|
|
684
692
|
}
|
|
685
693
|
if (childProps.children != null) {
|
|
686
|
-
return
|
|
694
|
+
return React.cloneElement(child, {
|
|
687
695
|
...childProps,
|
|
688
|
-
children: processChildren(childProps.children, control)
|
|
696
|
+
children: processChildren(childProps.children, control, isSubmitting)
|
|
689
697
|
});
|
|
690
698
|
}
|
|
691
699
|
return child;
|
|
@@ -699,12 +707,20 @@ function Form({
|
|
|
699
707
|
rootErrorPosition = "bottom",
|
|
700
708
|
rootErrorClassName,
|
|
701
709
|
fieldMapping,
|
|
710
|
+
mutation,
|
|
711
|
+
transformSubmit,
|
|
702
712
|
...props
|
|
703
713
|
}) {
|
|
704
|
-
const
|
|
714
|
+
const isSubmitting = form.formState.isSubmitting || (mutation?.isPending ?? false);
|
|
715
|
+
const wrappedOnSubmit = React.useCallback(
|
|
705
716
|
async (data) => {
|
|
706
717
|
try {
|
|
707
|
-
|
|
718
|
+
if (mutation) {
|
|
719
|
+
const variables = transformSubmit ? transformSubmit(data) : data;
|
|
720
|
+
await mutation.mutateAsync(variables);
|
|
721
|
+
} else if (onSubmit) {
|
|
722
|
+
await onSubmit(data);
|
|
723
|
+
}
|
|
708
724
|
} catch (error) {
|
|
709
725
|
mapApiErrorsToForm(error, form, {
|
|
710
726
|
fieldMapping,
|
|
@@ -713,26 +729,14 @@ function Form({
|
|
|
713
729
|
console.error("[Form Submission Error]", error);
|
|
714
730
|
}
|
|
715
731
|
},
|
|
716
|
-
[onSubmit, fieldMapping, form, showRootError]
|
|
732
|
+
[onSubmit, mutation, transformSubmit, fieldMapping, form, showRootError]
|
|
717
733
|
);
|
|
718
734
|
const handleSubmit = form.handleSubmit(wrappedOnSubmit);
|
|
719
|
-
const processedChildren = processChildren(children, form.control);
|
|
735
|
+
const processedChildren = processChildren(children, form.control, isSubmitting);
|
|
720
736
|
return /* @__PURE__ */ jsx(FormProvider, { ...form, children: /* @__PURE__ */ jsxs("form", { onSubmit: handleSubmit, ...props, children: [
|
|
721
|
-
showRootError && rootErrorPosition === "top" && form.formState.errors.root && /* @__PURE__ */ jsx(
|
|
722
|
-
FieldError,
|
|
723
|
-
{
|
|
724
|
-
errors: [form.formState.errors.root],
|
|
725
|
-
className: cn("text-center", rootErrorClassName)
|
|
726
|
-
}
|
|
727
|
-
),
|
|
737
|
+
showRootError && rootErrorPosition === "top" && form.formState.errors.root && /* @__PURE__ */ jsx(FieldError, { errors: [form.formState.errors.root], className: cn("text-center", rootErrorClassName) }),
|
|
728
738
|
processedChildren,
|
|
729
|
-
showRootError && rootErrorPosition === "bottom" && form.formState.errors.root && /* @__PURE__ */ jsx(
|
|
730
|
-
FieldError,
|
|
731
|
-
{
|
|
732
|
-
errors: [form.formState.errors.root],
|
|
733
|
-
className: cn("text-center", rootErrorClassName)
|
|
734
|
-
}
|
|
735
|
-
)
|
|
739
|
+
showRootError && rootErrorPosition === "bottom" && form.formState.errors.root && /* @__PURE__ */ jsx(FieldError, { errors: [form.formState.errors.root], className: cn("text-center", rootErrorClassName) })
|
|
736
740
|
] }) });
|
|
737
741
|
}
|
|
738
742
|
Form.displayName = "Form";
|