@rachelallyson/hero-hook-form 2.3.0 → 2.5.1
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 +59 -0
- package/dist/index.d.ts +171 -5
- package/dist/index.js +329 -187
- package/dist/react/index.d.ts +171 -6
- package/dist/react/index.js +335 -192
- 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,101 @@ 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
|
+
const hasSelectedValue = selectedKey != null && selectedKey !== "";
|
|
121
|
+
const allowsCustomValue = autocompleteProps?.allowsCustomValue ?? false;
|
|
122
|
+
const shouldShowInputValue = allowsCustomValue || !hasSelectedValue;
|
|
123
|
+
return /* @__PURE__ */ React.createElement("div", { className }, /* @__PURE__ */ React.createElement(
|
|
124
|
+
Autocomplete,
|
|
125
|
+
{
|
|
126
|
+
...autocompleteProps,
|
|
127
|
+
description,
|
|
128
|
+
errorMessage: fieldState.error?.message,
|
|
129
|
+
isDisabled,
|
|
130
|
+
isInvalid: Boolean(fieldState.error),
|
|
131
|
+
label,
|
|
132
|
+
placeholder,
|
|
133
|
+
selectedKey: allowsCustomValue ? void 0 : hasSelectedValue ? String(selectedKey) : void 0,
|
|
134
|
+
inputValue: shouldShowInputValue ? field2.value ?? "" : void 0,
|
|
135
|
+
onSelectionChange: (key) => {
|
|
136
|
+
const next = key ?? "";
|
|
137
|
+
field2.onChange(next);
|
|
138
|
+
},
|
|
139
|
+
onInputChange: (value) => {
|
|
140
|
+
if (allowsCustomValue) {
|
|
141
|
+
field2.onChange(value);
|
|
142
|
+
}
|
|
143
|
+
},
|
|
144
|
+
items
|
|
145
|
+
},
|
|
146
|
+
children ? children : (item) => /* @__PURE__ */ React.createElement(
|
|
147
|
+
AutocompleteItem,
|
|
148
|
+
{
|
|
149
|
+
key: String(item.value),
|
|
150
|
+
textValue: String(item.value),
|
|
151
|
+
description: item.description,
|
|
152
|
+
isDisabled: item.disabled
|
|
153
|
+
},
|
|
154
|
+
item.label
|
|
155
|
+
)
|
|
156
|
+
));
|
|
157
|
+
},
|
|
158
|
+
rules
|
|
159
|
+
}
|
|
160
|
+
);
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
// src/fields/CheckboxField.tsx
|
|
164
|
+
import React3 from "react";
|
|
165
|
+
import { Controller as Controller2 } from "react-hook-form";
|
|
166
|
+
|
|
85
167
|
// src/providers/ConfigProvider.tsx
|
|
86
|
-
import
|
|
168
|
+
import React2, { createContext, useContext, useMemo } from "react";
|
|
87
169
|
var DefaultsContext = createContext(null);
|
|
88
170
|
function HeroHookFormProvider(props) {
|
|
89
171
|
const value = useMemo(() => props.defaults ?? {}, [props.defaults]);
|
|
90
|
-
return /* @__PURE__ */
|
|
172
|
+
return /* @__PURE__ */ React2.createElement(DefaultsContext.Provider, { value }, props.children);
|
|
91
173
|
}
|
|
92
174
|
function useHeroHookFormDefaults() {
|
|
93
175
|
const cfg = useContext(DefaultsContext) ?? {};
|
|
@@ -168,18 +250,6 @@ function useHeroHookFormDefaults() {
|
|
|
168
250
|
};
|
|
169
251
|
}
|
|
170
252
|
|
|
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
253
|
// src/fields/CheckboxField.tsx
|
|
184
254
|
function CheckboxField(props) {
|
|
185
255
|
const {
|
|
@@ -193,12 +263,12 @@ function CheckboxField(props) {
|
|
|
193
263
|
rules
|
|
194
264
|
} = props;
|
|
195
265
|
const defaults = useHeroHookFormDefaults();
|
|
196
|
-
return /* @__PURE__ */
|
|
197
|
-
|
|
266
|
+
return /* @__PURE__ */ React3.createElement(
|
|
267
|
+
Controller2,
|
|
198
268
|
{
|
|
199
269
|
control,
|
|
200
270
|
name,
|
|
201
|
-
render: ({ field: field2, fieldState }) => /* @__PURE__ */
|
|
271
|
+
render: ({ field: field2, fieldState }) => /* @__PURE__ */ React3.createElement("div", { className }, /* @__PURE__ */ React3.createElement(
|
|
202
272
|
Checkbox,
|
|
203
273
|
{
|
|
204
274
|
...defaults.checkbox,
|
|
@@ -210,14 +280,14 @@ function CheckboxField(props) {
|
|
|
210
280
|
onValueChange: (val) => field2.onChange(val)
|
|
211
281
|
},
|
|
212
282
|
label
|
|
213
|
-
), description ? /* @__PURE__ */
|
|
283
|
+
), 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
284
|
rules
|
|
215
285
|
}
|
|
216
286
|
);
|
|
217
287
|
}
|
|
218
288
|
|
|
219
289
|
// src/fields/ConditionalField.tsx
|
|
220
|
-
import
|
|
290
|
+
import React4 from "react";
|
|
221
291
|
import { useWatch, useFormContext } from "react-hook-form";
|
|
222
292
|
function ConditionalField({
|
|
223
293
|
className,
|
|
@@ -231,7 +301,7 @@ function ConditionalField({
|
|
|
231
301
|
if (!shouldShow) {
|
|
232
302
|
return null;
|
|
233
303
|
}
|
|
234
|
-
return /* @__PURE__ */
|
|
304
|
+
return /* @__PURE__ */ React4.createElement("div", { className }, /* @__PURE__ */ React4.createElement(
|
|
235
305
|
FormField,
|
|
236
306
|
{
|
|
237
307
|
config: field2,
|
|
@@ -247,29 +317,29 @@ function ConditionalField({
|
|
|
247
317
|
}
|
|
248
318
|
|
|
249
319
|
// src/fields/ContentField.tsx
|
|
250
|
-
import
|
|
320
|
+
import React5 from "react";
|
|
251
321
|
function ContentField({
|
|
252
322
|
config,
|
|
253
323
|
form,
|
|
254
324
|
submissionState
|
|
255
325
|
}) {
|
|
256
326
|
if (config.render) {
|
|
257
|
-
return /* @__PURE__ */
|
|
327
|
+
return /* @__PURE__ */ React5.createElement("div", { className: config.className }, config.render({
|
|
258
328
|
errors: form.formState.errors,
|
|
259
329
|
form,
|
|
260
330
|
isSubmitting: submissionState.isSubmitting
|
|
261
331
|
}));
|
|
262
332
|
}
|
|
263
|
-
return /* @__PURE__ */
|
|
333
|
+
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
334
|
}
|
|
265
335
|
|
|
266
336
|
// src/fields/DateField.tsx
|
|
267
|
-
import
|
|
268
|
-
import { Controller as
|
|
337
|
+
import React6 from "react";
|
|
338
|
+
import { Controller as Controller3 } from "react-hook-form";
|
|
269
339
|
function CoercedDateInput(props) {
|
|
270
340
|
const { dateProps, description, disabled, errorMessage, field: field2, label } = props;
|
|
271
341
|
const defaults = useHeroHookFormDefaults();
|
|
272
|
-
return /* @__PURE__ */
|
|
342
|
+
return /* @__PURE__ */ React6.createElement(
|
|
273
343
|
DateInput,
|
|
274
344
|
{
|
|
275
345
|
...defaults.dateInput,
|
|
@@ -297,12 +367,12 @@ function DateField(props) {
|
|
|
297
367
|
rules,
|
|
298
368
|
transform
|
|
299
369
|
} = props;
|
|
300
|
-
return /* @__PURE__ */
|
|
301
|
-
|
|
370
|
+
return /* @__PURE__ */ React6.createElement(
|
|
371
|
+
Controller3,
|
|
302
372
|
{
|
|
303
373
|
control,
|
|
304
374
|
name,
|
|
305
|
-
render: ({ field: field2, fieldState }) => /* @__PURE__ */
|
|
375
|
+
render: ({ field: field2, fieldState }) => /* @__PURE__ */ React6.createElement("div", { className }, /* @__PURE__ */ React6.createElement(
|
|
306
376
|
CoercedDateInput,
|
|
307
377
|
{
|
|
308
378
|
dateProps,
|
|
@@ -322,7 +392,7 @@ function DateField(props) {
|
|
|
322
392
|
}
|
|
323
393
|
|
|
324
394
|
// src/fields/DynamicSectionField.tsx
|
|
325
|
-
import
|
|
395
|
+
import React7 from "react";
|
|
326
396
|
import { useWatch as useWatch2, useFormContext as useFormContext2 } from "react-hook-form";
|
|
327
397
|
function DynamicSectionField({
|
|
328
398
|
className,
|
|
@@ -336,7 +406,7 @@ function DynamicSectionField({
|
|
|
336
406
|
if (!shouldShow) {
|
|
337
407
|
return null;
|
|
338
408
|
}
|
|
339
|
-
return /* @__PURE__ */
|
|
409
|
+
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
410
|
FormField,
|
|
341
411
|
{
|
|
342
412
|
key: `${fieldConfig.name}-${index}`,
|
|
@@ -353,7 +423,7 @@ function DynamicSectionField({
|
|
|
353
423
|
}
|
|
354
424
|
|
|
355
425
|
// src/fields/FieldArrayField.tsx
|
|
356
|
-
import
|
|
426
|
+
import React8 from "react";
|
|
357
427
|
import { useFieldArray, useFormContext as useFormContext3 } from "react-hook-form";
|
|
358
428
|
import { Button as Button2 } from "@heroui/react";
|
|
359
429
|
function FieldArrayField({
|
|
@@ -401,13 +471,13 @@ function FieldArrayField({
|
|
|
401
471
|
remove(index);
|
|
402
472
|
}
|
|
403
473
|
};
|
|
404
|
-
return /* @__PURE__ */
|
|
474
|
+
return /* @__PURE__ */ React8.createElement("div", { className }, /* @__PURE__ */ React8.createElement("div", { className: "space-y-4" }, fields.map((field2, index) => /* @__PURE__ */ React8.createElement(
|
|
405
475
|
"div",
|
|
406
476
|
{
|
|
407
477
|
key: field2.id,
|
|
408
478
|
className: "border border-gray-200 rounded-lg p-4 space-y-4"
|
|
409
479
|
},
|
|
410
|
-
/* @__PURE__ */
|
|
480
|
+
/* @__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
481
|
Button2,
|
|
412
482
|
{
|
|
413
483
|
size: "sm",
|
|
@@ -419,7 +489,7 @@ function FieldArrayField({
|
|
|
419
489
|
},
|
|
420
490
|
removeButtonText
|
|
421
491
|
)),
|
|
422
|
-
/* @__PURE__ */
|
|
492
|
+
/* @__PURE__ */ React8.createElement("div", { className: "grid grid-cols-1 md:grid-cols-2 gap-4" }, fieldConfigs.map((fieldConfig) => /* @__PURE__ */ React8.createElement(
|
|
423
493
|
FormField,
|
|
424
494
|
{
|
|
425
495
|
key: `${fieldConfig.name}-${index}`,
|
|
@@ -436,7 +506,7 @@ function FieldArrayField({
|
|
|
436
506
|
}
|
|
437
507
|
}
|
|
438
508
|
)))
|
|
439
|
-
)), canAdd && /* @__PURE__ */
|
|
509
|
+
)), canAdd && /* @__PURE__ */ React8.createElement(
|
|
440
510
|
Button2,
|
|
441
511
|
{
|
|
442
512
|
variant: "bordered",
|
|
@@ -445,7 +515,7 @@ function FieldArrayField({
|
|
|
445
515
|
className: "w-full"
|
|
446
516
|
},
|
|
447
517
|
addButtonText
|
|
448
|
-
), fields.length === 0 && /* @__PURE__ */
|
|
518
|
+
), 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
519
|
Button2,
|
|
450
520
|
{
|
|
451
521
|
variant: "bordered",
|
|
@@ -458,8 +528,8 @@ function FieldArrayField({
|
|
|
458
528
|
}
|
|
459
529
|
|
|
460
530
|
// src/fields/FileField.tsx
|
|
461
|
-
import
|
|
462
|
-
import { Controller as
|
|
531
|
+
import React9 from "react";
|
|
532
|
+
import { Controller as Controller4 } from "react-hook-form";
|
|
463
533
|
function CoercedFileInput(props) {
|
|
464
534
|
const {
|
|
465
535
|
accept,
|
|
@@ -472,7 +542,7 @@ function CoercedFileInput(props) {
|
|
|
472
542
|
multiple
|
|
473
543
|
} = props;
|
|
474
544
|
const defaults = useHeroHookFormDefaults();
|
|
475
|
-
return /* @__PURE__ */
|
|
545
|
+
return /* @__PURE__ */ React9.createElement(
|
|
476
546
|
Input,
|
|
477
547
|
{
|
|
478
548
|
...defaults.input,
|
|
@@ -508,12 +578,12 @@ function FileField(props) {
|
|
|
508
578
|
rules,
|
|
509
579
|
transform
|
|
510
580
|
} = props;
|
|
511
|
-
return /* @__PURE__ */
|
|
512
|
-
|
|
581
|
+
return /* @__PURE__ */ React9.createElement(
|
|
582
|
+
Controller4,
|
|
513
583
|
{
|
|
514
584
|
control,
|
|
515
585
|
name,
|
|
516
|
-
render: ({ field: field2, fieldState }) => /* @__PURE__ */
|
|
586
|
+
render: ({ field: field2, fieldState }) => /* @__PURE__ */ React9.createElement("div", { className }, /* @__PURE__ */ React9.createElement(
|
|
517
587
|
CoercedFileInput,
|
|
518
588
|
{
|
|
519
589
|
accept,
|
|
@@ -535,8 +605,8 @@ function FileField(props) {
|
|
|
535
605
|
}
|
|
536
606
|
|
|
537
607
|
// src/fields/FontPickerField.tsx
|
|
538
|
-
import
|
|
539
|
-
import { Controller as
|
|
608
|
+
import React10 from "react";
|
|
609
|
+
import { Controller as Controller5 } from "react-hook-form";
|
|
540
610
|
var FontPickerComponent = null;
|
|
541
611
|
var fontPickerLoaded = false;
|
|
542
612
|
var fontPickerLoading = false;
|
|
@@ -552,12 +622,12 @@ function FontPickerField(props) {
|
|
|
552
622
|
name,
|
|
553
623
|
rules
|
|
554
624
|
} = props;
|
|
555
|
-
const [fontPickerState, setFontPickerState] =
|
|
625
|
+
const [fontPickerState, setFontPickerState] = React10.useState({
|
|
556
626
|
component: FontPickerComponent,
|
|
557
627
|
error: null,
|
|
558
628
|
loading: false
|
|
559
629
|
});
|
|
560
|
-
|
|
630
|
+
React10.useEffect(() => {
|
|
561
631
|
if (fontPickerLoaded && FontPickerComponent) {
|
|
562
632
|
setFontPickerState({
|
|
563
633
|
component: FontPickerComponent,
|
|
@@ -615,17 +685,17 @@ function FontPickerField(props) {
|
|
|
615
685
|
void loadFontPicker();
|
|
616
686
|
}, []);
|
|
617
687
|
if (fontPickerState.loading) {
|
|
618
|
-
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-default-200 bg-default-50 rounded-medium" }, /* @__PURE__ */ React10.createElement("p", { className: "text-default-600 text-sm" }, "Loading font picker..."))));
|
|
619
689
|
}
|
|
620
690
|
if (!fontPickerState.component) {
|
|
621
|
-
return /* @__PURE__ */
|
|
691
|
+
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
692
|
}
|
|
623
|
-
return /* @__PURE__ */
|
|
624
|
-
|
|
693
|
+
return /* @__PURE__ */ React10.createElement(
|
|
694
|
+
Controller5,
|
|
625
695
|
{
|
|
626
696
|
control,
|
|
627
697
|
name,
|
|
628
|
-
render: ({ field: field2, fieldState }) => /* @__PURE__ */
|
|
698
|
+
render: ({ field: field2, fieldState }) => /* @__PURE__ */ React10.createElement(
|
|
629
699
|
fontPickerState.component,
|
|
630
700
|
{
|
|
631
701
|
label,
|
|
@@ -644,12 +714,12 @@ function FontPickerField(props) {
|
|
|
644
714
|
}
|
|
645
715
|
|
|
646
716
|
// src/fields/InputField.tsx
|
|
647
|
-
import
|
|
648
|
-
import { Controller as
|
|
717
|
+
import React11 from "react";
|
|
718
|
+
import { Controller as Controller6 } from "react-hook-form";
|
|
649
719
|
function CoercedInput(props) {
|
|
650
720
|
const { description, disabled, errorMessage, field: field2, inputProps, label } = props;
|
|
651
721
|
const defaults = useHeroHookFormDefaults();
|
|
652
|
-
return /* @__PURE__ */
|
|
722
|
+
return /* @__PURE__ */ React11.createElement(
|
|
653
723
|
Input,
|
|
654
724
|
{
|
|
655
725
|
...defaults.input,
|
|
@@ -665,7 +735,7 @@ function CoercedInput(props) {
|
|
|
665
735
|
}
|
|
666
736
|
);
|
|
667
737
|
}
|
|
668
|
-
var InputField =
|
|
738
|
+
var InputField = React11.memo(
|
|
669
739
|
(props) => {
|
|
670
740
|
const {
|
|
671
741
|
className,
|
|
@@ -678,12 +748,12 @@ var InputField = React10.memo(
|
|
|
678
748
|
rules,
|
|
679
749
|
transform
|
|
680
750
|
} = props;
|
|
681
|
-
return /* @__PURE__ */
|
|
682
|
-
|
|
751
|
+
return /* @__PURE__ */ React11.createElement(
|
|
752
|
+
Controller6,
|
|
683
753
|
{
|
|
684
754
|
control,
|
|
685
755
|
name,
|
|
686
|
-
render: ({ field: field2, fieldState }) => /* @__PURE__ */
|
|
756
|
+
render: ({ field: field2, fieldState }) => /* @__PURE__ */ React11.createElement("div", { className }, /* @__PURE__ */ React11.createElement(
|
|
687
757
|
CoercedInput,
|
|
688
758
|
{
|
|
689
759
|
description,
|
|
@@ -713,8 +783,8 @@ var InputField = React10.memo(
|
|
|
713
783
|
);
|
|
714
784
|
|
|
715
785
|
// src/fields/RadioGroupField.tsx
|
|
716
|
-
import
|
|
717
|
-
import { Controller as
|
|
786
|
+
import React12 from "react";
|
|
787
|
+
import { Controller as Controller7 } from "react-hook-form";
|
|
718
788
|
function RadioGroupField(props) {
|
|
719
789
|
const {
|
|
720
790
|
className,
|
|
@@ -728,12 +798,12 @@ function RadioGroupField(props) {
|
|
|
728
798
|
rules
|
|
729
799
|
} = props;
|
|
730
800
|
const defaults = useHeroHookFormDefaults();
|
|
731
|
-
return /* @__PURE__ */
|
|
732
|
-
|
|
801
|
+
return /* @__PURE__ */ React12.createElement(
|
|
802
|
+
Controller7,
|
|
733
803
|
{
|
|
734
804
|
control,
|
|
735
805
|
name,
|
|
736
|
-
render: ({ field: field2, fieldState }) => /* @__PURE__ */
|
|
806
|
+
render: ({ field: field2, fieldState }) => /* @__PURE__ */ React12.createElement("div", { className }, /* @__PURE__ */ React12.createElement(
|
|
737
807
|
RadioGroup,
|
|
738
808
|
{
|
|
739
809
|
...defaults.radioGroup,
|
|
@@ -746,7 +816,7 @@ function RadioGroupField(props) {
|
|
|
746
816
|
onBlur: field2.onBlur,
|
|
747
817
|
onValueChange: (val) => field2.onChange(val)
|
|
748
818
|
},
|
|
749
|
-
options.map((opt) => /* @__PURE__ */
|
|
819
|
+
options.map((opt) => /* @__PURE__ */ React12.createElement(
|
|
750
820
|
Radio,
|
|
751
821
|
{
|
|
752
822
|
key: String(opt.value),
|
|
@@ -755,15 +825,15 @@ function RadioGroupField(props) {
|
|
|
755
825
|
},
|
|
756
826
|
opt.label
|
|
757
827
|
))
|
|
758
|
-
), fieldState.error?.message ? /* @__PURE__ */
|
|
828
|
+
), fieldState.error?.message ? /* @__PURE__ */ React12.createElement("p", { className: "text-tiny text-danger mt-1" }, fieldState.error.message) : null),
|
|
759
829
|
rules
|
|
760
830
|
}
|
|
761
831
|
);
|
|
762
832
|
}
|
|
763
833
|
|
|
764
834
|
// src/fields/SelectField.tsx
|
|
765
|
-
import
|
|
766
|
-
import { Controller as
|
|
835
|
+
import React13 from "react";
|
|
836
|
+
import { Controller as Controller8 } from "react-hook-form";
|
|
767
837
|
function SelectField(props) {
|
|
768
838
|
const {
|
|
769
839
|
className,
|
|
@@ -778,14 +848,14 @@ function SelectField(props) {
|
|
|
778
848
|
selectProps
|
|
779
849
|
} = props;
|
|
780
850
|
const defaults = useHeroHookFormDefaults();
|
|
781
|
-
return /* @__PURE__ */
|
|
782
|
-
|
|
851
|
+
return /* @__PURE__ */ React13.createElement(
|
|
852
|
+
Controller8,
|
|
783
853
|
{
|
|
784
854
|
control,
|
|
785
855
|
name,
|
|
786
856
|
render: ({ field: field2, fieldState }) => {
|
|
787
857
|
const selectedKey = field2.value;
|
|
788
|
-
return /* @__PURE__ */
|
|
858
|
+
return /* @__PURE__ */ React13.createElement("div", { className }, /* @__PURE__ */ React13.createElement(
|
|
789
859
|
Select,
|
|
790
860
|
{
|
|
791
861
|
...defaults.select,
|
|
@@ -803,7 +873,7 @@ function SelectField(props) {
|
|
|
803
873
|
field2.onChange(next);
|
|
804
874
|
}
|
|
805
875
|
},
|
|
806
|
-
options.map((opt) => /* @__PURE__ */
|
|
876
|
+
options.map((opt) => /* @__PURE__ */ React13.createElement(
|
|
807
877
|
SelectItem,
|
|
808
878
|
{
|
|
809
879
|
key: String(opt.value),
|
|
@@ -820,12 +890,12 @@ function SelectField(props) {
|
|
|
820
890
|
}
|
|
821
891
|
|
|
822
892
|
// src/fields/SliderField.tsx
|
|
823
|
-
import
|
|
824
|
-
import { Controller as
|
|
893
|
+
import React14 from "react";
|
|
894
|
+
import { Controller as Controller9 } from "react-hook-form";
|
|
825
895
|
function CoercedSlider(props) {
|
|
826
896
|
const { description, disabled, errorMessage, field: field2, label, sliderProps } = props;
|
|
827
897
|
const defaults = useHeroHookFormDefaults();
|
|
828
|
-
return /* @__PURE__ */
|
|
898
|
+
return /* @__PURE__ */ React14.createElement(
|
|
829
899
|
Slider,
|
|
830
900
|
{
|
|
831
901
|
...defaults.slider,
|
|
@@ -853,12 +923,12 @@ function SliderField(props) {
|
|
|
853
923
|
sliderProps,
|
|
854
924
|
transform
|
|
855
925
|
} = props;
|
|
856
|
-
return /* @__PURE__ */
|
|
857
|
-
|
|
926
|
+
return /* @__PURE__ */ React14.createElement(
|
|
927
|
+
Controller9,
|
|
858
928
|
{
|
|
859
929
|
control,
|
|
860
930
|
name,
|
|
861
|
-
render: ({ field: field2, fieldState }) => /* @__PURE__ */
|
|
931
|
+
render: ({ field: field2, fieldState }) => /* @__PURE__ */ React14.createElement("div", { className }, /* @__PURE__ */ React14.createElement(
|
|
862
932
|
CoercedSlider,
|
|
863
933
|
{
|
|
864
934
|
description,
|
|
@@ -878,8 +948,8 @@ function SliderField(props) {
|
|
|
878
948
|
}
|
|
879
949
|
|
|
880
950
|
// src/fields/SwitchField.tsx
|
|
881
|
-
import
|
|
882
|
-
import { Controller as
|
|
951
|
+
import React15 from "react";
|
|
952
|
+
import { Controller as Controller10 } from "react-hook-form";
|
|
883
953
|
function SwitchField(props) {
|
|
884
954
|
const {
|
|
885
955
|
className,
|
|
@@ -892,12 +962,12 @@ function SwitchField(props) {
|
|
|
892
962
|
switchProps
|
|
893
963
|
} = props;
|
|
894
964
|
const defaults = useHeroHookFormDefaults();
|
|
895
|
-
return /* @__PURE__ */
|
|
896
|
-
|
|
965
|
+
return /* @__PURE__ */ React15.createElement(
|
|
966
|
+
Controller10,
|
|
897
967
|
{
|
|
898
968
|
control,
|
|
899
969
|
name,
|
|
900
|
-
render: ({ field: field2, fieldState }) => /* @__PURE__ */
|
|
970
|
+
render: ({ field: field2, fieldState }) => /* @__PURE__ */ React15.createElement("div", { className }, /* @__PURE__ */ React15.createElement(
|
|
901
971
|
Switch,
|
|
902
972
|
{
|
|
903
973
|
...defaults.switch,
|
|
@@ -908,15 +978,15 @@ function SwitchField(props) {
|
|
|
908
978
|
onValueChange: (val) => field2.onChange(val)
|
|
909
979
|
},
|
|
910
980
|
label
|
|
911
|
-
), description ? /* @__PURE__ */
|
|
981
|
+
), 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
982
|
rules
|
|
913
983
|
}
|
|
914
984
|
);
|
|
915
985
|
}
|
|
916
986
|
|
|
917
987
|
// src/fields/TextareaField.tsx
|
|
918
|
-
import
|
|
919
|
-
import { Controller as
|
|
988
|
+
import React16 from "react";
|
|
989
|
+
import { Controller as Controller11 } from "react-hook-form";
|
|
920
990
|
function TextareaField(props) {
|
|
921
991
|
const {
|
|
922
992
|
className,
|
|
@@ -929,12 +999,12 @@ function TextareaField(props) {
|
|
|
929
999
|
textareaProps
|
|
930
1000
|
} = props;
|
|
931
1001
|
const defaults = useHeroHookFormDefaults();
|
|
932
|
-
return /* @__PURE__ */
|
|
933
|
-
|
|
1002
|
+
return /* @__PURE__ */ React16.createElement(
|
|
1003
|
+
Controller11,
|
|
934
1004
|
{
|
|
935
1005
|
control,
|
|
936
1006
|
name,
|
|
937
|
-
render: ({ field: field2, fieldState }) => /* @__PURE__ */
|
|
1007
|
+
render: ({ field: field2, fieldState }) => /* @__PURE__ */ React16.createElement("div", { className }, /* @__PURE__ */ React16.createElement(
|
|
938
1008
|
Textarea,
|
|
939
1009
|
{
|
|
940
1010
|
...defaults.textarea,
|
|
@@ -955,7 +1025,7 @@ function TextareaField(props) {
|
|
|
955
1025
|
}
|
|
956
1026
|
|
|
957
1027
|
// src/components/FormField.tsx
|
|
958
|
-
var FormField =
|
|
1028
|
+
var FormField = React17.memo(
|
|
959
1029
|
({
|
|
960
1030
|
config,
|
|
961
1031
|
form,
|
|
@@ -967,7 +1037,7 @@ var FormField = React16.memo(
|
|
|
967
1037
|
const { control } = form;
|
|
968
1038
|
const watchedValues = useWatch3({ control });
|
|
969
1039
|
if (config.type === "content") {
|
|
970
|
-
return /* @__PURE__ */
|
|
1040
|
+
return /* @__PURE__ */ React17.createElement(
|
|
971
1041
|
ContentField,
|
|
972
1042
|
{
|
|
973
1043
|
config,
|
|
@@ -997,7 +1067,7 @@ var FormField = React16.memo(
|
|
|
997
1067
|
};
|
|
998
1068
|
switch (config.type) {
|
|
999
1069
|
case "input":
|
|
1000
|
-
return /* @__PURE__ */
|
|
1070
|
+
return /* @__PURE__ */ React17.createElement(
|
|
1001
1071
|
InputField,
|
|
1002
1072
|
{
|
|
1003
1073
|
...baseProps,
|
|
@@ -1007,7 +1077,7 @@ var FormField = React16.memo(
|
|
|
1007
1077
|
}
|
|
1008
1078
|
);
|
|
1009
1079
|
case "textarea":
|
|
1010
|
-
return /* @__PURE__ */
|
|
1080
|
+
return /* @__PURE__ */ React17.createElement(
|
|
1011
1081
|
TextareaField,
|
|
1012
1082
|
{
|
|
1013
1083
|
...baseProps,
|
|
@@ -1017,7 +1087,7 @@ var FormField = React16.memo(
|
|
|
1017
1087
|
}
|
|
1018
1088
|
);
|
|
1019
1089
|
case "select":
|
|
1020
|
-
return /* @__PURE__ */
|
|
1090
|
+
return /* @__PURE__ */ React17.createElement(
|
|
1021
1091
|
SelectField,
|
|
1022
1092
|
{
|
|
1023
1093
|
...baseProps,
|
|
@@ -1030,8 +1100,22 @@ var FormField = React16.memo(
|
|
|
1030
1100
|
selectProps: config.selectProps
|
|
1031
1101
|
}
|
|
1032
1102
|
);
|
|
1103
|
+
case "autocomplete":
|
|
1104
|
+
return /* @__PURE__ */ React17.createElement(
|
|
1105
|
+
AutocompleteField,
|
|
1106
|
+
{
|
|
1107
|
+
...baseProps,
|
|
1108
|
+
control,
|
|
1109
|
+
defaultValue: config.defaultValue,
|
|
1110
|
+
items: (config.options ?? []).map((opt) => ({
|
|
1111
|
+
label: opt.label,
|
|
1112
|
+
value: String(opt.value)
|
|
1113
|
+
})),
|
|
1114
|
+
autocompleteProps: config.autocompleteProps
|
|
1115
|
+
}
|
|
1116
|
+
);
|
|
1033
1117
|
case "checkbox":
|
|
1034
|
-
return /* @__PURE__ */
|
|
1118
|
+
return /* @__PURE__ */ React17.createElement(
|
|
1035
1119
|
CheckboxField,
|
|
1036
1120
|
{
|
|
1037
1121
|
...baseProps,
|
|
@@ -1041,7 +1125,7 @@ var FormField = React16.memo(
|
|
|
1041
1125
|
}
|
|
1042
1126
|
);
|
|
1043
1127
|
case "radio":
|
|
1044
|
-
return /* @__PURE__ */
|
|
1128
|
+
return /* @__PURE__ */ React17.createElement(
|
|
1045
1129
|
RadioGroupField,
|
|
1046
1130
|
{
|
|
1047
1131
|
...baseProps,
|
|
@@ -1055,7 +1139,7 @@ var FormField = React16.memo(
|
|
|
1055
1139
|
}
|
|
1056
1140
|
);
|
|
1057
1141
|
case "switch":
|
|
1058
|
-
return /* @__PURE__ */
|
|
1142
|
+
return /* @__PURE__ */ React17.createElement(
|
|
1059
1143
|
SwitchField,
|
|
1060
1144
|
{
|
|
1061
1145
|
...baseProps,
|
|
@@ -1065,7 +1149,7 @@ var FormField = React16.memo(
|
|
|
1065
1149
|
}
|
|
1066
1150
|
);
|
|
1067
1151
|
case "slider":
|
|
1068
|
-
return /* @__PURE__ */
|
|
1152
|
+
return /* @__PURE__ */ React17.createElement(
|
|
1069
1153
|
SliderField,
|
|
1070
1154
|
{
|
|
1071
1155
|
...baseProps,
|
|
@@ -1075,7 +1159,7 @@ var FormField = React16.memo(
|
|
|
1075
1159
|
}
|
|
1076
1160
|
);
|
|
1077
1161
|
case "date":
|
|
1078
|
-
return /* @__PURE__ */
|
|
1162
|
+
return /* @__PURE__ */ React17.createElement(
|
|
1079
1163
|
DateField,
|
|
1080
1164
|
{
|
|
1081
1165
|
...baseProps,
|
|
@@ -1085,7 +1169,7 @@ var FormField = React16.memo(
|
|
|
1085
1169
|
}
|
|
1086
1170
|
);
|
|
1087
1171
|
case "file":
|
|
1088
|
-
return /* @__PURE__ */
|
|
1172
|
+
return /* @__PURE__ */ React17.createElement(
|
|
1089
1173
|
FileField,
|
|
1090
1174
|
{
|
|
1091
1175
|
...baseProps,
|
|
@@ -1097,7 +1181,7 @@ var FormField = React16.memo(
|
|
|
1097
1181
|
}
|
|
1098
1182
|
);
|
|
1099
1183
|
case "fontPicker":
|
|
1100
|
-
return /* @__PURE__ */
|
|
1184
|
+
return /* @__PURE__ */ React17.createElement(
|
|
1101
1185
|
FontPickerField,
|
|
1102
1186
|
{
|
|
1103
1187
|
...baseProps,
|
|
@@ -1115,7 +1199,7 @@ var FormField = React16.memo(
|
|
|
1115
1199
|
name: config.name
|
|
1116
1200
|
});
|
|
1117
1201
|
case "conditional":
|
|
1118
|
-
return /* @__PURE__ */
|
|
1202
|
+
return /* @__PURE__ */ React17.createElement(
|
|
1119
1203
|
ConditionalField,
|
|
1120
1204
|
{
|
|
1121
1205
|
config,
|
|
@@ -1124,7 +1208,7 @@ var FormField = React16.memo(
|
|
|
1124
1208
|
}
|
|
1125
1209
|
);
|
|
1126
1210
|
case "fieldArray":
|
|
1127
|
-
return /* @__PURE__ */
|
|
1211
|
+
return /* @__PURE__ */ React17.createElement(
|
|
1128
1212
|
FieldArrayField,
|
|
1129
1213
|
{
|
|
1130
1214
|
config,
|
|
@@ -1132,7 +1216,7 @@ var FormField = React16.memo(
|
|
|
1132
1216
|
}
|
|
1133
1217
|
);
|
|
1134
1218
|
case "dynamicSection":
|
|
1135
|
-
return /* @__PURE__ */
|
|
1219
|
+
return /* @__PURE__ */ React17.createElement(
|
|
1136
1220
|
DynamicSectionField,
|
|
1137
1221
|
{
|
|
1138
1222
|
config,
|
|
@@ -1184,12 +1268,12 @@ function ConfigurableForm({
|
|
|
1184
1268
|
});
|
|
1185
1269
|
const renderFields = () => {
|
|
1186
1270
|
if (layout === "grid") {
|
|
1187
|
-
return /* @__PURE__ */
|
|
1271
|
+
return /* @__PURE__ */ React18.createElement(
|
|
1188
1272
|
"div",
|
|
1189
1273
|
{
|
|
1190
1274
|
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
1275
|
},
|
|
1192
|
-
fields.map((field2) => /* @__PURE__ */
|
|
1276
|
+
fields.map((field2) => /* @__PURE__ */ React18.createElement(
|
|
1193
1277
|
FormField,
|
|
1194
1278
|
{
|
|
1195
1279
|
key: field2.name,
|
|
@@ -1201,7 +1285,7 @@ function ConfigurableForm({
|
|
|
1201
1285
|
);
|
|
1202
1286
|
}
|
|
1203
1287
|
if (layout === "horizontal") {
|
|
1204
|
-
return /* @__PURE__ */
|
|
1288
|
+
return /* @__PURE__ */ React18.createElement("div", { className: `grid gap-${spacing} grid-cols-1 md:grid-cols-2` }, fields.map((field2) => /* @__PURE__ */ React18.createElement(
|
|
1205
1289
|
FormField,
|
|
1206
1290
|
{
|
|
1207
1291
|
key: field2.name,
|
|
@@ -1211,7 +1295,7 @@ function ConfigurableForm({
|
|
|
1211
1295
|
}
|
|
1212
1296
|
)));
|
|
1213
1297
|
}
|
|
1214
|
-
return /* @__PURE__ */
|
|
1298
|
+
return /* @__PURE__ */ React18.createElement("div", { className: `space-y-${spacing}` }, fields.map((field2) => /* @__PURE__ */ React18.createElement(
|
|
1215
1299
|
FormField,
|
|
1216
1300
|
{
|
|
1217
1301
|
key: field2.name,
|
|
@@ -1225,23 +1309,23 @@ function ConfigurableForm({
|
|
|
1225
1309
|
e.preventDefault();
|
|
1226
1310
|
void handleSubmit();
|
|
1227
1311
|
};
|
|
1228
|
-
return /* @__PURE__ */
|
|
1312
|
+
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
1313
|
"div",
|
|
1230
1314
|
{
|
|
1231
1315
|
className: "mb-6 p-4 bg-success-50 border border-success-200 rounded-lg",
|
|
1232
1316
|
"data-testid": "success-message"
|
|
1233
1317
|
},
|
|
1234
|
-
/* @__PURE__ */
|
|
1235
|
-
/* @__PURE__ */
|
|
1236
|
-
), error && /* @__PURE__ */
|
|
1318
|
+
/* @__PURE__ */ React18.createElement("p", { className: "text-success-800 font-medium" }, "Success!"),
|
|
1319
|
+
/* @__PURE__ */ React18.createElement("p", { className: "text-success-700 text-sm mt-1" }, "Your request has been processed successfully.")
|
|
1320
|
+
), error && /* @__PURE__ */ React18.createElement(
|
|
1237
1321
|
"div",
|
|
1238
1322
|
{
|
|
1239
1323
|
className: "mb-6 p-4 bg-danger-50 border border-danger-200 rounded-lg",
|
|
1240
1324
|
"data-testid": "error-message"
|
|
1241
1325
|
},
|
|
1242
|
-
/* @__PURE__ */
|
|
1243
|
-
/* @__PURE__ */
|
|
1244
|
-
), renderFields(), /* @__PURE__ */
|
|
1326
|
+
/* @__PURE__ */ React18.createElement("p", { className: "text-danger-800 font-medium" }, "Error"),
|
|
1327
|
+
/* @__PURE__ */ React18.createElement("p", { className: "text-danger-700 text-sm mt-1" }, error)
|
|
1328
|
+
), renderFields(), /* @__PURE__ */ React18.createElement("div", { className: "mt-6 flex gap-3 justify-end" }, /* @__PURE__ */ React18.createElement(
|
|
1245
1329
|
Button3,
|
|
1246
1330
|
{
|
|
1247
1331
|
color: "primary",
|
|
@@ -1251,7 +1335,7 @@ function ConfigurableForm({
|
|
|
1251
1335
|
...submitButtonProps
|
|
1252
1336
|
},
|
|
1253
1337
|
submitButtonText
|
|
1254
|
-
), showResetButton && /* @__PURE__ */
|
|
1338
|
+
), showResetButton && /* @__PURE__ */ React18.createElement(
|
|
1255
1339
|
Button3,
|
|
1256
1340
|
{
|
|
1257
1341
|
isDisabled: isSubmitting,
|
|
@@ -1264,7 +1348,7 @@ function ConfigurableForm({
|
|
|
1264
1348
|
}
|
|
1265
1349
|
|
|
1266
1350
|
// src/components/ServerActionForm.tsx
|
|
1267
|
-
import
|
|
1351
|
+
import React19 from "react";
|
|
1268
1352
|
import { useActionState } from "react";
|
|
1269
1353
|
function ServerActionForm({
|
|
1270
1354
|
action,
|
|
@@ -1289,10 +1373,10 @@ function ServerActionForm({
|
|
|
1289
1373
|
action,
|
|
1290
1374
|
initialState ?? { errors: void 0, message: void 0, success: false }
|
|
1291
1375
|
);
|
|
1292
|
-
const formRef =
|
|
1293
|
-
const [clientErrors, setClientErrors] =
|
|
1294
|
-
const lastSubmittedFormData =
|
|
1295
|
-
|
|
1376
|
+
const formRef = React19.useRef(null);
|
|
1377
|
+
const [clientErrors, setClientErrors] = React19.useState({});
|
|
1378
|
+
const lastSubmittedFormData = React19.useRef(null);
|
|
1379
|
+
React19.useEffect(() => {
|
|
1296
1380
|
if (state && (state.errors || state.message && !state.success)) {
|
|
1297
1381
|
onError?.({
|
|
1298
1382
|
errors: state.errors,
|
|
@@ -1300,7 +1384,7 @@ function ServerActionForm({
|
|
|
1300
1384
|
});
|
|
1301
1385
|
}
|
|
1302
1386
|
}, [state, onError]);
|
|
1303
|
-
|
|
1387
|
+
React19.useEffect(() => {
|
|
1304
1388
|
if (state?.success && lastSubmittedFormData.current) {
|
|
1305
1389
|
onSuccess?.(lastSubmittedFormData.current);
|
|
1306
1390
|
}
|
|
@@ -1343,12 +1427,12 @@ function ServerActionForm({
|
|
|
1343
1427
|
};
|
|
1344
1428
|
const renderFields = () => {
|
|
1345
1429
|
if (layout === "grid") {
|
|
1346
|
-
return /* @__PURE__ */
|
|
1430
|
+
return /* @__PURE__ */ React19.createElement(
|
|
1347
1431
|
"div",
|
|
1348
1432
|
{
|
|
1349
1433
|
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
1434
|
},
|
|
1351
|
-
fields.map((field2) => /* @__PURE__ */
|
|
1435
|
+
fields.map((field2) => /* @__PURE__ */ React19.createElement(
|
|
1352
1436
|
ServerActionField,
|
|
1353
1437
|
{
|
|
1354
1438
|
key: field2.name,
|
|
@@ -1361,7 +1445,7 @@ function ServerActionForm({
|
|
|
1361
1445
|
);
|
|
1362
1446
|
}
|
|
1363
1447
|
if (layout === "horizontal") {
|
|
1364
|
-
return /* @__PURE__ */
|
|
1448
|
+
return /* @__PURE__ */ React19.createElement("div", { className: `grid gap-${spacing} grid-cols-1 md:grid-cols-2` }, fields.map((field2) => /* @__PURE__ */ React19.createElement(
|
|
1365
1449
|
ServerActionField,
|
|
1366
1450
|
{
|
|
1367
1451
|
key: field2.name,
|
|
@@ -1372,7 +1456,7 @@ function ServerActionForm({
|
|
|
1372
1456
|
}
|
|
1373
1457
|
)));
|
|
1374
1458
|
}
|
|
1375
|
-
return /* @__PURE__ */
|
|
1459
|
+
return /* @__PURE__ */ React19.createElement("div", { className: `space-y-${spacing}` }, fields.map((field2) => /* @__PURE__ */ React19.createElement(
|
|
1376
1460
|
ServerActionField,
|
|
1377
1461
|
{
|
|
1378
1462
|
key: field2.name,
|
|
@@ -1383,7 +1467,7 @@ function ServerActionForm({
|
|
|
1383
1467
|
}
|
|
1384
1468
|
)));
|
|
1385
1469
|
};
|
|
1386
|
-
return /* @__PURE__ */
|
|
1470
|
+
return /* @__PURE__ */ React19.createElement(
|
|
1387
1471
|
"form",
|
|
1388
1472
|
{
|
|
1389
1473
|
ref: formRef,
|
|
@@ -1391,27 +1475,27 @@ function ServerActionForm({
|
|
|
1391
1475
|
role: "form",
|
|
1392
1476
|
onSubmit: handleSubmit
|
|
1393
1477
|
},
|
|
1394
|
-
title && /* @__PURE__ */
|
|
1395
|
-
state?.success && !pending && /* @__PURE__ */
|
|
1478
|
+
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)),
|
|
1479
|
+
state?.success && !pending && /* @__PURE__ */ React19.createElement(
|
|
1396
1480
|
"div",
|
|
1397
1481
|
{
|
|
1398
1482
|
className: "mb-6 p-4 bg-success-50 border border-success-200 rounded-lg",
|
|
1399
1483
|
"data-testid": "success-message"
|
|
1400
1484
|
},
|
|
1401
|
-
/* @__PURE__ */
|
|
1402
|
-
state.message && /* @__PURE__ */
|
|
1485
|
+
/* @__PURE__ */ React19.createElement("p", { className: "text-success-800 font-medium" }, "Success!"),
|
|
1486
|
+
state.message && /* @__PURE__ */ React19.createElement("p", { className: "text-success-700 text-sm mt-1" }, state.message)
|
|
1403
1487
|
),
|
|
1404
|
-
state?.message && !state.success && /* @__PURE__ */
|
|
1488
|
+
state?.message && !state.success && /* @__PURE__ */ React19.createElement(
|
|
1405
1489
|
"div",
|
|
1406
1490
|
{
|
|
1407
1491
|
className: "mb-6 p-4 bg-danger-50 border border-danger-200 rounded-lg",
|
|
1408
1492
|
"data-testid": "error-message"
|
|
1409
1493
|
},
|
|
1410
|
-
/* @__PURE__ */
|
|
1411
|
-
/* @__PURE__ */
|
|
1494
|
+
/* @__PURE__ */ React19.createElement("p", { className: "text-danger-800 font-medium" }, "Error"),
|
|
1495
|
+
/* @__PURE__ */ React19.createElement("p", { className: "text-danger-700 text-sm mt-1" }, state.message)
|
|
1412
1496
|
),
|
|
1413
1497
|
renderFields(),
|
|
1414
|
-
/* @__PURE__ */
|
|
1498
|
+
/* @__PURE__ */ React19.createElement("div", { className: "mt-6 flex gap-3 justify-end" }, /* @__PURE__ */ React19.createElement(
|
|
1415
1499
|
Button,
|
|
1416
1500
|
{
|
|
1417
1501
|
color: "primary",
|
|
@@ -1421,7 +1505,7 @@ function ServerActionForm({
|
|
|
1421
1505
|
...submitButtonProps
|
|
1422
1506
|
},
|
|
1423
1507
|
submitButtonText
|
|
1424
|
-
), showResetButton && /* @__PURE__ */
|
|
1508
|
+
), showResetButton && /* @__PURE__ */ React19.createElement(
|
|
1425
1509
|
Button,
|
|
1426
1510
|
{
|
|
1427
1511
|
isDisabled: pending,
|
|
@@ -1442,13 +1526,13 @@ function ServerActionField({
|
|
|
1442
1526
|
if (field2.type === "content") {
|
|
1443
1527
|
const contentField2 = field2;
|
|
1444
1528
|
if (contentField2.render) {
|
|
1445
|
-
return /* @__PURE__ */
|
|
1529
|
+
return /* @__PURE__ */ React19.createElement("div", { className: contentField2.className }, contentField2.render({
|
|
1446
1530
|
errors: {},
|
|
1447
1531
|
form: null,
|
|
1448
1532
|
isSubmitting: false
|
|
1449
1533
|
}));
|
|
1450
1534
|
}
|
|
1451
|
-
return /* @__PURE__ */
|
|
1535
|
+
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
1536
|
}
|
|
1453
1537
|
const fieldName = field2.name;
|
|
1454
1538
|
const fieldErrors = errors?.[fieldName];
|
|
@@ -1476,9 +1560,9 @@ function ServerActionField({
|
|
|
1476
1560
|
}
|
|
1477
1561
|
return false;
|
|
1478
1562
|
};
|
|
1479
|
-
const [value, setValue] =
|
|
1480
|
-
const [checked, setChecked] =
|
|
1481
|
-
|
|
1563
|
+
const [value, setValue] = React19.useState(getDefaultValue);
|
|
1564
|
+
const [checked, setChecked] = React19.useState(getDefaultChecked);
|
|
1565
|
+
React19.useEffect(() => {
|
|
1482
1566
|
const newDefaultValue = defaultValues?.[fieldName];
|
|
1483
1567
|
if (newDefaultValue !== void 0 && newDefaultValue !== null) {
|
|
1484
1568
|
if (field2.type === "checkbox") {
|
|
@@ -1492,7 +1576,7 @@ function ServerActionField({
|
|
|
1492
1576
|
}
|
|
1493
1577
|
}
|
|
1494
1578
|
}, [defaultValues, fieldName, field2.type]);
|
|
1495
|
-
|
|
1579
|
+
React19.useEffect(() => {
|
|
1496
1580
|
const hiddenInput = document.querySelector(
|
|
1497
1581
|
`input[type="hidden"][name="${fieldName}"]`
|
|
1498
1582
|
);
|
|
@@ -1507,7 +1591,7 @@ function ServerActionField({
|
|
|
1507
1591
|
switch (field2.type) {
|
|
1508
1592
|
case "input": {
|
|
1509
1593
|
const inputType = field2.inputProps?.type || "text";
|
|
1510
|
-
return /* @__PURE__ */
|
|
1594
|
+
return /* @__PURE__ */ React19.createElement(React19.Fragment, null, /* @__PURE__ */ React19.createElement("input", { type: "hidden", name: fieldName, value }), /* @__PURE__ */ React19.createElement(
|
|
1511
1595
|
Input,
|
|
1512
1596
|
{
|
|
1513
1597
|
...field2.inputProps,
|
|
@@ -1524,7 +1608,7 @@ function ServerActionField({
|
|
|
1524
1608
|
));
|
|
1525
1609
|
}
|
|
1526
1610
|
case "textarea": {
|
|
1527
|
-
return /* @__PURE__ */
|
|
1611
|
+
return /* @__PURE__ */ React19.createElement(React19.Fragment, null, /* @__PURE__ */ React19.createElement("input", { type: "hidden", name: fieldName, value }), /* @__PURE__ */ React19.createElement(
|
|
1528
1612
|
Textarea,
|
|
1529
1613
|
{
|
|
1530
1614
|
...field2.textareaProps,
|
|
@@ -1540,7 +1624,7 @@ function ServerActionField({
|
|
|
1540
1624
|
));
|
|
1541
1625
|
}
|
|
1542
1626
|
case "checkbox": {
|
|
1543
|
-
return /* @__PURE__ */
|
|
1627
|
+
return /* @__PURE__ */ React19.createElement(React19.Fragment, null, /* @__PURE__ */ React19.createElement("input", { type: "hidden", name: fieldName, value: checked ? "on" : "" }), /* @__PURE__ */ React19.createElement(
|
|
1544
1628
|
Checkbox,
|
|
1545
1629
|
{
|
|
1546
1630
|
...field2.checkboxProps,
|
|
@@ -1556,7 +1640,7 @@ function ServerActionField({
|
|
|
1556
1640
|
}
|
|
1557
1641
|
case "select": {
|
|
1558
1642
|
const options = field2.options || [];
|
|
1559
|
-
return /* @__PURE__ */
|
|
1643
|
+
return /* @__PURE__ */ React19.createElement(React19.Fragment, null, /* @__PURE__ */ React19.createElement("input", { type: "hidden", name: fieldName, value }), /* @__PURE__ */ React19.createElement(
|
|
1560
1644
|
Select,
|
|
1561
1645
|
{
|
|
1562
1646
|
...field2.selectProps,
|
|
@@ -1573,12 +1657,12 @@ function ServerActionField({
|
|
|
1573
1657
|
}
|
|
1574
1658
|
},
|
|
1575
1659
|
options.map(
|
|
1576
|
-
(option) => /* @__PURE__ */
|
|
1660
|
+
(option) => /* @__PURE__ */ React19.createElement(SelectItem, { key: String(option.value) }, option.label)
|
|
1577
1661
|
)
|
|
1578
1662
|
));
|
|
1579
1663
|
}
|
|
1580
1664
|
default:
|
|
1581
|
-
return /* @__PURE__ */
|
|
1665
|
+
return /* @__PURE__ */ React19.createElement(React19.Fragment, null, /* @__PURE__ */ React19.createElement("input", { type: "hidden", name: fieldName, value }), /* @__PURE__ */ React19.createElement(
|
|
1582
1666
|
Input,
|
|
1583
1667
|
{
|
|
1584
1668
|
"data-field-name": fieldName,
|
|
@@ -1608,10 +1692,10 @@ function useHeroForm() {
|
|
|
1608
1692
|
}
|
|
1609
1693
|
|
|
1610
1694
|
// src/providers/FormProvider.tsx
|
|
1611
|
-
import
|
|
1695
|
+
import React20 from "react";
|
|
1612
1696
|
import { FormProvider as RHFProvider } from "react-hook-form";
|
|
1613
1697
|
function FormProvider(props) {
|
|
1614
|
-
return /* @__PURE__ */
|
|
1698
|
+
return /* @__PURE__ */ React20.createElement(RHFProvider, { ...props.methods }, /* @__PURE__ */ React20.createElement(
|
|
1615
1699
|
"form",
|
|
1616
1700
|
{
|
|
1617
1701
|
className: props.className,
|
|
@@ -1624,7 +1708,7 @@ function FormProvider(props) {
|
|
|
1624
1708
|
}
|
|
1625
1709
|
|
|
1626
1710
|
// src/submit/SubmitButton.tsx
|
|
1627
|
-
import
|
|
1711
|
+
import React21 from "react";
|
|
1628
1712
|
function SubmitButton(props) {
|
|
1629
1713
|
const ctx = useFormContext5();
|
|
1630
1714
|
const loading = props.isLoading ?? ctx.formState.isSubmitting;
|
|
@@ -1634,10 +1718,10 @@ function SubmitButton(props) {
|
|
|
1634
1718
|
const defaults = useHeroHookFormDefaults();
|
|
1635
1719
|
const getButtonContent = () => {
|
|
1636
1720
|
if (enhancedState?.isSuccess) {
|
|
1637
|
-
return /* @__PURE__ */
|
|
1721
|
+
return /* @__PURE__ */ React21.createElement("span", { className: "inline-flex items-center gap-2" }, "\u2705", props.successText || "Success!");
|
|
1638
1722
|
}
|
|
1639
1723
|
if (loading) {
|
|
1640
|
-
return /* @__PURE__ */
|
|
1724
|
+
return /* @__PURE__ */ React21.createElement("span", { className: "inline-flex items-center gap-2" }, "\u23F3", props.loadingText || "Submitting...");
|
|
1641
1725
|
}
|
|
1642
1726
|
return props.children;
|
|
1643
1727
|
};
|
|
@@ -1650,7 +1734,7 @@ function SubmitButton(props) {
|
|
|
1650
1734
|
}
|
|
1651
1735
|
return props.buttonProps?.color || defaults.submitButton.color;
|
|
1652
1736
|
};
|
|
1653
|
-
return /* @__PURE__ */
|
|
1737
|
+
return /* @__PURE__ */ React21.createElement(
|
|
1654
1738
|
Button,
|
|
1655
1739
|
{
|
|
1656
1740
|
type: "submit",
|
|
@@ -1891,7 +1975,7 @@ var commonValidations = {
|
|
|
1891
1975
|
import { useFormContext as useFormContext5 } from "react-hook-form";
|
|
1892
1976
|
|
|
1893
1977
|
// src/components/ZodForm.tsx
|
|
1894
|
-
import
|
|
1978
|
+
import React23 from "react";
|
|
1895
1979
|
import { Button as Button5 } from "@heroui/react";
|
|
1896
1980
|
import {
|
|
1897
1981
|
FormProvider as FormProvider2
|
|
@@ -2014,7 +2098,7 @@ function useEnhancedFormState(form, options = {}) {
|
|
|
2014
2098
|
}
|
|
2015
2099
|
|
|
2016
2100
|
// src/components/FormStatus.tsx
|
|
2017
|
-
import
|
|
2101
|
+
import React22 from "react";
|
|
2018
2102
|
import { Button as Button4 } from "@heroui/react";
|
|
2019
2103
|
function FormStatus({
|
|
2020
2104
|
className = "",
|
|
@@ -2027,25 +2111,25 @@ function FormStatus({
|
|
|
2027
2111
|
return null;
|
|
2028
2112
|
}
|
|
2029
2113
|
if (isSubmitting) {
|
|
2030
|
-
return /* @__PURE__ */
|
|
2114
|
+
return /* @__PURE__ */ React22.createElement(
|
|
2031
2115
|
"div",
|
|
2032
2116
|
{
|
|
2033
2117
|
className: `flex items-center gap-3 p-4 bg-blue-50 border border-blue-200 rounded-lg ${className}`
|
|
2034
2118
|
},
|
|
2035
|
-
/* @__PURE__ */
|
|
2036
|
-
/* @__PURE__ */
|
|
2119
|
+
/* @__PURE__ */ React22.createElement("span", { className: "text-blue-600" }, "\u23F3"),
|
|
2120
|
+
/* @__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
2121
|
);
|
|
2038
2122
|
}
|
|
2039
2123
|
if (isSuccess) {
|
|
2040
|
-
return /* @__PURE__ */
|
|
2124
|
+
return /* @__PURE__ */ React22.createElement(
|
|
2041
2125
|
"div",
|
|
2042
2126
|
{
|
|
2043
2127
|
className: `flex items-center gap-3 p-4 bg-green-50 border border-green-200 rounded-lg ${className}`,
|
|
2044
2128
|
"data-testid": "success-message"
|
|
2045
2129
|
},
|
|
2046
|
-
/* @__PURE__ */
|
|
2047
|
-
/* @__PURE__ */
|
|
2048
|
-
onDismiss && /* @__PURE__ */
|
|
2130
|
+
/* @__PURE__ */ React22.createElement("span", { className: "text-green-600" }, "\u2705"),
|
|
2131
|
+
/* @__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.")),
|
|
2132
|
+
onDismiss && /* @__PURE__ */ React22.createElement(
|
|
2049
2133
|
Button4,
|
|
2050
2134
|
{
|
|
2051
2135
|
size: "sm",
|
|
@@ -2059,15 +2143,15 @@ function FormStatus({
|
|
|
2059
2143
|
);
|
|
2060
2144
|
}
|
|
2061
2145
|
if (isError && error) {
|
|
2062
|
-
return /* @__PURE__ */
|
|
2146
|
+
return /* @__PURE__ */ React22.createElement(
|
|
2063
2147
|
"div",
|
|
2064
2148
|
{
|
|
2065
2149
|
className: `flex items-center gap-3 p-4 bg-red-50 border border-red-200 rounded-lg ${className}`,
|
|
2066
2150
|
"data-testid": "error-message"
|
|
2067
2151
|
},
|
|
2068
|
-
/* @__PURE__ */
|
|
2069
|
-
/* @__PURE__ */
|
|
2070
|
-
onDismiss && /* @__PURE__ */
|
|
2152
|
+
/* @__PURE__ */ React22.createElement("span", { className: "text-red-600" }, "\u26A0\uFE0F"),
|
|
2153
|
+
/* @__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)),
|
|
2154
|
+
onDismiss && /* @__PURE__ */ React22.createElement(
|
|
2071
2155
|
Button4,
|
|
2072
2156
|
{
|
|
2073
2157
|
size: "sm",
|
|
@@ -2088,8 +2172,8 @@ function FormToast({
|
|
|
2088
2172
|
position = "top-right",
|
|
2089
2173
|
state
|
|
2090
2174
|
}) {
|
|
2091
|
-
const [isVisible, setIsVisible] =
|
|
2092
|
-
|
|
2175
|
+
const [isVisible, setIsVisible] = React22.useState(false);
|
|
2176
|
+
React22.useEffect(() => {
|
|
2093
2177
|
if (state.isSuccess || state.isError) {
|
|
2094
2178
|
setIsVisible(true);
|
|
2095
2179
|
if (duration > 0) {
|
|
@@ -2110,7 +2194,7 @@ function FormToast({
|
|
|
2110
2194
|
"top-left": "top-4 left-4",
|
|
2111
2195
|
"top-right": "top-4 right-4"
|
|
2112
2196
|
};
|
|
2113
|
-
return /* @__PURE__ */
|
|
2197
|
+
return /* @__PURE__ */ React22.createElement("div", { className: `fixed z-50 ${positionClasses[position]}` }, /* @__PURE__ */ React22.createElement(FormStatus, { state, onDismiss }));
|
|
2114
2198
|
}
|
|
2115
2199
|
|
|
2116
2200
|
// src/components/ZodForm.tsx
|
|
@@ -2160,12 +2244,12 @@ function ZodForm({
|
|
|
2160
2244
|
};
|
|
2161
2245
|
const renderFields = () => {
|
|
2162
2246
|
if (layout === "grid") {
|
|
2163
|
-
return /* @__PURE__ */
|
|
2247
|
+
return /* @__PURE__ */ React23.createElement(
|
|
2164
2248
|
"div",
|
|
2165
2249
|
{
|
|
2166
2250
|
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"}`
|
|
2167
2251
|
},
|
|
2168
|
-
config.fields.map((field2) => /* @__PURE__ */
|
|
2252
|
+
config.fields.map((field2) => /* @__PURE__ */ React23.createElement(
|
|
2169
2253
|
FormField,
|
|
2170
2254
|
{
|
|
2171
2255
|
key: field2.name,
|
|
@@ -2182,7 +2266,7 @@ function ZodForm({
|
|
|
2182
2266
|
);
|
|
2183
2267
|
}
|
|
2184
2268
|
if (layout === "horizontal") {
|
|
2185
|
-
return /* @__PURE__ */
|
|
2269
|
+
return /* @__PURE__ */ React23.createElement("div", { className: `grid gap-${spacing} grid-cols-1 md:grid-cols-2` }, config.fields.map((field2) => /* @__PURE__ */ React23.createElement(
|
|
2186
2270
|
FormField,
|
|
2187
2271
|
{
|
|
2188
2272
|
key: field2.name,
|
|
@@ -2197,7 +2281,7 @@ function ZodForm({
|
|
|
2197
2281
|
}
|
|
2198
2282
|
)));
|
|
2199
2283
|
}
|
|
2200
|
-
return /* @__PURE__ */
|
|
2284
|
+
return /* @__PURE__ */ React23.createElement("div", { className: `space-y-${spacing}` }, config.fields.map((field2) => /* @__PURE__ */ React23.createElement(
|
|
2201
2285
|
FormField,
|
|
2202
2286
|
{
|
|
2203
2287
|
key: field2.name,
|
|
@@ -2216,19 +2300,19 @@ function ZodForm({
|
|
|
2216
2300
|
e.preventDefault();
|
|
2217
2301
|
void handleSubmit();
|
|
2218
2302
|
};
|
|
2219
|
-
|
|
2303
|
+
React23.useEffect(() => {
|
|
2220
2304
|
if (config.onError && Object.keys(form.formState.errors).length > 0) {
|
|
2221
2305
|
config.onError(form.formState.errors);
|
|
2222
2306
|
}
|
|
2223
2307
|
}, [form.formState.errors, config.onError]);
|
|
2224
|
-
return /* @__PURE__ */
|
|
2308
|
+
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(
|
|
2225
2309
|
FormStatus,
|
|
2226
2310
|
{
|
|
2227
2311
|
state: enhancedState,
|
|
2228
2312
|
onDismiss: () => enhancedState.reset(),
|
|
2229
2313
|
showDetails: true
|
|
2230
2314
|
}
|
|
2231
|
-
), renderFields(), /* @__PURE__ */
|
|
2315
|
+
), renderFields(), /* @__PURE__ */ React23.createElement("div", { className: "mt-6 flex gap-3 justify-end" }, /* @__PURE__ */ React23.createElement(
|
|
2232
2316
|
Button5,
|
|
2233
2317
|
{
|
|
2234
2318
|
color: "primary",
|
|
@@ -2238,7 +2322,7 @@ function ZodForm({
|
|
|
2238
2322
|
...submitButtonProps
|
|
2239
2323
|
},
|
|
2240
2324
|
enhancedState.isSuccess ? "Success!" : submitButtonText
|
|
2241
|
-
), showResetButton && /* @__PURE__ */
|
|
2325
|
+
), showResetButton && /* @__PURE__ */ React23.createElement(
|
|
2242
2326
|
Button5,
|
|
2243
2327
|
{
|
|
2244
2328
|
isDisabled: enhancedState.isSubmitting,
|
|
@@ -2291,6 +2375,19 @@ var BasicFormBuilder = class {
|
|
|
2291
2375
|
});
|
|
2292
2376
|
return this;
|
|
2293
2377
|
}
|
|
2378
|
+
/**
|
|
2379
|
+
* Add an autocomplete field
|
|
2380
|
+
*/
|
|
2381
|
+
autocomplete(name, label, items, placeholder) {
|
|
2382
|
+
this.fields.push({
|
|
2383
|
+
autocompleteProps: placeholder ? { placeholder } : void 0,
|
|
2384
|
+
label,
|
|
2385
|
+
name,
|
|
2386
|
+
options: items,
|
|
2387
|
+
type: "autocomplete"
|
|
2388
|
+
});
|
|
2389
|
+
return this;
|
|
2390
|
+
}
|
|
2294
2391
|
/**
|
|
2295
2392
|
* Add a checkbox field
|
|
2296
2393
|
*/
|
|
@@ -2319,8 +2416,9 @@ var BasicFormBuilder = class {
|
|
|
2319
2416
|
/**
|
|
2320
2417
|
* Add a switch field
|
|
2321
2418
|
*/
|
|
2322
|
-
switch(name, label) {
|
|
2419
|
+
switch(name, label, description) {
|
|
2323
2420
|
this.fields.push({
|
|
2421
|
+
description,
|
|
2324
2422
|
label,
|
|
2325
2423
|
name,
|
|
2326
2424
|
type: "switch"
|
|
@@ -2338,6 +2436,16 @@ function createBasicFormBuilder() {
|
|
|
2338
2436
|
return new BasicFormBuilder();
|
|
2339
2437
|
}
|
|
2340
2438
|
var FormFieldHelpers = {
|
|
2439
|
+
/**
|
|
2440
|
+
* Create an autocomplete field
|
|
2441
|
+
*/
|
|
2442
|
+
autocomplete: (name, label, items, placeholder) => ({
|
|
2443
|
+
autocompleteProps: placeholder ? { placeholder } : void 0,
|
|
2444
|
+
label,
|
|
2445
|
+
name,
|
|
2446
|
+
options: items,
|
|
2447
|
+
type: "autocomplete"
|
|
2448
|
+
}),
|
|
2341
2449
|
/**
|
|
2342
2450
|
* Create a checkbox field
|
|
2343
2451
|
*/
|
|
@@ -2346,6 +2454,37 @@ var FormFieldHelpers = {
|
|
|
2346
2454
|
name,
|
|
2347
2455
|
type: "checkbox"
|
|
2348
2456
|
}),
|
|
2457
|
+
/**
|
|
2458
|
+
* Create a conditional field that shows/hides based on form data
|
|
2459
|
+
*
|
|
2460
|
+
* @example
|
|
2461
|
+
* ```tsx
|
|
2462
|
+
* FormFieldHelpers.conditional(
|
|
2463
|
+
* "phone",
|
|
2464
|
+
* (values) => values.hasPhone === true,
|
|
2465
|
+
* FormFieldHelpers.input("phone", "Phone Number", "tel")
|
|
2466
|
+
* )
|
|
2467
|
+
* ```
|
|
2468
|
+
*
|
|
2469
|
+
* @example
|
|
2470
|
+
* With explicit type in condition function (similar to content helper pattern):
|
|
2471
|
+
* ```tsx
|
|
2472
|
+
* FormFieldHelpers.conditional(
|
|
2473
|
+
* "options",
|
|
2474
|
+
* (formData: Partial<z.infer<typeof fieldSchema>>) =>
|
|
2475
|
+
* formData.fieldType === 'DROPDOWN',
|
|
2476
|
+
* FormFieldHelpers.textarea("options", "Dropdown Options", "One per line")
|
|
2477
|
+
* )
|
|
2478
|
+
* ```
|
|
2479
|
+
*/
|
|
2480
|
+
conditional: (name, condition, field2) => {
|
|
2481
|
+
return {
|
|
2482
|
+
condition,
|
|
2483
|
+
field: field2,
|
|
2484
|
+
name,
|
|
2485
|
+
type: "conditional"
|
|
2486
|
+
};
|
|
2487
|
+
},
|
|
2349
2488
|
/**
|
|
2350
2489
|
* Create a content field for headers, questions, or custom content between fields
|
|
2351
2490
|
*
|
|
@@ -2400,7 +2539,8 @@ var FormFieldHelpers = {
|
|
|
2400
2539
|
/**
|
|
2401
2540
|
* Create a switch field
|
|
2402
2541
|
*/
|
|
2403
|
-
switch: (name, label) => ({
|
|
2542
|
+
switch: (name, label, description) => ({
|
|
2543
|
+
description,
|
|
2404
2544
|
label,
|
|
2405
2545
|
name,
|
|
2406
2546
|
type: "switch"
|
|
@@ -2518,13 +2658,14 @@ function checkboxField(name, label, props) {
|
|
|
2518
2658
|
}
|
|
2519
2659
|
function switchField(name, label, props) {
|
|
2520
2660
|
return {
|
|
2661
|
+
description: props?.description,
|
|
2662
|
+
isDisabled: props?.isDisabled,
|
|
2521
2663
|
label,
|
|
2522
2664
|
name,
|
|
2523
2665
|
type: "switch",
|
|
2524
|
-
...props && {
|
|
2666
|
+
...props?.className && {
|
|
2525
2667
|
switchProps: {
|
|
2526
|
-
className: props.className
|
|
2527
|
-
disabled: props.isDisabled
|
|
2668
|
+
className: props.className
|
|
2528
2669
|
}
|
|
2529
2670
|
}
|
|
2530
2671
|
};
|
|
@@ -3535,6 +3676,7 @@ var validationUtils = {
|
|
|
3535
3676
|
};
|
|
3536
3677
|
export {
|
|
3537
3678
|
AdvancedFieldBuilder,
|
|
3679
|
+
AutocompleteField,
|
|
3538
3680
|
BasicFormBuilder,
|
|
3539
3681
|
CheckboxField,
|
|
3540
3682
|
CommonFields,
|