@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/react/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,107 @@ 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/react.ts
|
|
86
|
+
import {
|
|
87
|
+
Autocomplete,
|
|
88
|
+
AutocompleteItem,
|
|
89
|
+
Button,
|
|
90
|
+
Checkbox,
|
|
91
|
+
DateInput,
|
|
92
|
+
DatePicker,
|
|
93
|
+
Input,
|
|
94
|
+
Radio,
|
|
95
|
+
RadioGroup,
|
|
96
|
+
Select,
|
|
97
|
+
SelectItem,
|
|
98
|
+
Slider,
|
|
99
|
+
Spinner,
|
|
100
|
+
Switch,
|
|
101
|
+
Textarea
|
|
102
|
+
} from "@heroui/react";
|
|
103
|
+
|
|
104
|
+
// src/fields/AutocompleteField.tsx
|
|
105
|
+
function AutocompleteField(props) {
|
|
106
|
+
const {
|
|
107
|
+
autocompleteProps,
|
|
108
|
+
children,
|
|
109
|
+
className,
|
|
110
|
+
control,
|
|
111
|
+
description,
|
|
112
|
+
isDisabled,
|
|
113
|
+
items,
|
|
114
|
+
label,
|
|
115
|
+
name,
|
|
116
|
+
placeholder,
|
|
117
|
+
rules
|
|
118
|
+
} = props;
|
|
119
|
+
return /* @__PURE__ */ React.createElement(
|
|
120
|
+
Controller,
|
|
121
|
+
{
|
|
122
|
+
control,
|
|
123
|
+
name,
|
|
124
|
+
render: ({ field: field2, fieldState }) => {
|
|
125
|
+
const selectedKey = field2.value;
|
|
126
|
+
const hasSelectedValue = selectedKey != null && selectedKey !== "";
|
|
127
|
+
const allowsCustomValue = autocompleteProps?.allowsCustomValue ?? false;
|
|
128
|
+
const shouldShowInputValue = allowsCustomValue || !hasSelectedValue;
|
|
129
|
+
return /* @__PURE__ */ React.createElement("div", { className }, /* @__PURE__ */ React.createElement(
|
|
130
|
+
Autocomplete,
|
|
131
|
+
{
|
|
132
|
+
...autocompleteProps,
|
|
133
|
+
description,
|
|
134
|
+
errorMessage: fieldState.error?.message,
|
|
135
|
+
isDisabled,
|
|
136
|
+
isInvalid: Boolean(fieldState.error),
|
|
137
|
+
label,
|
|
138
|
+
placeholder,
|
|
139
|
+
selectedKey: allowsCustomValue ? void 0 : hasSelectedValue ? String(selectedKey) : void 0,
|
|
140
|
+
inputValue: shouldShowInputValue ? field2.value ?? "" : void 0,
|
|
141
|
+
onSelectionChange: (key) => {
|
|
142
|
+
const next = key ?? "";
|
|
143
|
+
field2.onChange(next);
|
|
144
|
+
},
|
|
145
|
+
onInputChange: (value) => {
|
|
146
|
+
if (allowsCustomValue) {
|
|
147
|
+
field2.onChange(value);
|
|
148
|
+
}
|
|
149
|
+
},
|
|
150
|
+
items
|
|
151
|
+
},
|
|
152
|
+
children ? children : (item) => /* @__PURE__ */ React.createElement(
|
|
153
|
+
AutocompleteItem,
|
|
154
|
+
{
|
|
155
|
+
key: String(item.value),
|
|
156
|
+
textValue: String(item.value),
|
|
157
|
+
description: item.description,
|
|
158
|
+
isDisabled: item.disabled
|
|
159
|
+
},
|
|
160
|
+
item.label
|
|
161
|
+
)
|
|
162
|
+
));
|
|
163
|
+
},
|
|
164
|
+
rules
|
|
165
|
+
}
|
|
166
|
+
);
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
// src/fields/CheckboxField.tsx
|
|
170
|
+
import React3 from "react";
|
|
171
|
+
import { Controller as Controller2 } from "react-hook-form";
|
|
172
|
+
|
|
85
173
|
// src/providers/ConfigProvider.tsx
|
|
86
|
-
import
|
|
174
|
+
import React2, { createContext, useContext, useMemo } from "react";
|
|
87
175
|
var DefaultsContext = createContext(null);
|
|
88
176
|
function HeroHookFormProvider(props) {
|
|
89
177
|
const value = useMemo(() => props.defaults ?? {}, [props.defaults]);
|
|
90
|
-
return /* @__PURE__ */
|
|
178
|
+
return /* @__PURE__ */ React2.createElement(DefaultsContext.Provider, { value }, props.children);
|
|
91
179
|
}
|
|
92
180
|
function useHeroHookFormDefaults() {
|
|
93
181
|
const cfg = useContext(DefaultsContext) ?? {};
|
|
@@ -168,23 +256,6 @@ function useHeroHookFormDefaults() {
|
|
|
168
256
|
};
|
|
169
257
|
}
|
|
170
258
|
|
|
171
|
-
// src/ui/react.ts
|
|
172
|
-
import {
|
|
173
|
-
Button,
|
|
174
|
-
Checkbox,
|
|
175
|
-
DateInput,
|
|
176
|
-
DatePicker,
|
|
177
|
-
Input,
|
|
178
|
-
Radio,
|
|
179
|
-
RadioGroup,
|
|
180
|
-
Select,
|
|
181
|
-
SelectItem,
|
|
182
|
-
Slider,
|
|
183
|
-
Spinner,
|
|
184
|
-
Switch,
|
|
185
|
-
Textarea
|
|
186
|
-
} from "@heroui/react";
|
|
187
|
-
|
|
188
259
|
// src/fields/CheckboxField.tsx
|
|
189
260
|
function CheckboxField(props) {
|
|
190
261
|
const {
|
|
@@ -198,12 +269,12 @@ function CheckboxField(props) {
|
|
|
198
269
|
rules
|
|
199
270
|
} = props;
|
|
200
271
|
const defaults = useHeroHookFormDefaults();
|
|
201
|
-
return /* @__PURE__ */
|
|
202
|
-
|
|
272
|
+
return /* @__PURE__ */ React3.createElement(
|
|
273
|
+
Controller2,
|
|
203
274
|
{
|
|
204
275
|
control,
|
|
205
276
|
name,
|
|
206
|
-
render: ({ field: field2, fieldState }) => /* @__PURE__ */
|
|
277
|
+
render: ({ field: field2, fieldState }) => /* @__PURE__ */ React3.createElement("div", { className }, /* @__PURE__ */ React3.createElement(
|
|
207
278
|
Checkbox,
|
|
208
279
|
{
|
|
209
280
|
...defaults.checkbox,
|
|
@@ -215,14 +286,14 @@ function CheckboxField(props) {
|
|
|
215
286
|
onValueChange: (val) => field2.onChange(val)
|
|
216
287
|
},
|
|
217
288
|
label
|
|
218
|
-
), description ? /* @__PURE__ */
|
|
289
|
+
), 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),
|
|
219
290
|
rules
|
|
220
291
|
}
|
|
221
292
|
);
|
|
222
293
|
}
|
|
223
294
|
|
|
224
295
|
// src/fields/ConditionalField.tsx
|
|
225
|
-
import
|
|
296
|
+
import React4 from "react";
|
|
226
297
|
import { useWatch, useFormContext } from "react-hook-form";
|
|
227
298
|
function ConditionalField({
|
|
228
299
|
className,
|
|
@@ -236,7 +307,7 @@ function ConditionalField({
|
|
|
236
307
|
if (!shouldShow) {
|
|
237
308
|
return null;
|
|
238
309
|
}
|
|
239
|
-
return /* @__PURE__ */
|
|
310
|
+
return /* @__PURE__ */ React4.createElement("div", { className }, /* @__PURE__ */ React4.createElement(
|
|
240
311
|
FormField,
|
|
241
312
|
{
|
|
242
313
|
config: field2,
|
|
@@ -252,29 +323,29 @@ function ConditionalField({
|
|
|
252
323
|
}
|
|
253
324
|
|
|
254
325
|
// src/fields/ContentField.tsx
|
|
255
|
-
import
|
|
326
|
+
import React5 from "react";
|
|
256
327
|
function ContentField({
|
|
257
328
|
config,
|
|
258
329
|
form,
|
|
259
330
|
submissionState
|
|
260
331
|
}) {
|
|
261
332
|
if (config.render) {
|
|
262
|
-
return /* @__PURE__ */
|
|
333
|
+
return /* @__PURE__ */ React5.createElement("div", { className: config.className }, config.render({
|
|
263
334
|
errors: form.formState.errors,
|
|
264
335
|
form,
|
|
265
336
|
isSubmitting: submissionState.isSubmitting
|
|
266
337
|
}));
|
|
267
338
|
}
|
|
268
|
-
return /* @__PURE__ */
|
|
339
|
+
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));
|
|
269
340
|
}
|
|
270
341
|
|
|
271
342
|
// src/fields/DateField.tsx
|
|
272
|
-
import
|
|
273
|
-
import { Controller as
|
|
343
|
+
import React6 from "react";
|
|
344
|
+
import { Controller as Controller3 } from "react-hook-form";
|
|
274
345
|
function CoercedDateInput(props) {
|
|
275
346
|
const { dateProps, description, disabled, errorMessage, field: field2, label } = props;
|
|
276
347
|
const defaults = useHeroHookFormDefaults();
|
|
277
|
-
return /* @__PURE__ */
|
|
348
|
+
return /* @__PURE__ */ React6.createElement(
|
|
278
349
|
DateInput,
|
|
279
350
|
{
|
|
280
351
|
...defaults.dateInput,
|
|
@@ -302,12 +373,12 @@ function DateField(props) {
|
|
|
302
373
|
rules,
|
|
303
374
|
transform
|
|
304
375
|
} = props;
|
|
305
|
-
return /* @__PURE__ */
|
|
306
|
-
|
|
376
|
+
return /* @__PURE__ */ React6.createElement(
|
|
377
|
+
Controller3,
|
|
307
378
|
{
|
|
308
379
|
control,
|
|
309
380
|
name,
|
|
310
|
-
render: ({ field: field2, fieldState }) => /* @__PURE__ */
|
|
381
|
+
render: ({ field: field2, fieldState }) => /* @__PURE__ */ React6.createElement("div", { className }, /* @__PURE__ */ React6.createElement(
|
|
311
382
|
CoercedDateInput,
|
|
312
383
|
{
|
|
313
384
|
dateProps,
|
|
@@ -327,7 +398,7 @@ function DateField(props) {
|
|
|
327
398
|
}
|
|
328
399
|
|
|
329
400
|
// src/fields/DynamicSectionField.tsx
|
|
330
|
-
import
|
|
401
|
+
import React7 from "react";
|
|
331
402
|
import { useWatch as useWatch2, useFormContext as useFormContext2 } from "react-hook-form";
|
|
332
403
|
function DynamicSectionField({
|
|
333
404
|
className,
|
|
@@ -341,7 +412,7 @@ function DynamicSectionField({
|
|
|
341
412
|
if (!shouldShow) {
|
|
342
413
|
return null;
|
|
343
414
|
}
|
|
344
|
-
return /* @__PURE__ */
|
|
415
|
+
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(
|
|
345
416
|
FormField,
|
|
346
417
|
{
|
|
347
418
|
key: `${fieldConfig.name}-${index}`,
|
|
@@ -358,7 +429,7 @@ function DynamicSectionField({
|
|
|
358
429
|
}
|
|
359
430
|
|
|
360
431
|
// src/fields/FieldArrayField.tsx
|
|
361
|
-
import
|
|
432
|
+
import React8 from "react";
|
|
362
433
|
import { useFieldArray, useFormContext as useFormContext3 } from "react-hook-form";
|
|
363
434
|
import { Button as Button2 } from "@heroui/react";
|
|
364
435
|
function FieldArrayField({
|
|
@@ -406,13 +477,13 @@ function FieldArrayField({
|
|
|
406
477
|
remove(index);
|
|
407
478
|
}
|
|
408
479
|
};
|
|
409
|
-
return /* @__PURE__ */
|
|
480
|
+
return /* @__PURE__ */ React8.createElement("div", { className }, /* @__PURE__ */ React8.createElement("div", { className: "space-y-4" }, fields.map((field2, index) => /* @__PURE__ */ React8.createElement(
|
|
410
481
|
"div",
|
|
411
482
|
{
|
|
412
483
|
key: field2.id,
|
|
413
484
|
className: "border border-gray-200 rounded-lg p-4 space-y-4"
|
|
414
485
|
},
|
|
415
|
-
/* @__PURE__ */
|
|
486
|
+
/* @__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(
|
|
416
487
|
Button2,
|
|
417
488
|
{
|
|
418
489
|
size: "sm",
|
|
@@ -424,7 +495,7 @@ function FieldArrayField({
|
|
|
424
495
|
},
|
|
425
496
|
removeButtonText
|
|
426
497
|
)),
|
|
427
|
-
/* @__PURE__ */
|
|
498
|
+
/* @__PURE__ */ React8.createElement("div", { className: "grid grid-cols-1 md:grid-cols-2 gap-4" }, fieldConfigs.map((fieldConfig) => /* @__PURE__ */ React8.createElement(
|
|
428
499
|
FormField,
|
|
429
500
|
{
|
|
430
501
|
key: `${fieldConfig.name}-${index}`,
|
|
@@ -441,7 +512,7 @@ function FieldArrayField({
|
|
|
441
512
|
}
|
|
442
513
|
}
|
|
443
514
|
)))
|
|
444
|
-
)), canAdd && /* @__PURE__ */
|
|
515
|
+
)), canAdd && /* @__PURE__ */ React8.createElement(
|
|
445
516
|
Button2,
|
|
446
517
|
{
|
|
447
518
|
variant: "bordered",
|
|
@@ -450,7 +521,7 @@ function FieldArrayField({
|
|
|
450
521
|
className: "w-full"
|
|
451
522
|
},
|
|
452
523
|
addButtonText
|
|
453
|
-
), fields.length === 0 && /* @__PURE__ */
|
|
524
|
+
), 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(
|
|
454
525
|
Button2,
|
|
455
526
|
{
|
|
456
527
|
variant: "bordered",
|
|
@@ -463,8 +534,8 @@ function FieldArrayField({
|
|
|
463
534
|
}
|
|
464
535
|
|
|
465
536
|
// src/fields/FileField.tsx
|
|
466
|
-
import
|
|
467
|
-
import { Controller as
|
|
537
|
+
import React9 from "react";
|
|
538
|
+
import { Controller as Controller4 } from "react-hook-form";
|
|
468
539
|
function CoercedFileInput(props) {
|
|
469
540
|
const {
|
|
470
541
|
accept,
|
|
@@ -477,7 +548,7 @@ function CoercedFileInput(props) {
|
|
|
477
548
|
multiple
|
|
478
549
|
} = props;
|
|
479
550
|
const defaults = useHeroHookFormDefaults();
|
|
480
|
-
return /* @__PURE__ */
|
|
551
|
+
return /* @__PURE__ */ React9.createElement(
|
|
481
552
|
Input,
|
|
482
553
|
{
|
|
483
554
|
...defaults.input,
|
|
@@ -513,12 +584,12 @@ function FileField(props) {
|
|
|
513
584
|
rules,
|
|
514
585
|
transform
|
|
515
586
|
} = props;
|
|
516
|
-
return /* @__PURE__ */
|
|
517
|
-
|
|
587
|
+
return /* @__PURE__ */ React9.createElement(
|
|
588
|
+
Controller4,
|
|
518
589
|
{
|
|
519
590
|
control,
|
|
520
591
|
name,
|
|
521
|
-
render: ({ field: field2, fieldState }) => /* @__PURE__ */
|
|
592
|
+
render: ({ field: field2, fieldState }) => /* @__PURE__ */ React9.createElement("div", { className }, /* @__PURE__ */ React9.createElement(
|
|
522
593
|
CoercedFileInput,
|
|
523
594
|
{
|
|
524
595
|
accept,
|
|
@@ -540,8 +611,8 @@ function FileField(props) {
|
|
|
540
611
|
}
|
|
541
612
|
|
|
542
613
|
// src/fields/FontPickerField.tsx
|
|
543
|
-
import
|
|
544
|
-
import { Controller as
|
|
614
|
+
import React10 from "react";
|
|
615
|
+
import { Controller as Controller5 } from "react-hook-form";
|
|
545
616
|
var FontPickerComponent = null;
|
|
546
617
|
var fontPickerLoaded = false;
|
|
547
618
|
var fontPickerLoading = false;
|
|
@@ -557,12 +628,12 @@ function FontPickerField(props) {
|
|
|
557
628
|
name,
|
|
558
629
|
rules
|
|
559
630
|
} = props;
|
|
560
|
-
const [fontPickerState, setFontPickerState] =
|
|
631
|
+
const [fontPickerState, setFontPickerState] = React10.useState({
|
|
561
632
|
component: FontPickerComponent,
|
|
562
633
|
error: null,
|
|
563
634
|
loading: false
|
|
564
635
|
});
|
|
565
|
-
|
|
636
|
+
React10.useEffect(() => {
|
|
566
637
|
if (fontPickerLoaded && FontPickerComponent) {
|
|
567
638
|
setFontPickerState({
|
|
568
639
|
component: FontPickerComponent,
|
|
@@ -620,17 +691,17 @@ function FontPickerField(props) {
|
|
|
620
691
|
void loadFontPicker();
|
|
621
692
|
}, []);
|
|
622
693
|
if (fontPickerState.loading) {
|
|
623
|
-
return /* @__PURE__ */
|
|
694
|
+
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..."))));
|
|
624
695
|
}
|
|
625
696
|
if (!fontPickerState.component) {
|
|
626
|
-
return /* @__PURE__ */
|
|
697
|
+
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."))));
|
|
627
698
|
}
|
|
628
|
-
return /* @__PURE__ */
|
|
629
|
-
|
|
699
|
+
return /* @__PURE__ */ React10.createElement(
|
|
700
|
+
Controller5,
|
|
630
701
|
{
|
|
631
702
|
control,
|
|
632
703
|
name,
|
|
633
|
-
render: ({ field: field2, fieldState }) => /* @__PURE__ */
|
|
704
|
+
render: ({ field: field2, fieldState }) => /* @__PURE__ */ React10.createElement(
|
|
634
705
|
fontPickerState.component,
|
|
635
706
|
{
|
|
636
707
|
label,
|
|
@@ -649,12 +720,12 @@ function FontPickerField(props) {
|
|
|
649
720
|
}
|
|
650
721
|
|
|
651
722
|
// src/fields/InputField.tsx
|
|
652
|
-
import
|
|
653
|
-
import { Controller as
|
|
723
|
+
import React11 from "react";
|
|
724
|
+
import { Controller as Controller6 } from "react-hook-form";
|
|
654
725
|
function CoercedInput(props) {
|
|
655
726
|
const { description, disabled, errorMessage, field: field2, inputProps, label } = props;
|
|
656
727
|
const defaults = useHeroHookFormDefaults();
|
|
657
|
-
return /* @__PURE__ */
|
|
728
|
+
return /* @__PURE__ */ React11.createElement(
|
|
658
729
|
Input,
|
|
659
730
|
{
|
|
660
731
|
...defaults.input,
|
|
@@ -670,7 +741,7 @@ function CoercedInput(props) {
|
|
|
670
741
|
}
|
|
671
742
|
);
|
|
672
743
|
}
|
|
673
|
-
var InputField =
|
|
744
|
+
var InputField = React11.memo(
|
|
674
745
|
(props) => {
|
|
675
746
|
const {
|
|
676
747
|
className,
|
|
@@ -683,12 +754,12 @@ var InputField = React10.memo(
|
|
|
683
754
|
rules,
|
|
684
755
|
transform
|
|
685
756
|
} = props;
|
|
686
|
-
return /* @__PURE__ */
|
|
687
|
-
|
|
757
|
+
return /* @__PURE__ */ React11.createElement(
|
|
758
|
+
Controller6,
|
|
688
759
|
{
|
|
689
760
|
control,
|
|
690
761
|
name,
|
|
691
|
-
render: ({ field: field2, fieldState }) => /* @__PURE__ */
|
|
762
|
+
render: ({ field: field2, fieldState }) => /* @__PURE__ */ React11.createElement("div", { className }, /* @__PURE__ */ React11.createElement(
|
|
692
763
|
CoercedInput,
|
|
693
764
|
{
|
|
694
765
|
description,
|
|
@@ -718,8 +789,8 @@ var InputField = React10.memo(
|
|
|
718
789
|
);
|
|
719
790
|
|
|
720
791
|
// src/fields/RadioGroupField.tsx
|
|
721
|
-
import
|
|
722
|
-
import { Controller as
|
|
792
|
+
import React12 from "react";
|
|
793
|
+
import { Controller as Controller7 } from "react-hook-form";
|
|
723
794
|
function RadioGroupField(props) {
|
|
724
795
|
const {
|
|
725
796
|
className,
|
|
@@ -733,12 +804,12 @@ function RadioGroupField(props) {
|
|
|
733
804
|
rules
|
|
734
805
|
} = props;
|
|
735
806
|
const defaults = useHeroHookFormDefaults();
|
|
736
|
-
return /* @__PURE__ */
|
|
737
|
-
|
|
807
|
+
return /* @__PURE__ */ React12.createElement(
|
|
808
|
+
Controller7,
|
|
738
809
|
{
|
|
739
810
|
control,
|
|
740
811
|
name,
|
|
741
|
-
render: ({ field: field2, fieldState }) => /* @__PURE__ */
|
|
812
|
+
render: ({ field: field2, fieldState }) => /* @__PURE__ */ React12.createElement("div", { className }, /* @__PURE__ */ React12.createElement(
|
|
742
813
|
RadioGroup,
|
|
743
814
|
{
|
|
744
815
|
...defaults.radioGroup,
|
|
@@ -751,7 +822,7 @@ function RadioGroupField(props) {
|
|
|
751
822
|
onBlur: field2.onBlur,
|
|
752
823
|
onValueChange: (val) => field2.onChange(val)
|
|
753
824
|
},
|
|
754
|
-
options.map((opt) => /* @__PURE__ */
|
|
825
|
+
options.map((opt) => /* @__PURE__ */ React12.createElement(
|
|
755
826
|
Radio,
|
|
756
827
|
{
|
|
757
828
|
key: String(opt.value),
|
|
@@ -760,15 +831,15 @@ function RadioGroupField(props) {
|
|
|
760
831
|
},
|
|
761
832
|
opt.label
|
|
762
833
|
))
|
|
763
|
-
), fieldState.error?.message ? /* @__PURE__ */
|
|
834
|
+
), fieldState.error?.message ? /* @__PURE__ */ React12.createElement("p", { className: "text-tiny text-danger mt-1" }, fieldState.error.message) : null),
|
|
764
835
|
rules
|
|
765
836
|
}
|
|
766
837
|
);
|
|
767
838
|
}
|
|
768
839
|
|
|
769
840
|
// src/fields/SelectField.tsx
|
|
770
|
-
import
|
|
771
|
-
import { Controller as
|
|
841
|
+
import React13 from "react";
|
|
842
|
+
import { Controller as Controller8 } from "react-hook-form";
|
|
772
843
|
function SelectField(props) {
|
|
773
844
|
const {
|
|
774
845
|
className,
|
|
@@ -783,14 +854,14 @@ function SelectField(props) {
|
|
|
783
854
|
selectProps
|
|
784
855
|
} = props;
|
|
785
856
|
const defaults = useHeroHookFormDefaults();
|
|
786
|
-
return /* @__PURE__ */
|
|
787
|
-
|
|
857
|
+
return /* @__PURE__ */ React13.createElement(
|
|
858
|
+
Controller8,
|
|
788
859
|
{
|
|
789
860
|
control,
|
|
790
861
|
name,
|
|
791
862
|
render: ({ field: field2, fieldState }) => {
|
|
792
863
|
const selectedKey = field2.value;
|
|
793
|
-
return /* @__PURE__ */
|
|
864
|
+
return /* @__PURE__ */ React13.createElement("div", { className }, /* @__PURE__ */ React13.createElement(
|
|
794
865
|
Select,
|
|
795
866
|
{
|
|
796
867
|
...defaults.select,
|
|
@@ -808,7 +879,7 @@ function SelectField(props) {
|
|
|
808
879
|
field2.onChange(next);
|
|
809
880
|
}
|
|
810
881
|
},
|
|
811
|
-
options.map((opt) => /* @__PURE__ */
|
|
882
|
+
options.map((opt) => /* @__PURE__ */ React13.createElement(
|
|
812
883
|
SelectItem,
|
|
813
884
|
{
|
|
814
885
|
key: String(opt.value),
|
|
@@ -825,12 +896,12 @@ function SelectField(props) {
|
|
|
825
896
|
}
|
|
826
897
|
|
|
827
898
|
// src/fields/SliderField.tsx
|
|
828
|
-
import
|
|
829
|
-
import { Controller as
|
|
899
|
+
import React14 from "react";
|
|
900
|
+
import { Controller as Controller9 } from "react-hook-form";
|
|
830
901
|
function CoercedSlider(props) {
|
|
831
902
|
const { description, disabled, errorMessage, field: field2, label, sliderProps } = props;
|
|
832
903
|
const defaults = useHeroHookFormDefaults();
|
|
833
|
-
return /* @__PURE__ */
|
|
904
|
+
return /* @__PURE__ */ React14.createElement(
|
|
834
905
|
Slider,
|
|
835
906
|
{
|
|
836
907
|
...defaults.slider,
|
|
@@ -858,12 +929,12 @@ function SliderField(props) {
|
|
|
858
929
|
sliderProps,
|
|
859
930
|
transform
|
|
860
931
|
} = props;
|
|
861
|
-
return /* @__PURE__ */
|
|
862
|
-
|
|
932
|
+
return /* @__PURE__ */ React14.createElement(
|
|
933
|
+
Controller9,
|
|
863
934
|
{
|
|
864
935
|
control,
|
|
865
936
|
name,
|
|
866
|
-
render: ({ field: field2, fieldState }) => /* @__PURE__ */
|
|
937
|
+
render: ({ field: field2, fieldState }) => /* @__PURE__ */ React14.createElement("div", { className }, /* @__PURE__ */ React14.createElement(
|
|
867
938
|
CoercedSlider,
|
|
868
939
|
{
|
|
869
940
|
description,
|
|
@@ -883,8 +954,8 @@ function SliderField(props) {
|
|
|
883
954
|
}
|
|
884
955
|
|
|
885
956
|
// src/fields/SwitchField.tsx
|
|
886
|
-
import
|
|
887
|
-
import { Controller as
|
|
957
|
+
import React15 from "react";
|
|
958
|
+
import { Controller as Controller10 } from "react-hook-form";
|
|
888
959
|
function SwitchField(props) {
|
|
889
960
|
const {
|
|
890
961
|
className,
|
|
@@ -897,12 +968,12 @@ function SwitchField(props) {
|
|
|
897
968
|
switchProps
|
|
898
969
|
} = props;
|
|
899
970
|
const defaults = useHeroHookFormDefaults();
|
|
900
|
-
return /* @__PURE__ */
|
|
901
|
-
|
|
971
|
+
return /* @__PURE__ */ React15.createElement(
|
|
972
|
+
Controller10,
|
|
902
973
|
{
|
|
903
974
|
control,
|
|
904
975
|
name,
|
|
905
|
-
render: ({ field: field2, fieldState }) => /* @__PURE__ */
|
|
976
|
+
render: ({ field: field2, fieldState }) => /* @__PURE__ */ React15.createElement("div", { className }, /* @__PURE__ */ React15.createElement(
|
|
906
977
|
Switch,
|
|
907
978
|
{
|
|
908
979
|
...defaults.switch,
|
|
@@ -913,15 +984,15 @@ function SwitchField(props) {
|
|
|
913
984
|
onValueChange: (val) => field2.onChange(val)
|
|
914
985
|
},
|
|
915
986
|
label
|
|
916
|
-
), description ? /* @__PURE__ */
|
|
987
|
+
), 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),
|
|
917
988
|
rules
|
|
918
989
|
}
|
|
919
990
|
);
|
|
920
991
|
}
|
|
921
992
|
|
|
922
993
|
// src/fields/TextareaField.tsx
|
|
923
|
-
import
|
|
924
|
-
import { Controller as
|
|
994
|
+
import React16 from "react";
|
|
995
|
+
import { Controller as Controller11 } from "react-hook-form";
|
|
925
996
|
function TextareaField(props) {
|
|
926
997
|
const {
|
|
927
998
|
className,
|
|
@@ -934,12 +1005,12 @@ function TextareaField(props) {
|
|
|
934
1005
|
textareaProps
|
|
935
1006
|
} = props;
|
|
936
1007
|
const defaults = useHeroHookFormDefaults();
|
|
937
|
-
return /* @__PURE__ */
|
|
938
|
-
|
|
1008
|
+
return /* @__PURE__ */ React16.createElement(
|
|
1009
|
+
Controller11,
|
|
939
1010
|
{
|
|
940
1011
|
control,
|
|
941
1012
|
name,
|
|
942
|
-
render: ({ field: field2, fieldState }) => /* @__PURE__ */
|
|
1013
|
+
render: ({ field: field2, fieldState }) => /* @__PURE__ */ React16.createElement("div", { className }, /* @__PURE__ */ React16.createElement(
|
|
943
1014
|
Textarea,
|
|
944
1015
|
{
|
|
945
1016
|
...defaults.textarea,
|
|
@@ -960,7 +1031,7 @@ function TextareaField(props) {
|
|
|
960
1031
|
}
|
|
961
1032
|
|
|
962
1033
|
// src/components/FormField.tsx
|
|
963
|
-
var FormField =
|
|
1034
|
+
var FormField = React17.memo(
|
|
964
1035
|
({
|
|
965
1036
|
config,
|
|
966
1037
|
form,
|
|
@@ -972,7 +1043,7 @@ var FormField = React16.memo(
|
|
|
972
1043
|
const { control } = form;
|
|
973
1044
|
const watchedValues = useWatch3({ control });
|
|
974
1045
|
if (config.type === "content") {
|
|
975
|
-
return /* @__PURE__ */
|
|
1046
|
+
return /* @__PURE__ */ React17.createElement(
|
|
976
1047
|
ContentField,
|
|
977
1048
|
{
|
|
978
1049
|
config,
|
|
@@ -1002,7 +1073,7 @@ var FormField = React16.memo(
|
|
|
1002
1073
|
};
|
|
1003
1074
|
switch (config.type) {
|
|
1004
1075
|
case "input":
|
|
1005
|
-
return /* @__PURE__ */
|
|
1076
|
+
return /* @__PURE__ */ React17.createElement(
|
|
1006
1077
|
InputField,
|
|
1007
1078
|
{
|
|
1008
1079
|
...baseProps,
|
|
@@ -1012,7 +1083,7 @@ var FormField = React16.memo(
|
|
|
1012
1083
|
}
|
|
1013
1084
|
);
|
|
1014
1085
|
case "textarea":
|
|
1015
|
-
return /* @__PURE__ */
|
|
1086
|
+
return /* @__PURE__ */ React17.createElement(
|
|
1016
1087
|
TextareaField,
|
|
1017
1088
|
{
|
|
1018
1089
|
...baseProps,
|
|
@@ -1022,7 +1093,7 @@ var FormField = React16.memo(
|
|
|
1022
1093
|
}
|
|
1023
1094
|
);
|
|
1024
1095
|
case "select":
|
|
1025
|
-
return /* @__PURE__ */
|
|
1096
|
+
return /* @__PURE__ */ React17.createElement(
|
|
1026
1097
|
SelectField,
|
|
1027
1098
|
{
|
|
1028
1099
|
...baseProps,
|
|
@@ -1035,8 +1106,22 @@ var FormField = React16.memo(
|
|
|
1035
1106
|
selectProps: config.selectProps
|
|
1036
1107
|
}
|
|
1037
1108
|
);
|
|
1109
|
+
case "autocomplete":
|
|
1110
|
+
return /* @__PURE__ */ React17.createElement(
|
|
1111
|
+
AutocompleteField,
|
|
1112
|
+
{
|
|
1113
|
+
...baseProps,
|
|
1114
|
+
control,
|
|
1115
|
+
defaultValue: config.defaultValue,
|
|
1116
|
+
items: (config.options ?? []).map((opt) => ({
|
|
1117
|
+
label: opt.label,
|
|
1118
|
+
value: String(opt.value)
|
|
1119
|
+
})),
|
|
1120
|
+
autocompleteProps: config.autocompleteProps
|
|
1121
|
+
}
|
|
1122
|
+
);
|
|
1038
1123
|
case "checkbox":
|
|
1039
|
-
return /* @__PURE__ */
|
|
1124
|
+
return /* @__PURE__ */ React17.createElement(
|
|
1040
1125
|
CheckboxField,
|
|
1041
1126
|
{
|
|
1042
1127
|
...baseProps,
|
|
@@ -1046,7 +1131,7 @@ var FormField = React16.memo(
|
|
|
1046
1131
|
}
|
|
1047
1132
|
);
|
|
1048
1133
|
case "radio":
|
|
1049
|
-
return /* @__PURE__ */
|
|
1134
|
+
return /* @__PURE__ */ React17.createElement(
|
|
1050
1135
|
RadioGroupField,
|
|
1051
1136
|
{
|
|
1052
1137
|
...baseProps,
|
|
@@ -1060,7 +1145,7 @@ var FormField = React16.memo(
|
|
|
1060
1145
|
}
|
|
1061
1146
|
);
|
|
1062
1147
|
case "switch":
|
|
1063
|
-
return /* @__PURE__ */
|
|
1148
|
+
return /* @__PURE__ */ React17.createElement(
|
|
1064
1149
|
SwitchField,
|
|
1065
1150
|
{
|
|
1066
1151
|
...baseProps,
|
|
@@ -1070,7 +1155,7 @@ var FormField = React16.memo(
|
|
|
1070
1155
|
}
|
|
1071
1156
|
);
|
|
1072
1157
|
case "slider":
|
|
1073
|
-
return /* @__PURE__ */
|
|
1158
|
+
return /* @__PURE__ */ React17.createElement(
|
|
1074
1159
|
SliderField,
|
|
1075
1160
|
{
|
|
1076
1161
|
...baseProps,
|
|
@@ -1080,7 +1165,7 @@ var FormField = React16.memo(
|
|
|
1080
1165
|
}
|
|
1081
1166
|
);
|
|
1082
1167
|
case "date":
|
|
1083
|
-
return /* @__PURE__ */
|
|
1168
|
+
return /* @__PURE__ */ React17.createElement(
|
|
1084
1169
|
DateField,
|
|
1085
1170
|
{
|
|
1086
1171
|
...baseProps,
|
|
@@ -1090,7 +1175,7 @@ var FormField = React16.memo(
|
|
|
1090
1175
|
}
|
|
1091
1176
|
);
|
|
1092
1177
|
case "file":
|
|
1093
|
-
return /* @__PURE__ */
|
|
1178
|
+
return /* @__PURE__ */ React17.createElement(
|
|
1094
1179
|
FileField,
|
|
1095
1180
|
{
|
|
1096
1181
|
...baseProps,
|
|
@@ -1102,7 +1187,7 @@ var FormField = React16.memo(
|
|
|
1102
1187
|
}
|
|
1103
1188
|
);
|
|
1104
1189
|
case "fontPicker":
|
|
1105
|
-
return /* @__PURE__ */
|
|
1190
|
+
return /* @__PURE__ */ React17.createElement(
|
|
1106
1191
|
FontPickerField,
|
|
1107
1192
|
{
|
|
1108
1193
|
...baseProps,
|
|
@@ -1120,7 +1205,7 @@ var FormField = React16.memo(
|
|
|
1120
1205
|
name: config.name
|
|
1121
1206
|
});
|
|
1122
1207
|
case "conditional":
|
|
1123
|
-
return /* @__PURE__ */
|
|
1208
|
+
return /* @__PURE__ */ React17.createElement(
|
|
1124
1209
|
ConditionalField,
|
|
1125
1210
|
{
|
|
1126
1211
|
config,
|
|
@@ -1129,7 +1214,7 @@ var FormField = React16.memo(
|
|
|
1129
1214
|
}
|
|
1130
1215
|
);
|
|
1131
1216
|
case "fieldArray":
|
|
1132
|
-
return /* @__PURE__ */
|
|
1217
|
+
return /* @__PURE__ */ React17.createElement(
|
|
1133
1218
|
FieldArrayField,
|
|
1134
1219
|
{
|
|
1135
1220
|
config,
|
|
@@ -1137,7 +1222,7 @@ var FormField = React16.memo(
|
|
|
1137
1222
|
}
|
|
1138
1223
|
);
|
|
1139
1224
|
case "dynamicSection":
|
|
1140
|
-
return /* @__PURE__ */
|
|
1225
|
+
return /* @__PURE__ */ React17.createElement(
|
|
1141
1226
|
DynamicSectionField,
|
|
1142
1227
|
{
|
|
1143
1228
|
config,
|
|
@@ -1189,12 +1274,12 @@ function ConfigurableForm({
|
|
|
1189
1274
|
});
|
|
1190
1275
|
const renderFields = () => {
|
|
1191
1276
|
if (layout === "grid") {
|
|
1192
|
-
return /* @__PURE__ */
|
|
1277
|
+
return /* @__PURE__ */ React18.createElement(
|
|
1193
1278
|
"div",
|
|
1194
1279
|
{
|
|
1195
1280
|
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"}`
|
|
1196
1281
|
},
|
|
1197
|
-
fields.map((field2) => /* @__PURE__ */
|
|
1282
|
+
fields.map((field2) => /* @__PURE__ */ React18.createElement(
|
|
1198
1283
|
FormField,
|
|
1199
1284
|
{
|
|
1200
1285
|
key: field2.name,
|
|
@@ -1206,7 +1291,7 @@ function ConfigurableForm({
|
|
|
1206
1291
|
);
|
|
1207
1292
|
}
|
|
1208
1293
|
if (layout === "horizontal") {
|
|
1209
|
-
return /* @__PURE__ */
|
|
1294
|
+
return /* @__PURE__ */ React18.createElement("div", { className: `grid gap-${spacing} grid-cols-1 md:grid-cols-2` }, fields.map((field2) => /* @__PURE__ */ React18.createElement(
|
|
1210
1295
|
FormField,
|
|
1211
1296
|
{
|
|
1212
1297
|
key: field2.name,
|
|
@@ -1216,7 +1301,7 @@ function ConfigurableForm({
|
|
|
1216
1301
|
}
|
|
1217
1302
|
)));
|
|
1218
1303
|
}
|
|
1219
|
-
return /* @__PURE__ */
|
|
1304
|
+
return /* @__PURE__ */ React18.createElement("div", { className: `space-y-${spacing}` }, fields.map((field2) => /* @__PURE__ */ React18.createElement(
|
|
1220
1305
|
FormField,
|
|
1221
1306
|
{
|
|
1222
1307
|
key: field2.name,
|
|
@@ -1230,23 +1315,23 @@ function ConfigurableForm({
|
|
|
1230
1315
|
e.preventDefault();
|
|
1231
1316
|
void handleSubmit();
|
|
1232
1317
|
};
|
|
1233
|
-
return /* @__PURE__ */
|
|
1318
|
+
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(
|
|
1234
1319
|
"div",
|
|
1235
1320
|
{
|
|
1236
1321
|
className: "mb-6 p-4 bg-success-50 border border-success-200 rounded-lg",
|
|
1237
1322
|
"data-testid": "success-message"
|
|
1238
1323
|
},
|
|
1239
|
-
/* @__PURE__ */
|
|
1240
|
-
/* @__PURE__ */
|
|
1241
|
-
), error && /* @__PURE__ */
|
|
1324
|
+
/* @__PURE__ */ React18.createElement("p", { className: "text-success-800 font-medium" }, "Success!"),
|
|
1325
|
+
/* @__PURE__ */ React18.createElement("p", { className: "text-success-700 text-sm mt-1" }, "Your request has been processed successfully.")
|
|
1326
|
+
), error && /* @__PURE__ */ React18.createElement(
|
|
1242
1327
|
"div",
|
|
1243
1328
|
{
|
|
1244
1329
|
className: "mb-6 p-4 bg-danger-50 border border-danger-200 rounded-lg",
|
|
1245
1330
|
"data-testid": "error-message"
|
|
1246
1331
|
},
|
|
1247
|
-
/* @__PURE__ */
|
|
1248
|
-
/* @__PURE__ */
|
|
1249
|
-
), renderFields(), /* @__PURE__ */
|
|
1332
|
+
/* @__PURE__ */ React18.createElement("p", { className: "text-danger-800 font-medium" }, "Error"),
|
|
1333
|
+
/* @__PURE__ */ React18.createElement("p", { className: "text-danger-700 text-sm mt-1" }, error)
|
|
1334
|
+
), renderFields(), /* @__PURE__ */ React18.createElement("div", { className: "mt-6 flex gap-3 justify-end" }, /* @__PURE__ */ React18.createElement(
|
|
1250
1335
|
Button3,
|
|
1251
1336
|
{
|
|
1252
1337
|
color: "primary",
|
|
@@ -1256,7 +1341,7 @@ function ConfigurableForm({
|
|
|
1256
1341
|
...submitButtonProps
|
|
1257
1342
|
},
|
|
1258
1343
|
submitButtonText
|
|
1259
|
-
), showResetButton && /* @__PURE__ */
|
|
1344
|
+
), showResetButton && /* @__PURE__ */ React18.createElement(
|
|
1260
1345
|
Button3,
|
|
1261
1346
|
{
|
|
1262
1347
|
isDisabled: isSubmitting,
|
|
@@ -1269,7 +1354,7 @@ function ConfigurableForm({
|
|
|
1269
1354
|
}
|
|
1270
1355
|
|
|
1271
1356
|
// src/components/ServerActionForm.tsx
|
|
1272
|
-
import
|
|
1357
|
+
import React19 from "react";
|
|
1273
1358
|
import { useActionState } from "react";
|
|
1274
1359
|
function ServerActionForm({
|
|
1275
1360
|
action,
|
|
@@ -1294,10 +1379,10 @@ function ServerActionForm({
|
|
|
1294
1379
|
action,
|
|
1295
1380
|
initialState ?? { errors: void 0, message: void 0, success: false }
|
|
1296
1381
|
);
|
|
1297
|
-
const formRef =
|
|
1298
|
-
const [clientErrors, setClientErrors] =
|
|
1299
|
-
const lastSubmittedFormData =
|
|
1300
|
-
|
|
1382
|
+
const formRef = React19.useRef(null);
|
|
1383
|
+
const [clientErrors, setClientErrors] = React19.useState({});
|
|
1384
|
+
const lastSubmittedFormData = React19.useRef(null);
|
|
1385
|
+
React19.useEffect(() => {
|
|
1301
1386
|
if (state && (state.errors || state.message && !state.success)) {
|
|
1302
1387
|
onError?.({
|
|
1303
1388
|
errors: state.errors,
|
|
@@ -1305,7 +1390,7 @@ function ServerActionForm({
|
|
|
1305
1390
|
});
|
|
1306
1391
|
}
|
|
1307
1392
|
}, [state, onError]);
|
|
1308
|
-
|
|
1393
|
+
React19.useEffect(() => {
|
|
1309
1394
|
if (state?.success && lastSubmittedFormData.current) {
|
|
1310
1395
|
onSuccess?.(lastSubmittedFormData.current);
|
|
1311
1396
|
}
|
|
@@ -1348,12 +1433,12 @@ function ServerActionForm({
|
|
|
1348
1433
|
};
|
|
1349
1434
|
const renderFields = () => {
|
|
1350
1435
|
if (layout === "grid") {
|
|
1351
|
-
return /* @__PURE__ */
|
|
1436
|
+
return /* @__PURE__ */ React19.createElement(
|
|
1352
1437
|
"div",
|
|
1353
1438
|
{
|
|
1354
1439
|
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"}`
|
|
1355
1440
|
},
|
|
1356
|
-
fields.map((field2) => /* @__PURE__ */
|
|
1441
|
+
fields.map((field2) => /* @__PURE__ */ React19.createElement(
|
|
1357
1442
|
ServerActionField,
|
|
1358
1443
|
{
|
|
1359
1444
|
key: field2.name,
|
|
@@ -1366,7 +1451,7 @@ function ServerActionForm({
|
|
|
1366
1451
|
);
|
|
1367
1452
|
}
|
|
1368
1453
|
if (layout === "horizontal") {
|
|
1369
|
-
return /* @__PURE__ */
|
|
1454
|
+
return /* @__PURE__ */ React19.createElement("div", { className: `grid gap-${spacing} grid-cols-1 md:grid-cols-2` }, fields.map((field2) => /* @__PURE__ */ React19.createElement(
|
|
1370
1455
|
ServerActionField,
|
|
1371
1456
|
{
|
|
1372
1457
|
key: field2.name,
|
|
@@ -1377,7 +1462,7 @@ function ServerActionForm({
|
|
|
1377
1462
|
}
|
|
1378
1463
|
)));
|
|
1379
1464
|
}
|
|
1380
|
-
return /* @__PURE__ */
|
|
1465
|
+
return /* @__PURE__ */ React19.createElement("div", { className: `space-y-${spacing}` }, fields.map((field2) => /* @__PURE__ */ React19.createElement(
|
|
1381
1466
|
ServerActionField,
|
|
1382
1467
|
{
|
|
1383
1468
|
key: field2.name,
|
|
@@ -1388,7 +1473,7 @@ function ServerActionForm({
|
|
|
1388
1473
|
}
|
|
1389
1474
|
)));
|
|
1390
1475
|
};
|
|
1391
|
-
return /* @__PURE__ */
|
|
1476
|
+
return /* @__PURE__ */ React19.createElement(
|
|
1392
1477
|
"form",
|
|
1393
1478
|
{
|
|
1394
1479
|
ref: formRef,
|
|
@@ -1396,27 +1481,27 @@ function ServerActionForm({
|
|
|
1396
1481
|
role: "form",
|
|
1397
1482
|
onSubmit: handleSubmit
|
|
1398
1483
|
},
|
|
1399
|
-
title && /* @__PURE__ */
|
|
1400
|
-
state?.success && !pending && /* @__PURE__ */
|
|
1484
|
+
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)),
|
|
1485
|
+
state?.success && !pending && /* @__PURE__ */ React19.createElement(
|
|
1401
1486
|
"div",
|
|
1402
1487
|
{
|
|
1403
1488
|
className: "mb-6 p-4 bg-success-50 border border-success-200 rounded-lg",
|
|
1404
1489
|
"data-testid": "success-message"
|
|
1405
1490
|
},
|
|
1406
|
-
/* @__PURE__ */
|
|
1407
|
-
state.message && /* @__PURE__ */
|
|
1491
|
+
/* @__PURE__ */ React19.createElement("p", { className: "text-success-800 font-medium" }, "Success!"),
|
|
1492
|
+
state.message && /* @__PURE__ */ React19.createElement("p", { className: "text-success-700 text-sm mt-1" }, state.message)
|
|
1408
1493
|
),
|
|
1409
|
-
state?.message && !state.success && /* @__PURE__ */
|
|
1494
|
+
state?.message && !state.success && /* @__PURE__ */ React19.createElement(
|
|
1410
1495
|
"div",
|
|
1411
1496
|
{
|
|
1412
1497
|
className: "mb-6 p-4 bg-danger-50 border border-danger-200 rounded-lg",
|
|
1413
1498
|
"data-testid": "error-message"
|
|
1414
1499
|
},
|
|
1415
|
-
/* @__PURE__ */
|
|
1416
|
-
/* @__PURE__ */
|
|
1500
|
+
/* @__PURE__ */ React19.createElement("p", { className: "text-danger-800 font-medium" }, "Error"),
|
|
1501
|
+
/* @__PURE__ */ React19.createElement("p", { className: "text-danger-700 text-sm mt-1" }, state.message)
|
|
1417
1502
|
),
|
|
1418
1503
|
renderFields(),
|
|
1419
|
-
/* @__PURE__ */
|
|
1504
|
+
/* @__PURE__ */ React19.createElement("div", { className: "mt-6 flex gap-3 justify-end" }, /* @__PURE__ */ React19.createElement(
|
|
1420
1505
|
Button,
|
|
1421
1506
|
{
|
|
1422
1507
|
color: "primary",
|
|
@@ -1426,7 +1511,7 @@ function ServerActionForm({
|
|
|
1426
1511
|
...submitButtonProps
|
|
1427
1512
|
},
|
|
1428
1513
|
submitButtonText
|
|
1429
|
-
), showResetButton && /* @__PURE__ */
|
|
1514
|
+
), showResetButton && /* @__PURE__ */ React19.createElement(
|
|
1430
1515
|
Button,
|
|
1431
1516
|
{
|
|
1432
1517
|
isDisabled: pending,
|
|
@@ -1447,13 +1532,13 @@ function ServerActionField({
|
|
|
1447
1532
|
if (field2.type === "content") {
|
|
1448
1533
|
const contentField2 = field2;
|
|
1449
1534
|
if (contentField2.render) {
|
|
1450
|
-
return /* @__PURE__ */
|
|
1535
|
+
return /* @__PURE__ */ React19.createElement("div", { className: contentField2.className }, contentField2.render({
|
|
1451
1536
|
errors: {},
|
|
1452
1537
|
form: null,
|
|
1453
1538
|
isSubmitting: false
|
|
1454
1539
|
}));
|
|
1455
1540
|
}
|
|
1456
|
-
return /* @__PURE__ */
|
|
1541
|
+
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));
|
|
1457
1542
|
}
|
|
1458
1543
|
const fieldName = field2.name;
|
|
1459
1544
|
const fieldErrors = errors?.[fieldName];
|
|
@@ -1481,9 +1566,9 @@ function ServerActionField({
|
|
|
1481
1566
|
}
|
|
1482
1567
|
return false;
|
|
1483
1568
|
};
|
|
1484
|
-
const [value, setValue] =
|
|
1485
|
-
const [checked, setChecked] =
|
|
1486
|
-
|
|
1569
|
+
const [value, setValue] = React19.useState(getDefaultValue);
|
|
1570
|
+
const [checked, setChecked] = React19.useState(getDefaultChecked);
|
|
1571
|
+
React19.useEffect(() => {
|
|
1487
1572
|
const newDefaultValue = defaultValues?.[fieldName];
|
|
1488
1573
|
if (newDefaultValue !== void 0 && newDefaultValue !== null) {
|
|
1489
1574
|
if (field2.type === "checkbox") {
|
|
@@ -1497,7 +1582,7 @@ function ServerActionField({
|
|
|
1497
1582
|
}
|
|
1498
1583
|
}
|
|
1499
1584
|
}, [defaultValues, fieldName, field2.type]);
|
|
1500
|
-
|
|
1585
|
+
React19.useEffect(() => {
|
|
1501
1586
|
const hiddenInput = document.querySelector(
|
|
1502
1587
|
`input[type="hidden"][name="${fieldName}"]`
|
|
1503
1588
|
);
|
|
@@ -1512,7 +1597,7 @@ function ServerActionField({
|
|
|
1512
1597
|
switch (field2.type) {
|
|
1513
1598
|
case "input": {
|
|
1514
1599
|
const inputType = field2.inputProps?.type || "text";
|
|
1515
|
-
return /* @__PURE__ */
|
|
1600
|
+
return /* @__PURE__ */ React19.createElement(React19.Fragment, null, /* @__PURE__ */ React19.createElement("input", { type: "hidden", name: fieldName, value }), /* @__PURE__ */ React19.createElement(
|
|
1516
1601
|
Input,
|
|
1517
1602
|
{
|
|
1518
1603
|
...field2.inputProps,
|
|
@@ -1529,7 +1614,7 @@ function ServerActionField({
|
|
|
1529
1614
|
));
|
|
1530
1615
|
}
|
|
1531
1616
|
case "textarea": {
|
|
1532
|
-
return /* @__PURE__ */
|
|
1617
|
+
return /* @__PURE__ */ React19.createElement(React19.Fragment, null, /* @__PURE__ */ React19.createElement("input", { type: "hidden", name: fieldName, value }), /* @__PURE__ */ React19.createElement(
|
|
1533
1618
|
Textarea,
|
|
1534
1619
|
{
|
|
1535
1620
|
...field2.textareaProps,
|
|
@@ -1545,7 +1630,7 @@ function ServerActionField({
|
|
|
1545
1630
|
));
|
|
1546
1631
|
}
|
|
1547
1632
|
case "checkbox": {
|
|
1548
|
-
return /* @__PURE__ */
|
|
1633
|
+
return /* @__PURE__ */ React19.createElement(React19.Fragment, null, /* @__PURE__ */ React19.createElement("input", { type: "hidden", name: fieldName, value: checked ? "on" : "" }), /* @__PURE__ */ React19.createElement(
|
|
1549
1634
|
Checkbox,
|
|
1550
1635
|
{
|
|
1551
1636
|
...field2.checkboxProps,
|
|
@@ -1561,7 +1646,7 @@ function ServerActionField({
|
|
|
1561
1646
|
}
|
|
1562
1647
|
case "select": {
|
|
1563
1648
|
const options = field2.options || [];
|
|
1564
|
-
return /* @__PURE__ */
|
|
1649
|
+
return /* @__PURE__ */ React19.createElement(React19.Fragment, null, /* @__PURE__ */ React19.createElement("input", { type: "hidden", name: fieldName, value }), /* @__PURE__ */ React19.createElement(
|
|
1565
1650
|
Select,
|
|
1566
1651
|
{
|
|
1567
1652
|
...field2.selectProps,
|
|
@@ -1578,12 +1663,12 @@ function ServerActionField({
|
|
|
1578
1663
|
}
|
|
1579
1664
|
},
|
|
1580
1665
|
options.map(
|
|
1581
|
-
(option) => /* @__PURE__ */
|
|
1666
|
+
(option) => /* @__PURE__ */ React19.createElement(SelectItem, { key: String(option.value) }, option.label)
|
|
1582
1667
|
)
|
|
1583
1668
|
));
|
|
1584
1669
|
}
|
|
1585
1670
|
default:
|
|
1586
|
-
return /* @__PURE__ */
|
|
1671
|
+
return /* @__PURE__ */ React19.createElement(React19.Fragment, null, /* @__PURE__ */ React19.createElement("input", { type: "hidden", name: fieldName, value }), /* @__PURE__ */ React19.createElement(
|
|
1587
1672
|
Input,
|
|
1588
1673
|
{
|
|
1589
1674
|
"data-field-name": fieldName,
|
|
@@ -1613,10 +1698,10 @@ function useHeroForm() {
|
|
|
1613
1698
|
}
|
|
1614
1699
|
|
|
1615
1700
|
// src/providers/FormProvider.tsx
|
|
1616
|
-
import
|
|
1701
|
+
import React20 from "react";
|
|
1617
1702
|
import { FormProvider as RHFProvider } from "react-hook-form";
|
|
1618
1703
|
function FormProvider(props) {
|
|
1619
|
-
return /* @__PURE__ */
|
|
1704
|
+
return /* @__PURE__ */ React20.createElement(RHFProvider, { ...props.methods }, /* @__PURE__ */ React20.createElement(
|
|
1620
1705
|
"form",
|
|
1621
1706
|
{
|
|
1622
1707
|
className: props.className,
|
|
@@ -1629,7 +1714,7 @@ function FormProvider(props) {
|
|
|
1629
1714
|
}
|
|
1630
1715
|
|
|
1631
1716
|
// src/submit/SubmitButton.tsx
|
|
1632
|
-
import
|
|
1717
|
+
import React21 from "react";
|
|
1633
1718
|
function SubmitButton(props) {
|
|
1634
1719
|
const ctx = useFormContext5();
|
|
1635
1720
|
const loading = props.isLoading ?? ctx.formState.isSubmitting;
|
|
@@ -1639,10 +1724,10 @@ function SubmitButton(props) {
|
|
|
1639
1724
|
const defaults = useHeroHookFormDefaults();
|
|
1640
1725
|
const getButtonContent = () => {
|
|
1641
1726
|
if (enhancedState?.isSuccess) {
|
|
1642
|
-
return /* @__PURE__ */
|
|
1727
|
+
return /* @__PURE__ */ React21.createElement("span", { className: "inline-flex items-center gap-2" }, "\u2705", props.successText || "Success!");
|
|
1643
1728
|
}
|
|
1644
1729
|
if (loading) {
|
|
1645
|
-
return /* @__PURE__ */
|
|
1730
|
+
return /* @__PURE__ */ React21.createElement("span", { className: "inline-flex items-center gap-2" }, "\u23F3", props.loadingText || "Submitting...");
|
|
1646
1731
|
}
|
|
1647
1732
|
return props.children;
|
|
1648
1733
|
};
|
|
@@ -1655,7 +1740,7 @@ function SubmitButton(props) {
|
|
|
1655
1740
|
}
|
|
1656
1741
|
return props.buttonProps?.color || defaults.submitButton.color;
|
|
1657
1742
|
};
|
|
1658
|
-
return /* @__PURE__ */
|
|
1743
|
+
return /* @__PURE__ */ React21.createElement(
|
|
1659
1744
|
Button,
|
|
1660
1745
|
{
|
|
1661
1746
|
type: "submit",
|
|
@@ -1896,7 +1981,7 @@ var commonValidations = {
|
|
|
1896
1981
|
import { useFormContext as useFormContext5 } from "react-hook-form";
|
|
1897
1982
|
|
|
1898
1983
|
// src/components/ZodForm.tsx
|
|
1899
|
-
import
|
|
1984
|
+
import React23 from "react";
|
|
1900
1985
|
import { Button as Button5 } from "@heroui/react";
|
|
1901
1986
|
import {
|
|
1902
1987
|
FormProvider as FormProvider2
|
|
@@ -2019,7 +2104,7 @@ function useEnhancedFormState(form, options = {}) {
|
|
|
2019
2104
|
}
|
|
2020
2105
|
|
|
2021
2106
|
// src/components/FormStatus.tsx
|
|
2022
|
-
import
|
|
2107
|
+
import React22 from "react";
|
|
2023
2108
|
import { Button as Button4 } from "@heroui/react";
|
|
2024
2109
|
function FormStatus({
|
|
2025
2110
|
className = "",
|
|
@@ -2032,25 +2117,25 @@ function FormStatus({
|
|
|
2032
2117
|
return null;
|
|
2033
2118
|
}
|
|
2034
2119
|
if (isSubmitting) {
|
|
2035
|
-
return /* @__PURE__ */
|
|
2120
|
+
return /* @__PURE__ */ React22.createElement(
|
|
2036
2121
|
"div",
|
|
2037
2122
|
{
|
|
2038
2123
|
className: `flex items-center gap-3 p-4 bg-blue-50 border border-blue-200 rounded-lg ${className}`
|
|
2039
2124
|
},
|
|
2040
|
-
/* @__PURE__ */
|
|
2041
|
-
/* @__PURE__ */
|
|
2125
|
+
/* @__PURE__ */ React22.createElement("span", { className: "text-blue-600" }, "\u23F3"),
|
|
2126
|
+
/* @__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."))
|
|
2042
2127
|
);
|
|
2043
2128
|
}
|
|
2044
2129
|
if (isSuccess) {
|
|
2045
|
-
return /* @__PURE__ */
|
|
2130
|
+
return /* @__PURE__ */ React22.createElement(
|
|
2046
2131
|
"div",
|
|
2047
2132
|
{
|
|
2048
2133
|
className: `flex items-center gap-3 p-4 bg-green-50 border border-green-200 rounded-lg ${className}`,
|
|
2049
2134
|
"data-testid": "success-message"
|
|
2050
2135
|
},
|
|
2051
|
-
/* @__PURE__ */
|
|
2052
|
-
/* @__PURE__ */
|
|
2053
|
-
onDismiss && /* @__PURE__ */
|
|
2136
|
+
/* @__PURE__ */ React22.createElement("span", { className: "text-green-600" }, "\u2705"),
|
|
2137
|
+
/* @__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.")),
|
|
2138
|
+
onDismiss && /* @__PURE__ */ React22.createElement(
|
|
2054
2139
|
Button4,
|
|
2055
2140
|
{
|
|
2056
2141
|
size: "sm",
|
|
@@ -2064,15 +2149,15 @@ function FormStatus({
|
|
|
2064
2149
|
);
|
|
2065
2150
|
}
|
|
2066
2151
|
if (isError && error) {
|
|
2067
|
-
return /* @__PURE__ */
|
|
2152
|
+
return /* @__PURE__ */ React22.createElement(
|
|
2068
2153
|
"div",
|
|
2069
2154
|
{
|
|
2070
2155
|
className: `flex items-center gap-3 p-4 bg-red-50 border border-red-200 rounded-lg ${className}`,
|
|
2071
2156
|
"data-testid": "error-message"
|
|
2072
2157
|
},
|
|
2073
|
-
/* @__PURE__ */
|
|
2074
|
-
/* @__PURE__ */
|
|
2075
|
-
onDismiss && /* @__PURE__ */
|
|
2158
|
+
/* @__PURE__ */ React22.createElement("span", { className: "text-red-600" }, "\u26A0\uFE0F"),
|
|
2159
|
+
/* @__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)),
|
|
2160
|
+
onDismiss && /* @__PURE__ */ React22.createElement(
|
|
2076
2161
|
Button4,
|
|
2077
2162
|
{
|
|
2078
2163
|
size: "sm",
|
|
@@ -2093,8 +2178,8 @@ function FormToast({
|
|
|
2093
2178
|
position = "top-right",
|
|
2094
2179
|
state
|
|
2095
2180
|
}) {
|
|
2096
|
-
const [isVisible, setIsVisible] =
|
|
2097
|
-
|
|
2181
|
+
const [isVisible, setIsVisible] = React22.useState(false);
|
|
2182
|
+
React22.useEffect(() => {
|
|
2098
2183
|
if (state.isSuccess || state.isError) {
|
|
2099
2184
|
setIsVisible(true);
|
|
2100
2185
|
if (duration > 0) {
|
|
@@ -2115,7 +2200,7 @@ function FormToast({
|
|
|
2115
2200
|
"top-left": "top-4 left-4",
|
|
2116
2201
|
"top-right": "top-4 right-4"
|
|
2117
2202
|
};
|
|
2118
|
-
return /* @__PURE__ */
|
|
2203
|
+
return /* @__PURE__ */ React22.createElement("div", { className: `fixed z-50 ${positionClasses[position]}` }, /* @__PURE__ */ React22.createElement(FormStatus, { state, onDismiss }));
|
|
2119
2204
|
}
|
|
2120
2205
|
|
|
2121
2206
|
// src/components/ZodForm.tsx
|
|
@@ -2165,12 +2250,12 @@ function ZodForm({
|
|
|
2165
2250
|
};
|
|
2166
2251
|
const renderFields = () => {
|
|
2167
2252
|
if (layout === "grid") {
|
|
2168
|
-
return /* @__PURE__ */
|
|
2253
|
+
return /* @__PURE__ */ React23.createElement(
|
|
2169
2254
|
"div",
|
|
2170
2255
|
{
|
|
2171
2256
|
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"}`
|
|
2172
2257
|
},
|
|
2173
|
-
config.fields.map((field2) => /* @__PURE__ */
|
|
2258
|
+
config.fields.map((field2) => /* @__PURE__ */ React23.createElement(
|
|
2174
2259
|
FormField,
|
|
2175
2260
|
{
|
|
2176
2261
|
key: field2.name,
|
|
@@ -2187,7 +2272,7 @@ function ZodForm({
|
|
|
2187
2272
|
);
|
|
2188
2273
|
}
|
|
2189
2274
|
if (layout === "horizontal") {
|
|
2190
|
-
return /* @__PURE__ */
|
|
2275
|
+
return /* @__PURE__ */ React23.createElement("div", { className: `grid gap-${spacing} grid-cols-1 md:grid-cols-2` }, config.fields.map((field2) => /* @__PURE__ */ React23.createElement(
|
|
2191
2276
|
FormField,
|
|
2192
2277
|
{
|
|
2193
2278
|
key: field2.name,
|
|
@@ -2202,7 +2287,7 @@ function ZodForm({
|
|
|
2202
2287
|
}
|
|
2203
2288
|
)));
|
|
2204
2289
|
}
|
|
2205
|
-
return /* @__PURE__ */
|
|
2290
|
+
return /* @__PURE__ */ React23.createElement("div", { className: `space-y-${spacing}` }, config.fields.map((field2) => /* @__PURE__ */ React23.createElement(
|
|
2206
2291
|
FormField,
|
|
2207
2292
|
{
|
|
2208
2293
|
key: field2.name,
|
|
@@ -2221,19 +2306,19 @@ function ZodForm({
|
|
|
2221
2306
|
e.preventDefault();
|
|
2222
2307
|
void handleSubmit();
|
|
2223
2308
|
};
|
|
2224
|
-
|
|
2309
|
+
React23.useEffect(() => {
|
|
2225
2310
|
if (config.onError && Object.keys(form.formState.errors).length > 0) {
|
|
2226
2311
|
config.onError(form.formState.errors);
|
|
2227
2312
|
}
|
|
2228
2313
|
}, [form.formState.errors, config.onError]);
|
|
2229
|
-
return /* @__PURE__ */
|
|
2314
|
+
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(
|
|
2230
2315
|
FormStatus,
|
|
2231
2316
|
{
|
|
2232
2317
|
state: enhancedState,
|
|
2233
2318
|
onDismiss: () => enhancedState.reset(),
|
|
2234
2319
|
showDetails: true
|
|
2235
2320
|
}
|
|
2236
|
-
), renderFields(), /* @__PURE__ */
|
|
2321
|
+
), renderFields(), /* @__PURE__ */ React23.createElement("div", { className: "mt-6 flex gap-3 justify-end" }, /* @__PURE__ */ React23.createElement(
|
|
2237
2322
|
Button5,
|
|
2238
2323
|
{
|
|
2239
2324
|
color: "primary",
|
|
@@ -2243,7 +2328,7 @@ function ZodForm({
|
|
|
2243
2328
|
...submitButtonProps
|
|
2244
2329
|
},
|
|
2245
2330
|
enhancedState.isSuccess ? "Success!" : submitButtonText
|
|
2246
|
-
), showResetButton && /* @__PURE__ */
|
|
2331
|
+
), showResetButton && /* @__PURE__ */ React23.createElement(
|
|
2247
2332
|
Button5,
|
|
2248
2333
|
{
|
|
2249
2334
|
isDisabled: enhancedState.isSubmitting,
|
|
@@ -2296,6 +2381,19 @@ var BasicFormBuilder = class {
|
|
|
2296
2381
|
});
|
|
2297
2382
|
return this;
|
|
2298
2383
|
}
|
|
2384
|
+
/**
|
|
2385
|
+
* Add an autocomplete field
|
|
2386
|
+
*/
|
|
2387
|
+
autocomplete(name, label, items, placeholder) {
|
|
2388
|
+
this.fields.push({
|
|
2389
|
+
autocompleteProps: placeholder ? { placeholder } : void 0,
|
|
2390
|
+
label,
|
|
2391
|
+
name,
|
|
2392
|
+
options: items,
|
|
2393
|
+
type: "autocomplete"
|
|
2394
|
+
});
|
|
2395
|
+
return this;
|
|
2396
|
+
}
|
|
2299
2397
|
/**
|
|
2300
2398
|
* Add a checkbox field
|
|
2301
2399
|
*/
|
|
@@ -2324,8 +2422,9 @@ var BasicFormBuilder = class {
|
|
|
2324
2422
|
/**
|
|
2325
2423
|
* Add a switch field
|
|
2326
2424
|
*/
|
|
2327
|
-
switch(name, label) {
|
|
2425
|
+
switch(name, label, description) {
|
|
2328
2426
|
this.fields.push({
|
|
2427
|
+
description,
|
|
2329
2428
|
label,
|
|
2330
2429
|
name,
|
|
2331
2430
|
type: "switch"
|
|
@@ -2343,6 +2442,16 @@ function createBasicFormBuilder() {
|
|
|
2343
2442
|
return new BasicFormBuilder();
|
|
2344
2443
|
}
|
|
2345
2444
|
var FormFieldHelpers = {
|
|
2445
|
+
/**
|
|
2446
|
+
* Create an autocomplete field
|
|
2447
|
+
*/
|
|
2448
|
+
autocomplete: (name, label, items, placeholder) => ({
|
|
2449
|
+
autocompleteProps: placeholder ? { placeholder } : void 0,
|
|
2450
|
+
label,
|
|
2451
|
+
name,
|
|
2452
|
+
options: items,
|
|
2453
|
+
type: "autocomplete"
|
|
2454
|
+
}),
|
|
2346
2455
|
/**
|
|
2347
2456
|
* Create a checkbox field
|
|
2348
2457
|
*/
|
|
@@ -2351,6 +2460,37 @@ var FormFieldHelpers = {
|
|
|
2351
2460
|
name,
|
|
2352
2461
|
type: "checkbox"
|
|
2353
2462
|
}),
|
|
2463
|
+
/**
|
|
2464
|
+
* Create a conditional field that shows/hides based on form data
|
|
2465
|
+
*
|
|
2466
|
+
* @example
|
|
2467
|
+
* ```tsx
|
|
2468
|
+
* FormFieldHelpers.conditional(
|
|
2469
|
+
* "phone",
|
|
2470
|
+
* (values) => values.hasPhone === true,
|
|
2471
|
+
* FormFieldHelpers.input("phone", "Phone Number", "tel")
|
|
2472
|
+
* )
|
|
2473
|
+
* ```
|
|
2474
|
+
*
|
|
2475
|
+
* @example
|
|
2476
|
+
* With explicit type in condition function (similar to content helper pattern):
|
|
2477
|
+
* ```tsx
|
|
2478
|
+
* FormFieldHelpers.conditional(
|
|
2479
|
+
* "options",
|
|
2480
|
+
* (formData: Partial<z.infer<typeof fieldSchema>>) =>
|
|
2481
|
+
* formData.fieldType === 'DROPDOWN',
|
|
2482
|
+
* FormFieldHelpers.textarea("options", "Dropdown Options", "One per line")
|
|
2483
|
+
* )
|
|
2484
|
+
* ```
|
|
2485
|
+
*/
|
|
2486
|
+
conditional: (name, condition, field2) => {
|
|
2487
|
+
return {
|
|
2488
|
+
condition,
|
|
2489
|
+
field: field2,
|
|
2490
|
+
name,
|
|
2491
|
+
type: "conditional"
|
|
2492
|
+
};
|
|
2493
|
+
},
|
|
2354
2494
|
/**
|
|
2355
2495
|
* Create a content field for headers, questions, or custom content between fields
|
|
2356
2496
|
*
|
|
@@ -2405,7 +2545,8 @@ var FormFieldHelpers = {
|
|
|
2405
2545
|
/**
|
|
2406
2546
|
* Create a switch field
|
|
2407
2547
|
*/
|
|
2408
|
-
switch: (name, label) => ({
|
|
2548
|
+
switch: (name, label, description) => ({
|
|
2549
|
+
description,
|
|
2409
2550
|
label,
|
|
2410
2551
|
name,
|
|
2411
2552
|
type: "switch"
|
|
@@ -2523,13 +2664,14 @@ function checkboxField(name, label, props) {
|
|
|
2523
2664
|
}
|
|
2524
2665
|
function switchField(name, label, props) {
|
|
2525
2666
|
return {
|
|
2667
|
+
description: props?.description,
|
|
2668
|
+
isDisabled: props?.isDisabled,
|
|
2526
2669
|
label,
|
|
2527
2670
|
name,
|
|
2528
2671
|
type: "switch",
|
|
2529
|
-
...props && {
|
|
2672
|
+
...props?.className && {
|
|
2530
2673
|
switchProps: {
|
|
2531
|
-
className: props.className
|
|
2532
|
-
disabled: props.isDisabled
|
|
2674
|
+
className: props.className
|
|
2533
2675
|
}
|
|
2534
2676
|
}
|
|
2535
2677
|
};
|
|
@@ -3540,6 +3682,7 @@ var validationUtils = {
|
|
|
3540
3682
|
};
|
|
3541
3683
|
export {
|
|
3542
3684
|
AdvancedFieldBuilder,
|
|
3685
|
+
AutocompleteField,
|
|
3543
3686
|
BasicFormBuilder,
|
|
3544
3687
|
CheckboxField,
|
|
3545
3688
|
CommonFields,
|