@rachelallyson/hero-hook-form 2.2.1 → 2.4.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/CHANGELOG.md +54 -0
- package/dist/index.d.ts +827 -45
- package/dist/index.js +310 -206
- package/dist/react/index.d.ts +827 -46
- package/dist/react/index.js +316 -211
- package/package.json +7 -1
package/dist/index.js
CHANGED
|
@@ -6,7 +6,7 @@ var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require
|
|
|
6
6
|
});
|
|
7
7
|
|
|
8
8
|
// src/components/Form.tsx
|
|
9
|
-
import
|
|
9
|
+
import React18 from "react";
|
|
10
10
|
import { Button as Button3 } from "@heroui/react";
|
|
11
11
|
|
|
12
12
|
// src/hooks/useFormHelper.ts
|
|
@@ -75,19 +75,98 @@ function useFormHelper({
|
|
|
75
75
|
}
|
|
76
76
|
|
|
77
77
|
// src/components/FormField.tsx
|
|
78
|
-
import
|
|
78
|
+
import React17 from "react";
|
|
79
79
|
import { useWatch as useWatch3 } from "react-hook-form";
|
|
80
80
|
|
|
81
|
-
// src/fields/
|
|
82
|
-
import
|
|
81
|
+
// src/fields/AutocompleteField.tsx
|
|
82
|
+
import React from "react";
|
|
83
83
|
import { Controller } from "react-hook-form";
|
|
84
84
|
|
|
85
|
+
// src/ui/ind.ts
|
|
86
|
+
import { Autocomplete, AutocompleteItem } from "@heroui/autocomplete";
|
|
87
|
+
import { Button } from "@heroui/button";
|
|
88
|
+
import { Checkbox } from "@heroui/checkbox";
|
|
89
|
+
import { DateInput } from "@heroui/date-input";
|
|
90
|
+
import { DatePicker } from "@heroui/date-picker";
|
|
91
|
+
import { Input, Textarea } from "@heroui/input";
|
|
92
|
+
import { Radio, RadioGroup } from "@heroui/radio";
|
|
93
|
+
import { Select, SelectItem } from "@heroui/select";
|
|
94
|
+
import { Slider } from "@heroui/slider";
|
|
95
|
+
import { Spinner } from "@heroui/spinner";
|
|
96
|
+
import { Switch } from "@heroui/switch";
|
|
97
|
+
|
|
98
|
+
// src/fields/AutocompleteField.tsx
|
|
99
|
+
function AutocompleteField(props) {
|
|
100
|
+
const {
|
|
101
|
+
autocompleteProps,
|
|
102
|
+
children,
|
|
103
|
+
className,
|
|
104
|
+
control,
|
|
105
|
+
description,
|
|
106
|
+
isDisabled,
|
|
107
|
+
items,
|
|
108
|
+
label,
|
|
109
|
+
name,
|
|
110
|
+
placeholder,
|
|
111
|
+
rules
|
|
112
|
+
} = props;
|
|
113
|
+
return /* @__PURE__ */ React.createElement(
|
|
114
|
+
Controller,
|
|
115
|
+
{
|
|
116
|
+
control,
|
|
117
|
+
name,
|
|
118
|
+
render: ({ field: field2, fieldState }) => {
|
|
119
|
+
const selectedKey = field2.value;
|
|
120
|
+
return /* @__PURE__ */ React.createElement("div", { className }, /* @__PURE__ */ React.createElement(
|
|
121
|
+
Autocomplete,
|
|
122
|
+
{
|
|
123
|
+
...autocompleteProps,
|
|
124
|
+
description,
|
|
125
|
+
errorMessage: fieldState.error?.message,
|
|
126
|
+
isDisabled,
|
|
127
|
+
isInvalid: Boolean(fieldState.error),
|
|
128
|
+
label,
|
|
129
|
+
placeholder,
|
|
130
|
+
selectedKey: selectedKey != null ? String(selectedKey) : void 0,
|
|
131
|
+
inputValue: selectedKey != null ? void 0 : field2.value ?? "",
|
|
132
|
+
onSelectionChange: (key) => {
|
|
133
|
+
const next = key ?? "";
|
|
134
|
+
field2.onChange(next);
|
|
135
|
+
},
|
|
136
|
+
onInputChange: (value) => {
|
|
137
|
+
if (autocompleteProps?.allowsCustomValue) {
|
|
138
|
+
field2.onChange(value);
|
|
139
|
+
}
|
|
140
|
+
},
|
|
141
|
+
defaultItems: items
|
|
142
|
+
},
|
|
143
|
+
children ? children : (item) => /* @__PURE__ */ React.createElement(
|
|
144
|
+
AutocompleteItem,
|
|
145
|
+
{
|
|
146
|
+
key: String(item.value),
|
|
147
|
+
textValue: String(item.value),
|
|
148
|
+
description: item.description,
|
|
149
|
+
isDisabled: item.disabled
|
|
150
|
+
},
|
|
151
|
+
item.label
|
|
152
|
+
)
|
|
153
|
+
));
|
|
154
|
+
},
|
|
155
|
+
rules
|
|
156
|
+
}
|
|
157
|
+
);
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
// src/fields/CheckboxField.tsx
|
|
161
|
+
import React3 from "react";
|
|
162
|
+
import { Controller as Controller2 } from "react-hook-form";
|
|
163
|
+
|
|
85
164
|
// src/providers/ConfigProvider.tsx
|
|
86
|
-
import
|
|
165
|
+
import React2, { createContext, useContext, useMemo } from "react";
|
|
87
166
|
var DefaultsContext = createContext(null);
|
|
88
167
|
function HeroHookFormProvider(props) {
|
|
89
168
|
const value = useMemo(() => props.defaults ?? {}, [props.defaults]);
|
|
90
|
-
return /* @__PURE__ */
|
|
169
|
+
return /* @__PURE__ */ React2.createElement(DefaultsContext.Provider, { value }, props.children);
|
|
91
170
|
}
|
|
92
171
|
function useHeroHookFormDefaults() {
|
|
93
172
|
const cfg = useContext(DefaultsContext) ?? {};
|
|
@@ -168,18 +247,6 @@ function useHeroHookFormDefaults() {
|
|
|
168
247
|
};
|
|
169
248
|
}
|
|
170
249
|
|
|
171
|
-
// src/ui/ind.ts
|
|
172
|
-
import { Button } from "@heroui/button";
|
|
173
|
-
import { Checkbox } from "@heroui/checkbox";
|
|
174
|
-
import { DateInput } from "@heroui/date-input";
|
|
175
|
-
import { DatePicker } from "@heroui/date-picker";
|
|
176
|
-
import { Input, Textarea } from "@heroui/input";
|
|
177
|
-
import { Radio, RadioGroup } from "@heroui/radio";
|
|
178
|
-
import { Select, SelectItem } from "@heroui/select";
|
|
179
|
-
import { Slider } from "@heroui/slider";
|
|
180
|
-
import { Spinner } from "@heroui/spinner";
|
|
181
|
-
import { Switch } from "@heroui/switch";
|
|
182
|
-
|
|
183
250
|
// src/fields/CheckboxField.tsx
|
|
184
251
|
function CheckboxField(props) {
|
|
185
252
|
const {
|
|
@@ -193,12 +260,12 @@ function CheckboxField(props) {
|
|
|
193
260
|
rules
|
|
194
261
|
} = props;
|
|
195
262
|
const defaults = useHeroHookFormDefaults();
|
|
196
|
-
return /* @__PURE__ */
|
|
197
|
-
|
|
263
|
+
return /* @__PURE__ */ React3.createElement(
|
|
264
|
+
Controller2,
|
|
198
265
|
{
|
|
199
266
|
control,
|
|
200
267
|
name,
|
|
201
|
-
render: ({ field: field2, fieldState }) => /* @__PURE__ */
|
|
268
|
+
render: ({ field: field2, fieldState }) => /* @__PURE__ */ React3.createElement("div", { className }, /* @__PURE__ */ React3.createElement(
|
|
202
269
|
Checkbox,
|
|
203
270
|
{
|
|
204
271
|
...defaults.checkbox,
|
|
@@ -210,14 +277,14 @@ function CheckboxField(props) {
|
|
|
210
277
|
onValueChange: (val) => field2.onChange(val)
|
|
211
278
|
},
|
|
212
279
|
label
|
|
213
|
-
), description ? /* @__PURE__ */
|
|
280
|
+
), description ? /* @__PURE__ */ React3.createElement("p", { className: "text-small text-default-400" }, description) : null, fieldState.error?.message ? /* @__PURE__ */ React3.createElement("p", { className: "text-tiny text-danger mt-1" }, fieldState.error.message) : null),
|
|
214
281
|
rules
|
|
215
282
|
}
|
|
216
283
|
);
|
|
217
284
|
}
|
|
218
285
|
|
|
219
286
|
// src/fields/ConditionalField.tsx
|
|
220
|
-
import
|
|
287
|
+
import React4 from "react";
|
|
221
288
|
import { useWatch, useFormContext } from "react-hook-form";
|
|
222
289
|
function ConditionalField({
|
|
223
290
|
className,
|
|
@@ -231,7 +298,7 @@ function ConditionalField({
|
|
|
231
298
|
if (!shouldShow) {
|
|
232
299
|
return null;
|
|
233
300
|
}
|
|
234
|
-
return /* @__PURE__ */
|
|
301
|
+
return /* @__PURE__ */ React4.createElement("div", { className }, /* @__PURE__ */ React4.createElement(
|
|
235
302
|
FormField,
|
|
236
303
|
{
|
|
237
304
|
config: field2,
|
|
@@ -247,29 +314,29 @@ function ConditionalField({
|
|
|
247
314
|
}
|
|
248
315
|
|
|
249
316
|
// src/fields/ContentField.tsx
|
|
250
|
-
import
|
|
317
|
+
import React5 from "react";
|
|
251
318
|
function ContentField({
|
|
252
319
|
config,
|
|
253
320
|
form,
|
|
254
321
|
submissionState
|
|
255
322
|
}) {
|
|
256
323
|
if (config.render) {
|
|
257
|
-
return /* @__PURE__ */
|
|
324
|
+
return /* @__PURE__ */ React5.createElement("div", { className: config.className }, config.render({
|
|
258
325
|
errors: form.formState.errors,
|
|
259
326
|
form,
|
|
260
327
|
isSubmitting: submissionState.isSubmitting
|
|
261
328
|
}));
|
|
262
329
|
}
|
|
263
|
-
return /* @__PURE__ */
|
|
330
|
+
return /* @__PURE__ */ React5.createElement("div", { className: config.className }, config.title && /* @__PURE__ */ React5.createElement("h3", { className: "text-lg font-semibold text-foreground mb-2" }, config.title), config.description && /* @__PURE__ */ React5.createElement("p", { className: "text-sm text-muted-foreground" }, config.description));
|
|
264
331
|
}
|
|
265
332
|
|
|
266
333
|
// src/fields/DateField.tsx
|
|
267
|
-
import
|
|
268
|
-
import { Controller as
|
|
334
|
+
import React6 from "react";
|
|
335
|
+
import { Controller as Controller3 } from "react-hook-form";
|
|
269
336
|
function CoercedDateInput(props) {
|
|
270
337
|
const { dateProps, description, disabled, errorMessage, field: field2, label } = props;
|
|
271
338
|
const defaults = useHeroHookFormDefaults();
|
|
272
|
-
return /* @__PURE__ */
|
|
339
|
+
return /* @__PURE__ */ React6.createElement(
|
|
273
340
|
DateInput,
|
|
274
341
|
{
|
|
275
342
|
...defaults.dateInput,
|
|
@@ -297,12 +364,12 @@ function DateField(props) {
|
|
|
297
364
|
rules,
|
|
298
365
|
transform
|
|
299
366
|
} = props;
|
|
300
|
-
return /* @__PURE__ */
|
|
301
|
-
|
|
367
|
+
return /* @__PURE__ */ React6.createElement(
|
|
368
|
+
Controller3,
|
|
302
369
|
{
|
|
303
370
|
control,
|
|
304
371
|
name,
|
|
305
|
-
render: ({ field: field2, fieldState }) => /* @__PURE__ */
|
|
372
|
+
render: ({ field: field2, fieldState }) => /* @__PURE__ */ React6.createElement("div", { className }, /* @__PURE__ */ React6.createElement(
|
|
306
373
|
CoercedDateInput,
|
|
307
374
|
{
|
|
308
375
|
dateProps,
|
|
@@ -322,7 +389,7 @@ function DateField(props) {
|
|
|
322
389
|
}
|
|
323
390
|
|
|
324
391
|
// src/fields/DynamicSectionField.tsx
|
|
325
|
-
import
|
|
392
|
+
import React7 from "react";
|
|
326
393
|
import { useWatch as useWatch2, useFormContext as useFormContext2 } from "react-hook-form";
|
|
327
394
|
function DynamicSectionField({
|
|
328
395
|
className,
|
|
@@ -336,7 +403,7 @@ function DynamicSectionField({
|
|
|
336
403
|
if (!shouldShow) {
|
|
337
404
|
return null;
|
|
338
405
|
}
|
|
339
|
-
return /* @__PURE__ */
|
|
406
|
+
return /* @__PURE__ */ React7.createElement("div", { className }, (title || description) && /* @__PURE__ */ React7.createElement("div", { className: "mb-6" }, title && /* @__PURE__ */ React7.createElement("h3", { className: "text-lg font-semibold text-gray-900 mb-2" }, title), description && /* @__PURE__ */ React7.createElement("p", { className: "text-sm text-gray-600" }, description)), /* @__PURE__ */ React7.createElement("div", { className: "space-y-4" }, fields.map((fieldConfig, index) => /* @__PURE__ */ React7.createElement(
|
|
340
407
|
FormField,
|
|
341
408
|
{
|
|
342
409
|
key: `${fieldConfig.name}-${index}`,
|
|
@@ -353,7 +420,7 @@ function DynamicSectionField({
|
|
|
353
420
|
}
|
|
354
421
|
|
|
355
422
|
// src/fields/FieldArrayField.tsx
|
|
356
|
-
import
|
|
423
|
+
import React8 from "react";
|
|
357
424
|
import { useFieldArray, useFormContext as useFormContext3 } from "react-hook-form";
|
|
358
425
|
import { Button as Button2 } from "@heroui/react";
|
|
359
426
|
function FieldArrayField({
|
|
@@ -401,13 +468,13 @@ function FieldArrayField({
|
|
|
401
468
|
remove(index);
|
|
402
469
|
}
|
|
403
470
|
};
|
|
404
|
-
return /* @__PURE__ */
|
|
471
|
+
return /* @__PURE__ */ React8.createElement("div", { className }, /* @__PURE__ */ React8.createElement("div", { className: "space-y-4" }, fields.map((field2, index) => /* @__PURE__ */ React8.createElement(
|
|
405
472
|
"div",
|
|
406
473
|
{
|
|
407
474
|
key: field2.id,
|
|
408
475
|
className: "border border-gray-200 rounded-lg p-4 space-y-4"
|
|
409
476
|
},
|
|
410
|
-
/* @__PURE__ */
|
|
477
|
+
/* @__PURE__ */ React8.createElement("div", { className: "flex justify-between items-center" }, /* @__PURE__ */ React8.createElement("h4", { className: "text-sm font-medium text-gray-700" }, config.label, " #", index + 1), canRemove && /* @__PURE__ */ React8.createElement(
|
|
411
478
|
Button2,
|
|
412
479
|
{
|
|
413
480
|
size: "sm",
|
|
@@ -419,7 +486,7 @@ function FieldArrayField({
|
|
|
419
486
|
},
|
|
420
487
|
removeButtonText
|
|
421
488
|
)),
|
|
422
|
-
/* @__PURE__ */
|
|
489
|
+
/* @__PURE__ */ React8.createElement("div", { className: "grid grid-cols-1 md:grid-cols-2 gap-4" }, fieldConfigs.map((fieldConfig) => /* @__PURE__ */ React8.createElement(
|
|
423
490
|
FormField,
|
|
424
491
|
{
|
|
425
492
|
key: `${fieldConfig.name}-${index}`,
|
|
@@ -436,7 +503,7 @@ function FieldArrayField({
|
|
|
436
503
|
}
|
|
437
504
|
}
|
|
438
505
|
)))
|
|
439
|
-
)), canAdd && /* @__PURE__ */
|
|
506
|
+
)), canAdd && /* @__PURE__ */ React8.createElement(
|
|
440
507
|
Button2,
|
|
441
508
|
{
|
|
442
509
|
variant: "bordered",
|
|
@@ -445,7 +512,7 @@ function FieldArrayField({
|
|
|
445
512
|
className: "w-full"
|
|
446
513
|
},
|
|
447
514
|
addButtonText
|
|
448
|
-
), fields.length === 0 && /* @__PURE__ */
|
|
515
|
+
), fields.length === 0 && /* @__PURE__ */ React8.createElement("div", { className: "text-center py-8 text-gray-500" }, /* @__PURE__ */ React8.createElement("p", null, "No ", config.label?.toLowerCase(), " added yet."), /* @__PURE__ */ React8.createElement(
|
|
449
516
|
Button2,
|
|
450
517
|
{
|
|
451
518
|
variant: "bordered",
|
|
@@ -458,8 +525,8 @@ function FieldArrayField({
|
|
|
458
525
|
}
|
|
459
526
|
|
|
460
527
|
// src/fields/FileField.tsx
|
|
461
|
-
import
|
|
462
|
-
import { Controller as
|
|
528
|
+
import React9 from "react";
|
|
529
|
+
import { Controller as Controller4 } from "react-hook-form";
|
|
463
530
|
function CoercedFileInput(props) {
|
|
464
531
|
const {
|
|
465
532
|
accept,
|
|
@@ -472,7 +539,7 @@ function CoercedFileInput(props) {
|
|
|
472
539
|
multiple
|
|
473
540
|
} = props;
|
|
474
541
|
const defaults = useHeroHookFormDefaults();
|
|
475
|
-
return /* @__PURE__ */
|
|
542
|
+
return /* @__PURE__ */ React9.createElement(
|
|
476
543
|
Input,
|
|
477
544
|
{
|
|
478
545
|
...defaults.input,
|
|
@@ -508,12 +575,12 @@ function FileField(props) {
|
|
|
508
575
|
rules,
|
|
509
576
|
transform
|
|
510
577
|
} = props;
|
|
511
|
-
return /* @__PURE__ */
|
|
512
|
-
|
|
578
|
+
return /* @__PURE__ */ React9.createElement(
|
|
579
|
+
Controller4,
|
|
513
580
|
{
|
|
514
581
|
control,
|
|
515
582
|
name,
|
|
516
|
-
render: ({ field: field2, fieldState }) => /* @__PURE__ */
|
|
583
|
+
render: ({ field: field2, fieldState }) => /* @__PURE__ */ React9.createElement("div", { className }, /* @__PURE__ */ React9.createElement(
|
|
517
584
|
CoercedFileInput,
|
|
518
585
|
{
|
|
519
586
|
accept,
|
|
@@ -535,8 +602,8 @@ function FileField(props) {
|
|
|
535
602
|
}
|
|
536
603
|
|
|
537
604
|
// src/fields/FontPickerField.tsx
|
|
538
|
-
import
|
|
539
|
-
import { Controller as
|
|
605
|
+
import React10 from "react";
|
|
606
|
+
import { Controller as Controller5 } from "react-hook-form";
|
|
540
607
|
var FontPickerComponent = null;
|
|
541
608
|
var fontPickerLoaded = false;
|
|
542
609
|
var fontPickerLoading = false;
|
|
@@ -552,12 +619,12 @@ function FontPickerField(props) {
|
|
|
552
619
|
name,
|
|
553
620
|
rules
|
|
554
621
|
} = props;
|
|
555
|
-
const [fontPickerState, setFontPickerState] =
|
|
622
|
+
const [fontPickerState, setFontPickerState] = React10.useState({
|
|
556
623
|
component: FontPickerComponent,
|
|
557
624
|
error: null,
|
|
558
625
|
loading: false
|
|
559
626
|
});
|
|
560
|
-
|
|
627
|
+
React10.useEffect(() => {
|
|
561
628
|
if (fontPickerLoaded && FontPickerComponent) {
|
|
562
629
|
setFontPickerState({
|
|
563
630
|
component: FontPickerComponent,
|
|
@@ -615,17 +682,17 @@ function FontPickerField(props) {
|
|
|
615
682
|
void loadFontPicker();
|
|
616
683
|
}, []);
|
|
617
684
|
if (fontPickerState.loading) {
|
|
618
|
-
return /* @__PURE__ */
|
|
685
|
+
return /* @__PURE__ */ React10.createElement("div", { className }, /* @__PURE__ */ React10.createElement("div", { className: "space-y-2" }, label && /* @__PURE__ */ React10.createElement("label", { className: "block text-sm font-medium text-foreground" }, label), description && /* @__PURE__ */ React10.createElement("p", { className: "text-sm text-muted-foreground" }, description), /* @__PURE__ */ React10.createElement("div", { className: "p-4 border border-default-200 bg-default-50 rounded-medium" }, /* @__PURE__ */ React10.createElement("p", { className: "text-default-600 text-sm" }, "Loading font picker..."))));
|
|
619
686
|
}
|
|
620
687
|
if (!fontPickerState.component) {
|
|
621
|
-
return /* @__PURE__ */
|
|
688
|
+
return /* @__PURE__ */ React10.createElement("div", { className }, /* @__PURE__ */ React10.createElement("div", { className: "space-y-2" }, label && /* @__PURE__ */ React10.createElement("label", { className: "block text-sm font-medium text-foreground" }, label), description && /* @__PURE__ */ React10.createElement("p", { className: "text-sm text-muted-foreground" }, description), /* @__PURE__ */ React10.createElement("div", { className: "p-4 border border-warning-200 bg-warning-50 rounded-medium" }, /* @__PURE__ */ React10.createElement("p", { className: "text-warning-800 text-sm" }, "Font picker requires the @rachelallyson/heroui-font-picker package. Please install it as a peer dependency for advanced font selection features."))));
|
|
622
689
|
}
|
|
623
|
-
return /* @__PURE__ */
|
|
624
|
-
|
|
690
|
+
return /* @__PURE__ */ React10.createElement(
|
|
691
|
+
Controller5,
|
|
625
692
|
{
|
|
626
693
|
control,
|
|
627
694
|
name,
|
|
628
|
-
render: ({ field: field2, fieldState }) => /* @__PURE__ */
|
|
695
|
+
render: ({ field: field2, fieldState }) => /* @__PURE__ */ React10.createElement(
|
|
629
696
|
fontPickerState.component,
|
|
630
697
|
{
|
|
631
698
|
label,
|
|
@@ -644,12 +711,12 @@ function FontPickerField(props) {
|
|
|
644
711
|
}
|
|
645
712
|
|
|
646
713
|
// src/fields/InputField.tsx
|
|
647
|
-
import
|
|
648
|
-
import { Controller as
|
|
714
|
+
import React11 from "react";
|
|
715
|
+
import { Controller as Controller6 } from "react-hook-form";
|
|
649
716
|
function CoercedInput(props) {
|
|
650
717
|
const { description, disabled, errorMessage, field: field2, inputProps, label } = props;
|
|
651
718
|
const defaults = useHeroHookFormDefaults();
|
|
652
|
-
return /* @__PURE__ */
|
|
719
|
+
return /* @__PURE__ */ React11.createElement(
|
|
653
720
|
Input,
|
|
654
721
|
{
|
|
655
722
|
...defaults.input,
|
|
@@ -665,7 +732,7 @@ function CoercedInput(props) {
|
|
|
665
732
|
}
|
|
666
733
|
);
|
|
667
734
|
}
|
|
668
|
-
var InputField =
|
|
735
|
+
var InputField = React11.memo(
|
|
669
736
|
(props) => {
|
|
670
737
|
const {
|
|
671
738
|
className,
|
|
@@ -678,12 +745,12 @@ var InputField = React10.memo(
|
|
|
678
745
|
rules,
|
|
679
746
|
transform
|
|
680
747
|
} = props;
|
|
681
|
-
return /* @__PURE__ */
|
|
682
|
-
|
|
748
|
+
return /* @__PURE__ */ React11.createElement(
|
|
749
|
+
Controller6,
|
|
683
750
|
{
|
|
684
751
|
control,
|
|
685
752
|
name,
|
|
686
|
-
render: ({ field: field2, fieldState }) => /* @__PURE__ */
|
|
753
|
+
render: ({ field: field2, fieldState }) => /* @__PURE__ */ React11.createElement("div", { className }, /* @__PURE__ */ React11.createElement(
|
|
687
754
|
CoercedInput,
|
|
688
755
|
{
|
|
689
756
|
description,
|
|
@@ -713,8 +780,8 @@ var InputField = React10.memo(
|
|
|
713
780
|
);
|
|
714
781
|
|
|
715
782
|
// src/fields/RadioGroupField.tsx
|
|
716
|
-
import
|
|
717
|
-
import { Controller as
|
|
783
|
+
import React12 from "react";
|
|
784
|
+
import { Controller as Controller7 } from "react-hook-form";
|
|
718
785
|
function RadioGroupField(props) {
|
|
719
786
|
const {
|
|
720
787
|
className,
|
|
@@ -728,12 +795,12 @@ function RadioGroupField(props) {
|
|
|
728
795
|
rules
|
|
729
796
|
} = props;
|
|
730
797
|
const defaults = useHeroHookFormDefaults();
|
|
731
|
-
return /* @__PURE__ */
|
|
732
|
-
|
|
798
|
+
return /* @__PURE__ */ React12.createElement(
|
|
799
|
+
Controller7,
|
|
733
800
|
{
|
|
734
801
|
control,
|
|
735
802
|
name,
|
|
736
|
-
render: ({ field: field2, fieldState }) => /* @__PURE__ */
|
|
803
|
+
render: ({ field: field2, fieldState }) => /* @__PURE__ */ React12.createElement("div", { className }, /* @__PURE__ */ React12.createElement(
|
|
737
804
|
RadioGroup,
|
|
738
805
|
{
|
|
739
806
|
...defaults.radioGroup,
|
|
@@ -746,7 +813,7 @@ function RadioGroupField(props) {
|
|
|
746
813
|
onBlur: field2.onBlur,
|
|
747
814
|
onValueChange: (val) => field2.onChange(val)
|
|
748
815
|
},
|
|
749
|
-
options.map((opt) => /* @__PURE__ */
|
|
816
|
+
options.map((opt) => /* @__PURE__ */ React12.createElement(
|
|
750
817
|
Radio,
|
|
751
818
|
{
|
|
752
819
|
key: String(opt.value),
|
|
@@ -755,15 +822,15 @@ function RadioGroupField(props) {
|
|
|
755
822
|
},
|
|
756
823
|
opt.label
|
|
757
824
|
))
|
|
758
|
-
), fieldState.error?.message ? /* @__PURE__ */
|
|
825
|
+
), fieldState.error?.message ? /* @__PURE__ */ React12.createElement("p", { className: "text-tiny text-danger mt-1" }, fieldState.error.message) : null),
|
|
759
826
|
rules
|
|
760
827
|
}
|
|
761
828
|
);
|
|
762
829
|
}
|
|
763
830
|
|
|
764
831
|
// src/fields/SelectField.tsx
|
|
765
|
-
import
|
|
766
|
-
import { Controller as
|
|
832
|
+
import React13 from "react";
|
|
833
|
+
import { Controller as Controller8 } from "react-hook-form";
|
|
767
834
|
function SelectField(props) {
|
|
768
835
|
const {
|
|
769
836
|
className,
|
|
@@ -778,14 +845,14 @@ function SelectField(props) {
|
|
|
778
845
|
selectProps
|
|
779
846
|
} = props;
|
|
780
847
|
const defaults = useHeroHookFormDefaults();
|
|
781
|
-
return /* @__PURE__ */
|
|
782
|
-
|
|
848
|
+
return /* @__PURE__ */ React13.createElement(
|
|
849
|
+
Controller8,
|
|
783
850
|
{
|
|
784
851
|
control,
|
|
785
852
|
name,
|
|
786
853
|
render: ({ field: field2, fieldState }) => {
|
|
787
854
|
const selectedKey = field2.value;
|
|
788
|
-
return /* @__PURE__ */
|
|
855
|
+
return /* @__PURE__ */ React13.createElement("div", { className }, /* @__PURE__ */ React13.createElement(
|
|
789
856
|
Select,
|
|
790
857
|
{
|
|
791
858
|
...defaults.select,
|
|
@@ -803,7 +870,7 @@ function SelectField(props) {
|
|
|
803
870
|
field2.onChange(next);
|
|
804
871
|
}
|
|
805
872
|
},
|
|
806
|
-
options.map((opt) => /* @__PURE__ */
|
|
873
|
+
options.map((opt) => /* @__PURE__ */ React13.createElement(
|
|
807
874
|
SelectItem,
|
|
808
875
|
{
|
|
809
876
|
key: String(opt.value),
|
|
@@ -820,12 +887,12 @@ function SelectField(props) {
|
|
|
820
887
|
}
|
|
821
888
|
|
|
822
889
|
// src/fields/SliderField.tsx
|
|
823
|
-
import
|
|
824
|
-
import { Controller as
|
|
890
|
+
import React14 from "react";
|
|
891
|
+
import { Controller as Controller9 } from "react-hook-form";
|
|
825
892
|
function CoercedSlider(props) {
|
|
826
893
|
const { description, disabled, errorMessage, field: field2, label, sliderProps } = props;
|
|
827
894
|
const defaults = useHeroHookFormDefaults();
|
|
828
|
-
return /* @__PURE__ */
|
|
895
|
+
return /* @__PURE__ */ React14.createElement(
|
|
829
896
|
Slider,
|
|
830
897
|
{
|
|
831
898
|
...defaults.slider,
|
|
@@ -853,12 +920,12 @@ function SliderField(props) {
|
|
|
853
920
|
sliderProps,
|
|
854
921
|
transform
|
|
855
922
|
} = props;
|
|
856
|
-
return /* @__PURE__ */
|
|
857
|
-
|
|
923
|
+
return /* @__PURE__ */ React14.createElement(
|
|
924
|
+
Controller9,
|
|
858
925
|
{
|
|
859
926
|
control,
|
|
860
927
|
name,
|
|
861
|
-
render: ({ field: field2, fieldState }) => /* @__PURE__ */
|
|
928
|
+
render: ({ field: field2, fieldState }) => /* @__PURE__ */ React14.createElement("div", { className }, /* @__PURE__ */ React14.createElement(
|
|
862
929
|
CoercedSlider,
|
|
863
930
|
{
|
|
864
931
|
description,
|
|
@@ -878,8 +945,8 @@ function SliderField(props) {
|
|
|
878
945
|
}
|
|
879
946
|
|
|
880
947
|
// src/fields/SwitchField.tsx
|
|
881
|
-
import
|
|
882
|
-
import { Controller as
|
|
948
|
+
import React15 from "react";
|
|
949
|
+
import { Controller as Controller10 } from "react-hook-form";
|
|
883
950
|
function SwitchField(props) {
|
|
884
951
|
const {
|
|
885
952
|
className,
|
|
@@ -892,12 +959,12 @@ function SwitchField(props) {
|
|
|
892
959
|
switchProps
|
|
893
960
|
} = props;
|
|
894
961
|
const defaults = useHeroHookFormDefaults();
|
|
895
|
-
return /* @__PURE__ */
|
|
896
|
-
|
|
962
|
+
return /* @__PURE__ */ React15.createElement(
|
|
963
|
+
Controller10,
|
|
897
964
|
{
|
|
898
965
|
control,
|
|
899
966
|
name,
|
|
900
|
-
render: ({ field: field2, fieldState }) => /* @__PURE__ */
|
|
967
|
+
render: ({ field: field2, fieldState }) => /* @__PURE__ */ React15.createElement("div", { className }, /* @__PURE__ */ React15.createElement(
|
|
901
968
|
Switch,
|
|
902
969
|
{
|
|
903
970
|
...defaults.switch,
|
|
@@ -908,15 +975,15 @@ function SwitchField(props) {
|
|
|
908
975
|
onValueChange: (val) => field2.onChange(val)
|
|
909
976
|
},
|
|
910
977
|
label
|
|
911
|
-
), description ? /* @__PURE__ */
|
|
978
|
+
), description ? /* @__PURE__ */ React15.createElement("p", { className: "text-small text-default-400" }, description) : null, fieldState.error?.message ? /* @__PURE__ */ React15.createElement("p", { className: "text-tiny text-danger mt-1" }, fieldState.error.message) : null),
|
|
912
979
|
rules
|
|
913
980
|
}
|
|
914
981
|
);
|
|
915
982
|
}
|
|
916
983
|
|
|
917
984
|
// src/fields/TextareaField.tsx
|
|
918
|
-
import
|
|
919
|
-
import { Controller as
|
|
985
|
+
import React16 from "react";
|
|
986
|
+
import { Controller as Controller11 } from "react-hook-form";
|
|
920
987
|
function TextareaField(props) {
|
|
921
988
|
const {
|
|
922
989
|
className,
|
|
@@ -929,12 +996,12 @@ function TextareaField(props) {
|
|
|
929
996
|
textareaProps
|
|
930
997
|
} = props;
|
|
931
998
|
const defaults = useHeroHookFormDefaults();
|
|
932
|
-
return /* @__PURE__ */
|
|
933
|
-
|
|
999
|
+
return /* @__PURE__ */ React16.createElement(
|
|
1000
|
+
Controller11,
|
|
934
1001
|
{
|
|
935
1002
|
control,
|
|
936
1003
|
name,
|
|
937
|
-
render: ({ field: field2, fieldState }) => /* @__PURE__ */
|
|
1004
|
+
render: ({ field: field2, fieldState }) => /* @__PURE__ */ React16.createElement("div", { className }, /* @__PURE__ */ React16.createElement(
|
|
938
1005
|
Textarea,
|
|
939
1006
|
{
|
|
940
1007
|
...defaults.textarea,
|
|
@@ -955,7 +1022,7 @@ function TextareaField(props) {
|
|
|
955
1022
|
}
|
|
956
1023
|
|
|
957
1024
|
// src/components/FormField.tsx
|
|
958
|
-
var FormField =
|
|
1025
|
+
var FormField = React17.memo(
|
|
959
1026
|
({
|
|
960
1027
|
config,
|
|
961
1028
|
form,
|
|
@@ -967,7 +1034,7 @@ var FormField = React16.memo(
|
|
|
967
1034
|
const { control } = form;
|
|
968
1035
|
const watchedValues = useWatch3({ control });
|
|
969
1036
|
if (config.type === "content") {
|
|
970
|
-
return /* @__PURE__ */
|
|
1037
|
+
return /* @__PURE__ */ React17.createElement(
|
|
971
1038
|
ContentField,
|
|
972
1039
|
{
|
|
973
1040
|
config,
|
|
@@ -997,7 +1064,7 @@ var FormField = React16.memo(
|
|
|
997
1064
|
};
|
|
998
1065
|
switch (config.type) {
|
|
999
1066
|
case "input":
|
|
1000
|
-
return /* @__PURE__ */
|
|
1067
|
+
return /* @__PURE__ */ React17.createElement(
|
|
1001
1068
|
InputField,
|
|
1002
1069
|
{
|
|
1003
1070
|
...baseProps,
|
|
@@ -1007,7 +1074,7 @@ var FormField = React16.memo(
|
|
|
1007
1074
|
}
|
|
1008
1075
|
);
|
|
1009
1076
|
case "textarea":
|
|
1010
|
-
return /* @__PURE__ */
|
|
1077
|
+
return /* @__PURE__ */ React17.createElement(
|
|
1011
1078
|
TextareaField,
|
|
1012
1079
|
{
|
|
1013
1080
|
...baseProps,
|
|
@@ -1017,7 +1084,7 @@ var FormField = React16.memo(
|
|
|
1017
1084
|
}
|
|
1018
1085
|
);
|
|
1019
1086
|
case "select":
|
|
1020
|
-
return /* @__PURE__ */
|
|
1087
|
+
return /* @__PURE__ */ React17.createElement(
|
|
1021
1088
|
SelectField,
|
|
1022
1089
|
{
|
|
1023
1090
|
...baseProps,
|
|
@@ -1030,8 +1097,22 @@ var FormField = React16.memo(
|
|
|
1030
1097
|
selectProps: config.selectProps
|
|
1031
1098
|
}
|
|
1032
1099
|
);
|
|
1100
|
+
case "autocomplete":
|
|
1101
|
+
return /* @__PURE__ */ React17.createElement(
|
|
1102
|
+
AutocompleteField,
|
|
1103
|
+
{
|
|
1104
|
+
...baseProps,
|
|
1105
|
+
control,
|
|
1106
|
+
defaultValue: config.defaultValue,
|
|
1107
|
+
items: (config.options ?? []).map((opt) => ({
|
|
1108
|
+
label: opt.label,
|
|
1109
|
+
value: String(opt.value)
|
|
1110
|
+
})),
|
|
1111
|
+
autocompleteProps: config.autocompleteProps
|
|
1112
|
+
}
|
|
1113
|
+
);
|
|
1033
1114
|
case "checkbox":
|
|
1034
|
-
return /* @__PURE__ */
|
|
1115
|
+
return /* @__PURE__ */ React17.createElement(
|
|
1035
1116
|
CheckboxField,
|
|
1036
1117
|
{
|
|
1037
1118
|
...baseProps,
|
|
@@ -1041,7 +1122,7 @@ var FormField = React16.memo(
|
|
|
1041
1122
|
}
|
|
1042
1123
|
);
|
|
1043
1124
|
case "radio":
|
|
1044
|
-
return /* @__PURE__ */
|
|
1125
|
+
return /* @__PURE__ */ React17.createElement(
|
|
1045
1126
|
RadioGroupField,
|
|
1046
1127
|
{
|
|
1047
1128
|
...baseProps,
|
|
@@ -1055,7 +1136,7 @@ var FormField = React16.memo(
|
|
|
1055
1136
|
}
|
|
1056
1137
|
);
|
|
1057
1138
|
case "switch":
|
|
1058
|
-
return /* @__PURE__ */
|
|
1139
|
+
return /* @__PURE__ */ React17.createElement(
|
|
1059
1140
|
SwitchField,
|
|
1060
1141
|
{
|
|
1061
1142
|
...baseProps,
|
|
@@ -1065,7 +1146,7 @@ var FormField = React16.memo(
|
|
|
1065
1146
|
}
|
|
1066
1147
|
);
|
|
1067
1148
|
case "slider":
|
|
1068
|
-
return /* @__PURE__ */
|
|
1149
|
+
return /* @__PURE__ */ React17.createElement(
|
|
1069
1150
|
SliderField,
|
|
1070
1151
|
{
|
|
1071
1152
|
...baseProps,
|
|
@@ -1075,7 +1156,7 @@ var FormField = React16.memo(
|
|
|
1075
1156
|
}
|
|
1076
1157
|
);
|
|
1077
1158
|
case "date":
|
|
1078
|
-
return /* @__PURE__ */
|
|
1159
|
+
return /* @__PURE__ */ React17.createElement(
|
|
1079
1160
|
DateField,
|
|
1080
1161
|
{
|
|
1081
1162
|
...baseProps,
|
|
@@ -1085,7 +1166,7 @@ var FormField = React16.memo(
|
|
|
1085
1166
|
}
|
|
1086
1167
|
);
|
|
1087
1168
|
case "file":
|
|
1088
|
-
return /* @__PURE__ */
|
|
1169
|
+
return /* @__PURE__ */ React17.createElement(
|
|
1089
1170
|
FileField,
|
|
1090
1171
|
{
|
|
1091
1172
|
...baseProps,
|
|
@@ -1097,7 +1178,7 @@ var FormField = React16.memo(
|
|
|
1097
1178
|
}
|
|
1098
1179
|
);
|
|
1099
1180
|
case "fontPicker":
|
|
1100
|
-
return /* @__PURE__ */
|
|
1181
|
+
return /* @__PURE__ */ React17.createElement(
|
|
1101
1182
|
FontPickerField,
|
|
1102
1183
|
{
|
|
1103
1184
|
...baseProps,
|
|
@@ -1115,7 +1196,7 @@ var FormField = React16.memo(
|
|
|
1115
1196
|
name: config.name
|
|
1116
1197
|
});
|
|
1117
1198
|
case "conditional":
|
|
1118
|
-
return /* @__PURE__ */
|
|
1199
|
+
return /* @__PURE__ */ React17.createElement(
|
|
1119
1200
|
ConditionalField,
|
|
1120
1201
|
{
|
|
1121
1202
|
config,
|
|
@@ -1124,7 +1205,7 @@ var FormField = React16.memo(
|
|
|
1124
1205
|
}
|
|
1125
1206
|
);
|
|
1126
1207
|
case "fieldArray":
|
|
1127
|
-
return /* @__PURE__ */
|
|
1208
|
+
return /* @__PURE__ */ React17.createElement(
|
|
1128
1209
|
FieldArrayField,
|
|
1129
1210
|
{
|
|
1130
1211
|
config,
|
|
@@ -1132,7 +1213,7 @@ var FormField = React16.memo(
|
|
|
1132
1213
|
}
|
|
1133
1214
|
);
|
|
1134
1215
|
case "dynamicSection":
|
|
1135
|
-
return /* @__PURE__ */
|
|
1216
|
+
return /* @__PURE__ */ React17.createElement(
|
|
1136
1217
|
DynamicSectionField,
|
|
1137
1218
|
{
|
|
1138
1219
|
config,
|
|
@@ -1184,12 +1265,12 @@ function ConfigurableForm({
|
|
|
1184
1265
|
});
|
|
1185
1266
|
const renderFields = () => {
|
|
1186
1267
|
if (layout === "grid") {
|
|
1187
|
-
return /* @__PURE__ */
|
|
1268
|
+
return /* @__PURE__ */ React18.createElement(
|
|
1188
1269
|
"div",
|
|
1189
1270
|
{
|
|
1190
1271
|
className: `grid gap-${spacing} ${columns === 1 ? "grid-cols-1" : columns === 2 ? "grid-cols-1 md:grid-cols-2" : "grid-cols-1 md:grid-cols-2 lg:grid-cols-3"}`
|
|
1191
1272
|
},
|
|
1192
|
-
fields.map((field2) => /* @__PURE__ */
|
|
1273
|
+
fields.map((field2) => /* @__PURE__ */ React18.createElement(
|
|
1193
1274
|
FormField,
|
|
1194
1275
|
{
|
|
1195
1276
|
key: field2.name,
|
|
@@ -1201,7 +1282,7 @@ function ConfigurableForm({
|
|
|
1201
1282
|
);
|
|
1202
1283
|
}
|
|
1203
1284
|
if (layout === "horizontal") {
|
|
1204
|
-
return /* @__PURE__ */
|
|
1285
|
+
return /* @__PURE__ */ React18.createElement("div", { className: `grid gap-${spacing} grid-cols-1 md:grid-cols-2` }, fields.map((field2) => /* @__PURE__ */ React18.createElement(
|
|
1205
1286
|
FormField,
|
|
1206
1287
|
{
|
|
1207
1288
|
key: field2.name,
|
|
@@ -1211,7 +1292,7 @@ function ConfigurableForm({
|
|
|
1211
1292
|
}
|
|
1212
1293
|
)));
|
|
1213
1294
|
}
|
|
1214
|
-
return /* @__PURE__ */
|
|
1295
|
+
return /* @__PURE__ */ React18.createElement("div", { className: `space-y-${spacing}` }, fields.map((field2) => /* @__PURE__ */ React18.createElement(
|
|
1215
1296
|
FormField,
|
|
1216
1297
|
{
|
|
1217
1298
|
key: field2.name,
|
|
@@ -1225,23 +1306,23 @@ function ConfigurableForm({
|
|
|
1225
1306
|
e.preventDefault();
|
|
1226
1307
|
void handleSubmit();
|
|
1227
1308
|
};
|
|
1228
|
-
return /* @__PURE__ */
|
|
1309
|
+
return /* @__PURE__ */ React18.createElement("form", { className, role: "form", onSubmit: handleFormSubmit }, title && /* @__PURE__ */ React18.createElement("div", { className: "mb-6" }, /* @__PURE__ */ React18.createElement("h2", { className: "text-xl font-semibold text-foreground mb-2" }, title), subtitle && /* @__PURE__ */ React18.createElement("p", { className: "text-sm text-muted-foreground" }, subtitle)), isSubmitted && isSuccess && /* @__PURE__ */ React18.createElement(
|
|
1229
1310
|
"div",
|
|
1230
1311
|
{
|
|
1231
1312
|
className: "mb-6 p-4 bg-success-50 border border-success-200 rounded-lg",
|
|
1232
1313
|
"data-testid": "success-message"
|
|
1233
1314
|
},
|
|
1234
|
-
/* @__PURE__ */
|
|
1235
|
-
/* @__PURE__ */
|
|
1236
|
-
), error && /* @__PURE__ */
|
|
1315
|
+
/* @__PURE__ */ React18.createElement("p", { className: "text-success-800 font-medium" }, "Success!"),
|
|
1316
|
+
/* @__PURE__ */ React18.createElement("p", { className: "text-success-700 text-sm mt-1" }, "Your request has been processed successfully.")
|
|
1317
|
+
), error && /* @__PURE__ */ React18.createElement(
|
|
1237
1318
|
"div",
|
|
1238
1319
|
{
|
|
1239
1320
|
className: "mb-6 p-4 bg-danger-50 border border-danger-200 rounded-lg",
|
|
1240
1321
|
"data-testid": "error-message"
|
|
1241
1322
|
},
|
|
1242
|
-
/* @__PURE__ */
|
|
1243
|
-
/* @__PURE__ */
|
|
1244
|
-
), renderFields(), /* @__PURE__ */
|
|
1323
|
+
/* @__PURE__ */ React18.createElement("p", { className: "text-danger-800 font-medium" }, "Error"),
|
|
1324
|
+
/* @__PURE__ */ React18.createElement("p", { className: "text-danger-700 text-sm mt-1" }, error)
|
|
1325
|
+
), renderFields(), /* @__PURE__ */ React18.createElement("div", { className: "mt-6 flex gap-3 justify-end" }, /* @__PURE__ */ React18.createElement(
|
|
1245
1326
|
Button3,
|
|
1246
1327
|
{
|
|
1247
1328
|
color: "primary",
|
|
@@ -1251,7 +1332,7 @@ function ConfigurableForm({
|
|
|
1251
1332
|
...submitButtonProps
|
|
1252
1333
|
},
|
|
1253
1334
|
submitButtonText
|
|
1254
|
-
), showResetButton && /* @__PURE__ */
|
|
1335
|
+
), showResetButton && /* @__PURE__ */ React18.createElement(
|
|
1255
1336
|
Button3,
|
|
1256
1337
|
{
|
|
1257
1338
|
isDisabled: isSubmitting,
|
|
@@ -1264,7 +1345,7 @@ function ConfigurableForm({
|
|
|
1264
1345
|
}
|
|
1265
1346
|
|
|
1266
1347
|
// src/components/ServerActionForm.tsx
|
|
1267
|
-
import
|
|
1348
|
+
import React19 from "react";
|
|
1268
1349
|
import { useActionState } from "react";
|
|
1269
1350
|
function ServerActionForm({
|
|
1270
1351
|
action,
|
|
@@ -1289,10 +1370,10 @@ function ServerActionForm({
|
|
|
1289
1370
|
action,
|
|
1290
1371
|
initialState ?? { errors: void 0, message: void 0, success: false }
|
|
1291
1372
|
);
|
|
1292
|
-
const formRef =
|
|
1293
|
-
const [clientErrors, setClientErrors] =
|
|
1294
|
-
const lastSubmittedFormData =
|
|
1295
|
-
|
|
1373
|
+
const formRef = React19.useRef(null);
|
|
1374
|
+
const [clientErrors, setClientErrors] = React19.useState({});
|
|
1375
|
+
const lastSubmittedFormData = React19.useRef(null);
|
|
1376
|
+
React19.useEffect(() => {
|
|
1296
1377
|
if (state && (state.errors || state.message && !state.success)) {
|
|
1297
1378
|
onError?.({
|
|
1298
1379
|
errors: state.errors,
|
|
@@ -1300,7 +1381,7 @@ function ServerActionForm({
|
|
|
1300
1381
|
});
|
|
1301
1382
|
}
|
|
1302
1383
|
}, [state, onError]);
|
|
1303
|
-
|
|
1384
|
+
React19.useEffect(() => {
|
|
1304
1385
|
if (state?.success && lastSubmittedFormData.current) {
|
|
1305
1386
|
onSuccess?.(lastSubmittedFormData.current);
|
|
1306
1387
|
}
|
|
@@ -1343,12 +1424,12 @@ function ServerActionForm({
|
|
|
1343
1424
|
};
|
|
1344
1425
|
const renderFields = () => {
|
|
1345
1426
|
if (layout === "grid") {
|
|
1346
|
-
return /* @__PURE__ */
|
|
1427
|
+
return /* @__PURE__ */ React19.createElement(
|
|
1347
1428
|
"div",
|
|
1348
1429
|
{
|
|
1349
1430
|
className: `grid gap-${spacing} ${columns === 1 ? "grid-cols-1" : columns === 2 ? "grid-cols-1 md:grid-cols-2" : "grid-cols-1 md:grid-cols-2 lg:grid-cols-3"}`
|
|
1350
1431
|
},
|
|
1351
|
-
fields.map((field2) => /* @__PURE__ */
|
|
1432
|
+
fields.map((field2) => /* @__PURE__ */ React19.createElement(
|
|
1352
1433
|
ServerActionField,
|
|
1353
1434
|
{
|
|
1354
1435
|
key: field2.name,
|
|
@@ -1361,7 +1442,7 @@ function ServerActionForm({
|
|
|
1361
1442
|
);
|
|
1362
1443
|
}
|
|
1363
1444
|
if (layout === "horizontal") {
|
|
1364
|
-
return /* @__PURE__ */
|
|
1445
|
+
return /* @__PURE__ */ React19.createElement("div", { className: `grid gap-${spacing} grid-cols-1 md:grid-cols-2` }, fields.map((field2) => /* @__PURE__ */ React19.createElement(
|
|
1365
1446
|
ServerActionField,
|
|
1366
1447
|
{
|
|
1367
1448
|
key: field2.name,
|
|
@@ -1372,7 +1453,7 @@ function ServerActionForm({
|
|
|
1372
1453
|
}
|
|
1373
1454
|
)));
|
|
1374
1455
|
}
|
|
1375
|
-
return /* @__PURE__ */
|
|
1456
|
+
return /* @__PURE__ */ React19.createElement("div", { className: `space-y-${spacing}` }, fields.map((field2) => /* @__PURE__ */ React19.createElement(
|
|
1376
1457
|
ServerActionField,
|
|
1377
1458
|
{
|
|
1378
1459
|
key: field2.name,
|
|
@@ -1383,7 +1464,7 @@ function ServerActionForm({
|
|
|
1383
1464
|
}
|
|
1384
1465
|
)));
|
|
1385
1466
|
};
|
|
1386
|
-
return /* @__PURE__ */
|
|
1467
|
+
return /* @__PURE__ */ React19.createElement(
|
|
1387
1468
|
"form",
|
|
1388
1469
|
{
|
|
1389
1470
|
ref: formRef,
|
|
@@ -1391,27 +1472,27 @@ function ServerActionForm({
|
|
|
1391
1472
|
role: "form",
|
|
1392
1473
|
onSubmit: handleSubmit
|
|
1393
1474
|
},
|
|
1394
|
-
title && /* @__PURE__ */
|
|
1395
|
-
state?.success && !pending && /* @__PURE__ */
|
|
1475
|
+
title && /* @__PURE__ */ React19.createElement("div", { className: "mb-6" }, /* @__PURE__ */ React19.createElement("h2", { className: "text-xl font-semibold text-foreground mb-2" }, title), subtitle && /* @__PURE__ */ React19.createElement("p", { className: "text-sm text-muted-foreground" }, subtitle)),
|
|
1476
|
+
state?.success && !pending && /* @__PURE__ */ React19.createElement(
|
|
1396
1477
|
"div",
|
|
1397
1478
|
{
|
|
1398
1479
|
className: "mb-6 p-4 bg-success-50 border border-success-200 rounded-lg",
|
|
1399
1480
|
"data-testid": "success-message"
|
|
1400
1481
|
},
|
|
1401
|
-
/* @__PURE__ */
|
|
1402
|
-
state.message && /* @__PURE__ */
|
|
1482
|
+
/* @__PURE__ */ React19.createElement("p", { className: "text-success-800 font-medium" }, "Success!"),
|
|
1483
|
+
state.message && /* @__PURE__ */ React19.createElement("p", { className: "text-success-700 text-sm mt-1" }, state.message)
|
|
1403
1484
|
),
|
|
1404
|
-
state?.message && !state.success && /* @__PURE__ */
|
|
1485
|
+
state?.message && !state.success && /* @__PURE__ */ React19.createElement(
|
|
1405
1486
|
"div",
|
|
1406
1487
|
{
|
|
1407
1488
|
className: "mb-6 p-4 bg-danger-50 border border-danger-200 rounded-lg",
|
|
1408
1489
|
"data-testid": "error-message"
|
|
1409
1490
|
},
|
|
1410
|
-
/* @__PURE__ */
|
|
1411
|
-
/* @__PURE__ */
|
|
1491
|
+
/* @__PURE__ */ React19.createElement("p", { className: "text-danger-800 font-medium" }, "Error"),
|
|
1492
|
+
/* @__PURE__ */ React19.createElement("p", { className: "text-danger-700 text-sm mt-1" }, state.message)
|
|
1412
1493
|
),
|
|
1413
1494
|
renderFields(),
|
|
1414
|
-
/* @__PURE__ */
|
|
1495
|
+
/* @__PURE__ */ React19.createElement("div", { className: "mt-6 flex gap-3 justify-end" }, /* @__PURE__ */ React19.createElement(
|
|
1415
1496
|
Button,
|
|
1416
1497
|
{
|
|
1417
1498
|
color: "primary",
|
|
@@ -1421,7 +1502,7 @@ function ServerActionForm({
|
|
|
1421
1502
|
...submitButtonProps
|
|
1422
1503
|
},
|
|
1423
1504
|
submitButtonText
|
|
1424
|
-
), showResetButton && /* @__PURE__ */
|
|
1505
|
+
), showResetButton && /* @__PURE__ */ React19.createElement(
|
|
1425
1506
|
Button,
|
|
1426
1507
|
{
|
|
1427
1508
|
isDisabled: pending,
|
|
@@ -1442,13 +1523,13 @@ function ServerActionField({
|
|
|
1442
1523
|
if (field2.type === "content") {
|
|
1443
1524
|
const contentField2 = field2;
|
|
1444
1525
|
if (contentField2.render) {
|
|
1445
|
-
return /* @__PURE__ */
|
|
1526
|
+
return /* @__PURE__ */ React19.createElement("div", { className: contentField2.className }, contentField2.render({
|
|
1446
1527
|
errors: {},
|
|
1447
1528
|
form: null,
|
|
1448
1529
|
isSubmitting: false
|
|
1449
1530
|
}));
|
|
1450
1531
|
}
|
|
1451
|
-
return /* @__PURE__ */
|
|
1532
|
+
return /* @__PURE__ */ React19.createElement("div", { className: contentField2.className }, contentField2.title && /* @__PURE__ */ React19.createElement("h3", { className: "text-lg font-semibold text-foreground mb-2" }, contentField2.title), contentField2.description && /* @__PURE__ */ React19.createElement("p", { className: "text-sm text-muted-foreground" }, contentField2.description));
|
|
1452
1533
|
}
|
|
1453
1534
|
const fieldName = field2.name;
|
|
1454
1535
|
const fieldErrors = errors?.[fieldName];
|
|
@@ -1476,9 +1557,9 @@ function ServerActionField({
|
|
|
1476
1557
|
}
|
|
1477
1558
|
return false;
|
|
1478
1559
|
};
|
|
1479
|
-
const [value, setValue] =
|
|
1480
|
-
const [checked, setChecked] =
|
|
1481
|
-
|
|
1560
|
+
const [value, setValue] = React19.useState(getDefaultValue);
|
|
1561
|
+
const [checked, setChecked] = React19.useState(getDefaultChecked);
|
|
1562
|
+
React19.useEffect(() => {
|
|
1482
1563
|
const newDefaultValue = defaultValues?.[fieldName];
|
|
1483
1564
|
if (newDefaultValue !== void 0 && newDefaultValue !== null) {
|
|
1484
1565
|
if (field2.type === "checkbox") {
|
|
@@ -1492,7 +1573,7 @@ function ServerActionField({
|
|
|
1492
1573
|
}
|
|
1493
1574
|
}
|
|
1494
1575
|
}, [defaultValues, fieldName, field2.type]);
|
|
1495
|
-
|
|
1576
|
+
React19.useEffect(() => {
|
|
1496
1577
|
const hiddenInput = document.querySelector(
|
|
1497
1578
|
`input[type="hidden"][name="${fieldName}"]`
|
|
1498
1579
|
);
|
|
@@ -1507,7 +1588,7 @@ function ServerActionField({
|
|
|
1507
1588
|
switch (field2.type) {
|
|
1508
1589
|
case "input": {
|
|
1509
1590
|
const inputType = field2.inputProps?.type || "text";
|
|
1510
|
-
return /* @__PURE__ */
|
|
1591
|
+
return /* @__PURE__ */ React19.createElement(React19.Fragment, null, /* @__PURE__ */ React19.createElement("input", { type: "hidden", name: fieldName, value }), /* @__PURE__ */ React19.createElement(
|
|
1511
1592
|
Input,
|
|
1512
1593
|
{
|
|
1513
1594
|
...field2.inputProps,
|
|
@@ -1524,7 +1605,7 @@ function ServerActionField({
|
|
|
1524
1605
|
));
|
|
1525
1606
|
}
|
|
1526
1607
|
case "textarea": {
|
|
1527
|
-
return /* @__PURE__ */
|
|
1608
|
+
return /* @__PURE__ */ React19.createElement(React19.Fragment, null, /* @__PURE__ */ React19.createElement("input", { type: "hidden", name: fieldName, value }), /* @__PURE__ */ React19.createElement(
|
|
1528
1609
|
Textarea,
|
|
1529
1610
|
{
|
|
1530
1611
|
...field2.textareaProps,
|
|
@@ -1540,7 +1621,7 @@ function ServerActionField({
|
|
|
1540
1621
|
));
|
|
1541
1622
|
}
|
|
1542
1623
|
case "checkbox": {
|
|
1543
|
-
return /* @__PURE__ */
|
|
1624
|
+
return /* @__PURE__ */ React19.createElement(React19.Fragment, null, /* @__PURE__ */ React19.createElement("input", { type: "hidden", name: fieldName, value: checked ? "on" : "" }), /* @__PURE__ */ React19.createElement(
|
|
1544
1625
|
Checkbox,
|
|
1545
1626
|
{
|
|
1546
1627
|
...field2.checkboxProps,
|
|
@@ -1556,7 +1637,7 @@ function ServerActionField({
|
|
|
1556
1637
|
}
|
|
1557
1638
|
case "select": {
|
|
1558
1639
|
const options = field2.options || [];
|
|
1559
|
-
return /* @__PURE__ */
|
|
1640
|
+
return /* @__PURE__ */ React19.createElement(React19.Fragment, null, /* @__PURE__ */ React19.createElement("input", { type: "hidden", name: fieldName, value }), /* @__PURE__ */ React19.createElement(
|
|
1560
1641
|
Select,
|
|
1561
1642
|
{
|
|
1562
1643
|
...field2.selectProps,
|
|
@@ -1573,12 +1654,12 @@ function ServerActionField({
|
|
|
1573
1654
|
}
|
|
1574
1655
|
},
|
|
1575
1656
|
options.map(
|
|
1576
|
-
(option) => /* @__PURE__ */
|
|
1657
|
+
(option) => /* @__PURE__ */ React19.createElement(SelectItem, { key: String(option.value) }, option.label)
|
|
1577
1658
|
)
|
|
1578
1659
|
));
|
|
1579
1660
|
}
|
|
1580
1661
|
default:
|
|
1581
|
-
return /* @__PURE__ */
|
|
1662
|
+
return /* @__PURE__ */ React19.createElement(React19.Fragment, null, /* @__PURE__ */ React19.createElement("input", { type: "hidden", name: fieldName, value }), /* @__PURE__ */ React19.createElement(
|
|
1582
1663
|
Input,
|
|
1583
1664
|
{
|
|
1584
1665
|
"data-field-name": fieldName,
|
|
@@ -1608,10 +1689,10 @@ function useHeroForm() {
|
|
|
1608
1689
|
}
|
|
1609
1690
|
|
|
1610
1691
|
// src/providers/FormProvider.tsx
|
|
1611
|
-
import
|
|
1692
|
+
import React20 from "react";
|
|
1612
1693
|
import { FormProvider as RHFProvider } from "react-hook-form";
|
|
1613
1694
|
function FormProvider(props) {
|
|
1614
|
-
return /* @__PURE__ */
|
|
1695
|
+
return /* @__PURE__ */ React20.createElement(RHFProvider, { ...props.methods }, /* @__PURE__ */ React20.createElement(
|
|
1615
1696
|
"form",
|
|
1616
1697
|
{
|
|
1617
1698
|
className: props.className,
|
|
@@ -1624,7 +1705,7 @@ function FormProvider(props) {
|
|
|
1624
1705
|
}
|
|
1625
1706
|
|
|
1626
1707
|
// src/submit/SubmitButton.tsx
|
|
1627
|
-
import
|
|
1708
|
+
import React21 from "react";
|
|
1628
1709
|
function SubmitButton(props) {
|
|
1629
1710
|
const ctx = useFormContext5();
|
|
1630
1711
|
const loading = props.isLoading ?? ctx.formState.isSubmitting;
|
|
@@ -1634,10 +1715,10 @@ function SubmitButton(props) {
|
|
|
1634
1715
|
const defaults = useHeroHookFormDefaults();
|
|
1635
1716
|
const getButtonContent = () => {
|
|
1636
1717
|
if (enhancedState?.isSuccess) {
|
|
1637
|
-
return /* @__PURE__ */
|
|
1718
|
+
return /* @__PURE__ */ React21.createElement("span", { className: "inline-flex items-center gap-2" }, "\u2705", props.successText || "Success!");
|
|
1638
1719
|
}
|
|
1639
1720
|
if (loading) {
|
|
1640
|
-
return /* @__PURE__ */
|
|
1721
|
+
return /* @__PURE__ */ React21.createElement("span", { className: "inline-flex items-center gap-2" }, "\u23F3", props.loadingText || "Submitting...");
|
|
1641
1722
|
}
|
|
1642
1723
|
return props.children;
|
|
1643
1724
|
};
|
|
@@ -1650,7 +1731,7 @@ function SubmitButton(props) {
|
|
|
1650
1731
|
}
|
|
1651
1732
|
return props.buttonProps?.color || defaults.submitButton.color;
|
|
1652
1733
|
};
|
|
1653
|
-
return /* @__PURE__ */
|
|
1734
|
+
return /* @__PURE__ */ React21.createElement(
|
|
1654
1735
|
Button,
|
|
1655
1736
|
{
|
|
1656
1737
|
type: "submit",
|
|
@@ -1891,7 +1972,7 @@ var commonValidations = {
|
|
|
1891
1972
|
import { useFormContext as useFormContext5 } from "react-hook-form";
|
|
1892
1973
|
|
|
1893
1974
|
// src/components/ZodForm.tsx
|
|
1894
|
-
import
|
|
1975
|
+
import React23 from "react";
|
|
1895
1976
|
import { Button as Button5 } from "@heroui/react";
|
|
1896
1977
|
import {
|
|
1897
1978
|
FormProvider as FormProvider2
|
|
@@ -2014,7 +2095,7 @@ function useEnhancedFormState(form, options = {}) {
|
|
|
2014
2095
|
}
|
|
2015
2096
|
|
|
2016
2097
|
// src/components/FormStatus.tsx
|
|
2017
|
-
import
|
|
2098
|
+
import React22 from "react";
|
|
2018
2099
|
import { Button as Button4 } from "@heroui/react";
|
|
2019
2100
|
function FormStatus({
|
|
2020
2101
|
className = "",
|
|
@@ -2027,25 +2108,25 @@ function FormStatus({
|
|
|
2027
2108
|
return null;
|
|
2028
2109
|
}
|
|
2029
2110
|
if (isSubmitting) {
|
|
2030
|
-
return /* @__PURE__ */
|
|
2111
|
+
return /* @__PURE__ */ React22.createElement(
|
|
2031
2112
|
"div",
|
|
2032
2113
|
{
|
|
2033
2114
|
className: `flex items-center gap-3 p-4 bg-blue-50 border border-blue-200 rounded-lg ${className}`
|
|
2034
2115
|
},
|
|
2035
|
-
/* @__PURE__ */
|
|
2036
|
-
/* @__PURE__ */
|
|
2116
|
+
/* @__PURE__ */ React22.createElement("span", { className: "text-blue-600" }, "\u23F3"),
|
|
2117
|
+
/* @__PURE__ */ React22.createElement("div", null, /* @__PURE__ */ React22.createElement("p", { className: "text-sm font-medium text-blue-900" }, "Submitting form..."), showDetails && /* @__PURE__ */ React22.createElement("p", { className: "text-xs text-blue-700" }, "Please wait while we process your request."))
|
|
2037
2118
|
);
|
|
2038
2119
|
}
|
|
2039
2120
|
if (isSuccess) {
|
|
2040
|
-
return /* @__PURE__ */
|
|
2121
|
+
return /* @__PURE__ */ React22.createElement(
|
|
2041
2122
|
"div",
|
|
2042
2123
|
{
|
|
2043
2124
|
className: `flex items-center gap-3 p-4 bg-green-50 border border-green-200 rounded-lg ${className}`,
|
|
2044
2125
|
"data-testid": "success-message"
|
|
2045
2126
|
},
|
|
2046
|
-
/* @__PURE__ */
|
|
2047
|
-
/* @__PURE__ */
|
|
2048
|
-
onDismiss && /* @__PURE__ */
|
|
2127
|
+
/* @__PURE__ */ React22.createElement("span", { className: "text-green-600" }, "\u2705"),
|
|
2128
|
+
/* @__PURE__ */ React22.createElement("div", { className: "flex-1" }, /* @__PURE__ */ React22.createElement("p", { className: "text-sm font-medium text-green-900" }, "Form submitted successfully!"), showDetails && submittedData && /* @__PURE__ */ React22.createElement("p", { className: "text-xs text-green-700" }, "Your data has been saved. Thank you for your submission.")),
|
|
2129
|
+
onDismiss && /* @__PURE__ */ React22.createElement(
|
|
2049
2130
|
Button4,
|
|
2050
2131
|
{
|
|
2051
2132
|
size: "sm",
|
|
@@ -2059,15 +2140,15 @@ function FormStatus({
|
|
|
2059
2140
|
);
|
|
2060
2141
|
}
|
|
2061
2142
|
if (isError && error) {
|
|
2062
|
-
return /* @__PURE__ */
|
|
2143
|
+
return /* @__PURE__ */ React22.createElement(
|
|
2063
2144
|
"div",
|
|
2064
2145
|
{
|
|
2065
2146
|
className: `flex items-center gap-3 p-4 bg-red-50 border border-red-200 rounded-lg ${className}`,
|
|
2066
2147
|
"data-testid": "error-message"
|
|
2067
2148
|
},
|
|
2068
|
-
/* @__PURE__ */
|
|
2069
|
-
/* @__PURE__ */
|
|
2070
|
-
onDismiss && /* @__PURE__ */
|
|
2149
|
+
/* @__PURE__ */ React22.createElement("span", { className: "text-red-600" }, "\u26A0\uFE0F"),
|
|
2150
|
+
/* @__PURE__ */ React22.createElement("div", { className: "flex-1" }, /* @__PURE__ */ React22.createElement("p", { className: "text-sm font-medium text-red-900" }, "Error submitting form"), /* @__PURE__ */ React22.createElement("p", { className: "text-xs text-red-700" }, error)),
|
|
2151
|
+
onDismiss && /* @__PURE__ */ React22.createElement(
|
|
2071
2152
|
Button4,
|
|
2072
2153
|
{
|
|
2073
2154
|
size: "sm",
|
|
@@ -2088,8 +2169,8 @@ function FormToast({
|
|
|
2088
2169
|
position = "top-right",
|
|
2089
2170
|
state
|
|
2090
2171
|
}) {
|
|
2091
|
-
const [isVisible, setIsVisible] =
|
|
2092
|
-
|
|
2172
|
+
const [isVisible, setIsVisible] = React22.useState(false);
|
|
2173
|
+
React22.useEffect(() => {
|
|
2093
2174
|
if (state.isSuccess || state.isError) {
|
|
2094
2175
|
setIsVisible(true);
|
|
2095
2176
|
if (duration > 0) {
|
|
@@ -2110,7 +2191,7 @@ function FormToast({
|
|
|
2110
2191
|
"top-left": "top-4 left-4",
|
|
2111
2192
|
"top-right": "top-4 right-4"
|
|
2112
2193
|
};
|
|
2113
|
-
return /* @__PURE__ */
|
|
2194
|
+
return /* @__PURE__ */ React22.createElement("div", { className: `fixed z-50 ${positionClasses[position]}` }, /* @__PURE__ */ React22.createElement(FormStatus, { state, onDismiss }));
|
|
2114
2195
|
}
|
|
2115
2196
|
|
|
2116
2197
|
// src/components/ZodForm.tsx
|
|
@@ -2122,7 +2203,6 @@ function ZodForm({
|
|
|
2122
2203
|
onError,
|
|
2123
2204
|
onSubmit,
|
|
2124
2205
|
onSuccess,
|
|
2125
|
-
render,
|
|
2126
2206
|
resetButtonText = "Reset",
|
|
2127
2207
|
showResetButton = false,
|
|
2128
2208
|
spacing = "4",
|
|
@@ -2161,12 +2241,12 @@ function ZodForm({
|
|
|
2161
2241
|
};
|
|
2162
2242
|
const renderFields = () => {
|
|
2163
2243
|
if (layout === "grid") {
|
|
2164
|
-
return /* @__PURE__ */
|
|
2244
|
+
return /* @__PURE__ */ React23.createElement(
|
|
2165
2245
|
"div",
|
|
2166
2246
|
{
|
|
2167
2247
|
className: `grid gap-${spacing} ${columns === 1 ? "grid-cols-1" : columns === 2 ? "grid-cols-1 md:grid-cols-2" : "grid-cols-1 md:grid-cols-2 lg:grid-cols-3"}`
|
|
2168
2248
|
},
|
|
2169
|
-
config.fields.map((field2) => /* @__PURE__ */
|
|
2249
|
+
config.fields.map((field2) => /* @__PURE__ */ React23.createElement(
|
|
2170
2250
|
FormField,
|
|
2171
2251
|
{
|
|
2172
2252
|
key: field2.name,
|
|
@@ -2183,7 +2263,7 @@ function ZodForm({
|
|
|
2183
2263
|
);
|
|
2184
2264
|
}
|
|
2185
2265
|
if (layout === "horizontal") {
|
|
2186
|
-
return /* @__PURE__ */
|
|
2266
|
+
return /* @__PURE__ */ React23.createElement("div", { className: `grid gap-${spacing} grid-cols-1 md:grid-cols-2` }, config.fields.map((field2) => /* @__PURE__ */ React23.createElement(
|
|
2187
2267
|
FormField,
|
|
2188
2268
|
{
|
|
2189
2269
|
key: field2.name,
|
|
@@ -2198,7 +2278,7 @@ function ZodForm({
|
|
|
2198
2278
|
}
|
|
2199
2279
|
)));
|
|
2200
2280
|
}
|
|
2201
|
-
return /* @__PURE__ */
|
|
2281
|
+
return /* @__PURE__ */ React23.createElement("div", { className: `space-y-${spacing}` }, config.fields.map((field2) => /* @__PURE__ */ React23.createElement(
|
|
2202
2282
|
FormField,
|
|
2203
2283
|
{
|
|
2204
2284
|
key: field2.name,
|
|
@@ -2217,29 +2297,19 @@ function ZodForm({
|
|
|
2217
2297
|
e.preventDefault();
|
|
2218
2298
|
void handleSubmit();
|
|
2219
2299
|
};
|
|
2220
|
-
|
|
2300
|
+
React23.useEffect(() => {
|
|
2221
2301
|
if (config.onError && Object.keys(form.formState.errors).length > 0) {
|
|
2222
2302
|
config.onError(form.formState.errors);
|
|
2223
2303
|
}
|
|
2224
2304
|
}, [form.formState.errors, config.onError]);
|
|
2225
|
-
|
|
2226
|
-
return /* @__PURE__ */ React22.createElement(FormProvider2, { ...form }, render({
|
|
2227
|
-
errors: form.formState.errors,
|
|
2228
|
-
form,
|
|
2229
|
-
isSubmitted: enhancedState.status !== "idle",
|
|
2230
|
-
isSubmitting: enhancedState.isSubmitting,
|
|
2231
|
-
isSuccess: enhancedState.isSuccess,
|
|
2232
|
-
values: form.getValues()
|
|
2233
|
-
}));
|
|
2234
|
-
}
|
|
2235
|
-
return /* @__PURE__ */ React22.createElement(FormProvider2, { ...form }, /* @__PURE__ */ React22.createElement("form", { className, role: "form", onSubmit: handleFormSubmit }, title && /* @__PURE__ */ React22.createElement("div", { className: "mb-6" }, /* @__PURE__ */ React22.createElement("h2", { className: "text-xl font-semibold text-foreground mb-2" }, title), subtitle && /* @__PURE__ */ React22.createElement("p", { className: "text-sm text-muted-foreground" }, subtitle)), /* @__PURE__ */ React22.createElement(
|
|
2305
|
+
return /* @__PURE__ */ React23.createElement(FormProvider2, { ...form }, /* @__PURE__ */ React23.createElement("form", { className, role: "form", onSubmit: handleFormSubmit }, title && /* @__PURE__ */ React23.createElement("div", { className: "mb-6" }, /* @__PURE__ */ React23.createElement("h2", { className: "text-xl font-semibold text-foreground mb-2" }, title), subtitle && /* @__PURE__ */ React23.createElement("p", { className: "text-sm text-muted-foreground" }, subtitle)), /* @__PURE__ */ React23.createElement(
|
|
2236
2306
|
FormStatus,
|
|
2237
2307
|
{
|
|
2238
2308
|
state: enhancedState,
|
|
2239
2309
|
onDismiss: () => enhancedState.reset(),
|
|
2240
2310
|
showDetails: true
|
|
2241
2311
|
}
|
|
2242
|
-
), renderFields(), /* @__PURE__ */
|
|
2312
|
+
), renderFields(), /* @__PURE__ */ React23.createElement("div", { className: "mt-6 flex gap-3 justify-end" }, /* @__PURE__ */ React23.createElement(
|
|
2243
2313
|
Button5,
|
|
2244
2314
|
{
|
|
2245
2315
|
color: "primary",
|
|
@@ -2249,7 +2319,7 @@ function ZodForm({
|
|
|
2249
2319
|
...submitButtonProps
|
|
2250
2320
|
},
|
|
2251
2321
|
enhancedState.isSuccess ? "Success!" : submitButtonText
|
|
2252
|
-
), showResetButton && /* @__PURE__ */
|
|
2322
|
+
), showResetButton && /* @__PURE__ */ React23.createElement(
|
|
2253
2323
|
Button5,
|
|
2254
2324
|
{
|
|
2255
2325
|
isDisabled: enhancedState.isSubmitting,
|
|
@@ -2330,8 +2400,9 @@ var BasicFormBuilder = class {
|
|
|
2330
2400
|
/**
|
|
2331
2401
|
* Add a switch field
|
|
2332
2402
|
*/
|
|
2333
|
-
switch(name, label) {
|
|
2403
|
+
switch(name, label, description) {
|
|
2334
2404
|
this.fields.push({
|
|
2405
|
+
description,
|
|
2335
2406
|
label,
|
|
2336
2407
|
name,
|
|
2337
2408
|
type: "switch"
|
|
@@ -2349,6 +2420,16 @@ function createBasicFormBuilder() {
|
|
|
2349
2420
|
return new BasicFormBuilder();
|
|
2350
2421
|
}
|
|
2351
2422
|
var FormFieldHelpers = {
|
|
2423
|
+
/**
|
|
2424
|
+
* Create an autocomplete field
|
|
2425
|
+
*/
|
|
2426
|
+
autocomplete: (name, label, items, placeholder) => ({
|
|
2427
|
+
autocompleteProps: placeholder ? { placeholder } : void 0,
|
|
2428
|
+
label,
|
|
2429
|
+
name,
|
|
2430
|
+
options: items,
|
|
2431
|
+
type: "autocomplete"
|
|
2432
|
+
}),
|
|
2352
2433
|
/**
|
|
2353
2434
|
* Create a checkbox field
|
|
2354
2435
|
*/
|
|
@@ -2357,6 +2438,24 @@ var FormFieldHelpers = {
|
|
|
2357
2438
|
name,
|
|
2358
2439
|
type: "checkbox"
|
|
2359
2440
|
}),
|
|
2441
|
+
/**
|
|
2442
|
+
* Create a conditional field that shows/hides based on form data
|
|
2443
|
+
*
|
|
2444
|
+
* @example
|
|
2445
|
+
* ```tsx
|
|
2446
|
+
* FormFieldHelpers.conditional(
|
|
2447
|
+
* "phone",
|
|
2448
|
+
* (values) => values.hasPhone === true,
|
|
2449
|
+
* FormFieldHelpers.input("phone", "Phone Number", "tel")
|
|
2450
|
+
* )
|
|
2451
|
+
* ```
|
|
2452
|
+
*/
|
|
2453
|
+
conditional: (name, condition, field2) => ({
|
|
2454
|
+
condition,
|
|
2455
|
+
field: field2,
|
|
2456
|
+
name,
|
|
2457
|
+
type: "conditional"
|
|
2458
|
+
}),
|
|
2360
2459
|
/**
|
|
2361
2460
|
* Create a content field for headers, questions, or custom content between fields
|
|
2362
2461
|
*
|
|
@@ -2371,14 +2470,16 @@ var FormFieldHelpers = {
|
|
|
2371
2470
|
* })
|
|
2372
2471
|
* ```
|
|
2373
2472
|
*/
|
|
2374
|
-
content: (title, description, options) =>
|
|
2375
|
-
|
|
2376
|
-
|
|
2377
|
-
|
|
2378
|
-
|
|
2379
|
-
|
|
2380
|
-
|
|
2381
|
-
|
|
2473
|
+
content: (title, description, options) => {
|
|
2474
|
+
return {
|
|
2475
|
+
className: options?.className,
|
|
2476
|
+
description: description || void 0,
|
|
2477
|
+
name: options?.name,
|
|
2478
|
+
render: options?.render,
|
|
2479
|
+
title: title || void 0,
|
|
2480
|
+
type: "content"
|
|
2481
|
+
};
|
|
2482
|
+
},
|
|
2382
2483
|
/**
|
|
2383
2484
|
* Create a date field
|
|
2384
2485
|
*/
|
|
@@ -2409,7 +2510,8 @@ var FormFieldHelpers = {
|
|
|
2409
2510
|
/**
|
|
2410
2511
|
* Create a switch field
|
|
2411
2512
|
*/
|
|
2412
|
-
switch: (name, label) => ({
|
|
2513
|
+
switch: (name, label, description) => ({
|
|
2514
|
+
description,
|
|
2413
2515
|
label,
|
|
2414
2516
|
name,
|
|
2415
2517
|
type: "switch"
|
|
@@ -2527,13 +2629,14 @@ function checkboxField(name, label, props) {
|
|
|
2527
2629
|
}
|
|
2528
2630
|
function switchField(name, label, props) {
|
|
2529
2631
|
return {
|
|
2632
|
+
description: props?.description,
|
|
2633
|
+
isDisabled: props?.isDisabled,
|
|
2530
2634
|
label,
|
|
2531
2635
|
name,
|
|
2532
2636
|
type: "switch",
|
|
2533
|
-
...props && {
|
|
2637
|
+
...props?.className && {
|
|
2534
2638
|
switchProps: {
|
|
2535
|
-
className: props.className
|
|
2536
|
-
disabled: props.isDisabled
|
|
2639
|
+
className: props.className
|
|
2537
2640
|
}
|
|
2538
2641
|
}
|
|
2539
2642
|
};
|
|
@@ -3544,6 +3647,7 @@ var validationUtils = {
|
|
|
3544
3647
|
};
|
|
3545
3648
|
export {
|
|
3546
3649
|
AdvancedFieldBuilder,
|
|
3650
|
+
AutocompleteField,
|
|
3547
3651
|
BasicFormBuilder,
|
|
3548
3652
|
CheckboxField,
|
|
3549
3653
|
CommonFields,
|