@page-speed/forms 0.5.0 → 0.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/README.md +1 -2
- package/dist/core.cjs +164 -83
- package/dist/core.cjs.map +1 -1
- package/dist/core.js +150 -69
- package/dist/core.js.map +1 -1
- package/dist/index.cjs +164 -83
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +6 -1
- package/dist/index.d.ts +6 -1
- package/dist/index.js +150 -69
- package/dist/index.js.map +1 -1
- package/dist/inputs.cjs +2720 -1371
- package/dist/inputs.cjs.map +1 -1
- package/dist/inputs.d.cts +9 -258
- package/dist/inputs.d.ts +9 -258
- package/dist/inputs.js +2721 -1371
- package/dist/inputs.js.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -123,7 +123,6 @@ Exports:
|
|
|
123
123
|
- `DatePicker`
|
|
124
124
|
- `DateRangePicker`
|
|
125
125
|
- `TimePicker`
|
|
126
|
-
- `RichTextEditor`
|
|
127
126
|
- `FileInput`
|
|
128
127
|
|
|
129
128
|
### Validation
|
|
@@ -154,7 +153,7 @@ Exports:
|
|
|
154
153
|
- Close on outside click
|
|
155
154
|
- Search support
|
|
156
155
|
- Option groups
|
|
157
|
-
- Selected options inside the menu use
|
|
156
|
+
- Selected options inside the menu use accent highlight styles
|
|
158
157
|
|
|
159
158
|
## Styling (Tailwind 4 + Semantic Tokens)
|
|
160
159
|
|
package/dist/core.cjs
CHANGED
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var
|
|
3
|
+
var React4 = require('react');
|
|
4
4
|
var react = require('@legendapp/state/react');
|
|
5
5
|
var useMap = require('@opensite/hooks/useMap');
|
|
6
6
|
var clsx = require('clsx');
|
|
7
7
|
var tailwindMerge = require('tailwind-merge');
|
|
8
|
+
var classVarianceAuthority = require('class-variance-authority');
|
|
9
|
+
var radixUi = require('radix-ui');
|
|
8
10
|
|
|
9
11
|
function _interopNamespace(e) {
|
|
10
12
|
if (e && e.__esModule) return e;
|
|
@@ -24,7 +26,7 @@ function _interopNamespace(e) {
|
|
|
24
26
|
return Object.freeze(n);
|
|
25
27
|
}
|
|
26
28
|
|
|
27
|
-
var
|
|
29
|
+
var React4__namespace = /*#__PURE__*/_interopNamespace(React4);
|
|
28
30
|
|
|
29
31
|
// src/core/useForm.ts
|
|
30
32
|
function useForm(options) {
|
|
@@ -47,9 +49,9 @@ function useForm(options) {
|
|
|
47
49
|
// Create a copy to prevent reference sharing
|
|
48
50
|
hasValidated: {}
|
|
49
51
|
});
|
|
50
|
-
const validationInProgress =
|
|
52
|
+
const validationInProgress = React4.useRef(/* @__PURE__ */ new Set());
|
|
51
53
|
const [, fieldMetadataActions] = useMap.useMap();
|
|
52
|
-
const validateField =
|
|
54
|
+
const validateField = React4.useCallback(
|
|
53
55
|
async (field) => {
|
|
54
56
|
const validators = validationSchema?.[field];
|
|
55
57
|
if (!validators) return void 0;
|
|
@@ -86,7 +88,7 @@ function useForm(options) {
|
|
|
86
88
|
},
|
|
87
89
|
[validationSchema, state$, fieldMetadataActions]
|
|
88
90
|
);
|
|
89
|
-
const validateForm =
|
|
91
|
+
const validateForm = React4.useCallback(async () => {
|
|
90
92
|
if (!validationSchema) return {};
|
|
91
93
|
const fields = Object.keys(validationSchema);
|
|
92
94
|
const errors2 = {};
|
|
@@ -101,7 +103,7 @@ function useForm(options) {
|
|
|
101
103
|
state$.errors.set(errors2);
|
|
102
104
|
return errors2;
|
|
103
105
|
}, [validationSchema, validateField, state$]);
|
|
104
|
-
const setFieldValue =
|
|
106
|
+
const setFieldValue = React4.useCallback(
|
|
105
107
|
(field, value) => {
|
|
106
108
|
state$.values[field].set(value);
|
|
107
109
|
const shouldRevalidate = revalidateOn === "onChange" && state$.hasValidated[String(field)].get();
|
|
@@ -114,7 +116,7 @@ function useForm(options) {
|
|
|
114
116
|
},
|
|
115
117
|
[state$, revalidateOn, validationSchema, validateField, debug]
|
|
116
118
|
);
|
|
117
|
-
const setFieldTouched =
|
|
119
|
+
const setFieldTouched = React4.useCallback(
|
|
118
120
|
(field, touched2) => {
|
|
119
121
|
state$.touched[field].set(touched2);
|
|
120
122
|
if (touched2 && validateOn === "onBlur" && validationSchema?.[field]) {
|
|
@@ -127,7 +129,7 @@ function useForm(options) {
|
|
|
127
129
|
},
|
|
128
130
|
[state$, validateOn, validationSchema, validateField, debug]
|
|
129
131
|
);
|
|
130
|
-
const resetForm =
|
|
132
|
+
const resetForm = React4.useCallback(() => {
|
|
131
133
|
state$.values.set(state$.initialValues.get());
|
|
132
134
|
state$.errors.set({});
|
|
133
135
|
state$.touched.set({});
|
|
@@ -139,7 +141,7 @@ function useForm(options) {
|
|
|
139
141
|
console.log("[useForm] Form reset");
|
|
140
142
|
}
|
|
141
143
|
}, [state$, fieldMetadataActions, debug]);
|
|
142
|
-
const handleSubmit =
|
|
144
|
+
const handleSubmit = React4.useCallback(
|
|
143
145
|
async (e) => {
|
|
144
146
|
e?.preventDefault();
|
|
145
147
|
if (debug) {
|
|
@@ -200,7 +202,7 @@ function useForm(options) {
|
|
|
200
202
|
debug
|
|
201
203
|
]
|
|
202
204
|
);
|
|
203
|
-
const getFieldProps =
|
|
205
|
+
const getFieldProps = React4.useCallback(
|
|
204
206
|
(field) => {
|
|
205
207
|
return {
|
|
206
208
|
name: String(field),
|
|
@@ -211,7 +213,7 @@ function useForm(options) {
|
|
|
211
213
|
},
|
|
212
214
|
[state$, setFieldValue, setFieldTouched]
|
|
213
215
|
);
|
|
214
|
-
const getFieldMeta =
|
|
216
|
+
const getFieldMeta = React4.useCallback(
|
|
215
217
|
(field) => {
|
|
216
218
|
const fieldKey = String(field);
|
|
217
219
|
const metadata = fieldMetadataActions.get(fieldKey);
|
|
@@ -270,13 +272,13 @@ function useForm(options) {
|
|
|
270
272
|
getFieldMeta
|
|
271
273
|
};
|
|
272
274
|
}
|
|
273
|
-
var FormContext =
|
|
275
|
+
var FormContext = React4__namespace.createContext(null);
|
|
274
276
|
FormContext.displayName = "FormContext";
|
|
275
277
|
|
|
276
278
|
// src/core/useField.ts
|
|
277
279
|
function useField(options) {
|
|
278
280
|
const { name, validate, transform } = options;
|
|
279
|
-
const form =
|
|
281
|
+
const form = React4.useContext(FormContext);
|
|
280
282
|
if (!form) {
|
|
281
283
|
throw new Error(
|
|
282
284
|
"useField must be used within a FormContext. Wrap your component with <Form> or use useForm's getFieldProps instead."
|
|
@@ -305,20 +307,20 @@ function useField(options) {
|
|
|
305
307
|
};
|
|
306
308
|
const meta = form.getFieldMeta(name);
|
|
307
309
|
const helpers = {
|
|
308
|
-
setValue:
|
|
310
|
+
setValue: React4.useCallback(
|
|
309
311
|
(value) => {
|
|
310
312
|
const transformedValue = transform ? transform(value) : value;
|
|
311
313
|
form.setFieldValue(name, transformedValue);
|
|
312
314
|
},
|
|
313
315
|
[name, transform, form]
|
|
314
316
|
),
|
|
315
|
-
setTouched:
|
|
317
|
+
setTouched: React4.useCallback(
|
|
316
318
|
(touched) => {
|
|
317
319
|
form.setFieldTouched(name, touched);
|
|
318
320
|
},
|
|
319
321
|
[name, form]
|
|
320
322
|
),
|
|
321
|
-
setError:
|
|
323
|
+
setError: React4.useCallback(
|
|
322
324
|
(error) => {
|
|
323
325
|
form.setFieldError(name, error);
|
|
324
326
|
},
|
|
@@ -338,7 +340,7 @@ function cn(...inputs) {
|
|
|
338
340
|
// src/core/form-feedback.tsx
|
|
339
341
|
function renderMessage(message, fallbackClassName, className) {
|
|
340
342
|
if (typeof message === "string") {
|
|
341
|
-
return /* @__PURE__ */
|
|
343
|
+
return /* @__PURE__ */ React4__namespace.createElement(
|
|
342
344
|
"p",
|
|
343
345
|
{
|
|
344
346
|
className: cn(
|
|
@@ -349,7 +351,7 @@ function renderMessage(message, fallbackClassName, className) {
|
|
|
349
351
|
message
|
|
350
352
|
);
|
|
351
353
|
}
|
|
352
|
-
return /* @__PURE__ */
|
|
354
|
+
return /* @__PURE__ */ React4__namespace.createElement("div", { className: cn(fallbackClassName, className) }, message);
|
|
353
355
|
}
|
|
354
356
|
function FormFeedback({
|
|
355
357
|
successMessage,
|
|
@@ -360,7 +362,7 @@ function FormFeedback({
|
|
|
360
362
|
if (!successMessage && !submissionError) {
|
|
361
363
|
return null;
|
|
362
364
|
}
|
|
363
|
-
return /* @__PURE__ */
|
|
365
|
+
return /* @__PURE__ */ React4__namespace.createElement(React4__namespace.Fragment, null, successMessage ? /* @__PURE__ */ React4__namespace.createElement(
|
|
364
366
|
"div",
|
|
365
367
|
{
|
|
366
368
|
className: cn(
|
|
@@ -375,7 +377,7 @@ function FormFeedback({
|
|
|
375
377
|
"text-primary-foreground",
|
|
376
378
|
"text-primary-foreground"
|
|
377
379
|
)
|
|
378
|
-
) : null, submissionError ? /* @__PURE__ */
|
|
380
|
+
) : null, submissionError ? /* @__PURE__ */ React4__namespace.createElement(
|
|
379
381
|
"div",
|
|
380
382
|
{
|
|
381
383
|
className: cn(
|
|
@@ -393,6 +395,54 @@ function FormFeedback({
|
|
|
393
395
|
) : null);
|
|
394
396
|
}
|
|
395
397
|
FormFeedback.displayName = "FormFeedback";
|
|
398
|
+
var buttonVariants = classVarianceAuthority.cva(
|
|
399
|
+
"inline-flex items-center justify-center gap-2 whitespace-nowrap rounded-md text-sm font-medium transition-all disabled:pointer-events-none disabled:opacity-50 [&_svg]:pointer-events-none [&_svg:not([class*='size-'])]:size-4 shrink-0 [&_svg]:shrink-0 outline-none focus-visible:border-ring focus-visible:ring-ring/50 focus-visible:ring-[3px] aria-invalid:ring-destructive/20 aria-invalid:border-destructive",
|
|
400
|
+
{
|
|
401
|
+
variants: {
|
|
402
|
+
variant: {
|
|
403
|
+
default: "bg-primary text-primary-foreground hover:bg-primary/90",
|
|
404
|
+
destructive: "bg-destructive text-white hover:bg-destructive/90 focus-visible:ring-destructive/20",
|
|
405
|
+
outline: "border border-input bg-transparent shadow-xs hover:bg-accent hover:text-accent-foreground",
|
|
406
|
+
secondary: "bg-secondary text-secondary-foreground hover:bg-secondary/80",
|
|
407
|
+
ghost: "hover:bg-accent hover:text-accent-foreground",
|
|
408
|
+
link: "text-primary underline-offset-4 hover:underline"
|
|
409
|
+
},
|
|
410
|
+
size: {
|
|
411
|
+
default: "h-9 px-4 py-2 has-[>svg]:px-3",
|
|
412
|
+
xs: "h-6 gap-1 rounded-md px-2 text-xs has-[>svg]:px-1.5 [&_svg:not([class*='size-'])]:size-3",
|
|
413
|
+
sm: "h-8 rounded-md gap-1.5 px-3 has-[>svg]:px-2.5",
|
|
414
|
+
lg: "h-10 rounded-md px-6 has-[>svg]:px-4",
|
|
415
|
+
icon: "size-9",
|
|
416
|
+
"icon-xs": "size-6 rounded-md [&_svg:not([class*='size-'])]:size-3",
|
|
417
|
+
"icon-sm": "size-8",
|
|
418
|
+
"icon-lg": "size-10"
|
|
419
|
+
}
|
|
420
|
+
},
|
|
421
|
+
defaultVariants: {
|
|
422
|
+
variant: "default",
|
|
423
|
+
size: "default"
|
|
424
|
+
}
|
|
425
|
+
}
|
|
426
|
+
);
|
|
427
|
+
function Button({
|
|
428
|
+
className,
|
|
429
|
+
variant = "default",
|
|
430
|
+
size = "default",
|
|
431
|
+
asChild = false,
|
|
432
|
+
...props
|
|
433
|
+
}) {
|
|
434
|
+
const Comp = asChild ? radixUi.Slot.Root : "button";
|
|
435
|
+
return /* @__PURE__ */ React4__namespace.createElement(
|
|
436
|
+
Comp,
|
|
437
|
+
{
|
|
438
|
+
"data-slot": "button",
|
|
439
|
+
"data-variant": variant,
|
|
440
|
+
"data-size": size,
|
|
441
|
+
className: cn(buttonVariants({ variant, size, className })),
|
|
442
|
+
...props
|
|
443
|
+
}
|
|
444
|
+
);
|
|
445
|
+
}
|
|
396
446
|
|
|
397
447
|
// src/core/Form.tsx
|
|
398
448
|
function Form({
|
|
@@ -410,7 +460,7 @@ function Form({
|
|
|
410
460
|
onNewSubmission,
|
|
411
461
|
...props
|
|
412
462
|
}) {
|
|
413
|
-
const handleFormSubmit =
|
|
463
|
+
const handleFormSubmit = React4__namespace.useCallback(
|
|
414
464
|
async (e) => {
|
|
415
465
|
try {
|
|
416
466
|
await form.handleSubmit(e);
|
|
@@ -429,11 +479,11 @@ function Form({
|
|
|
429
479
|
const newSubmissionAction = submissionConfig?.newFormSubmissionAction;
|
|
430
480
|
const showNewSubmissionAction = isSubmissionSuccessful && (typeof newSubmissionAction?.enable === "boolean" ? newSubmissionAction.enable : Boolean(newSubmissionAction?.label));
|
|
431
481
|
const newSubmissionLabel = newSubmissionAction?.label ?? "Submit another response";
|
|
432
|
-
const handleNewSubmission =
|
|
482
|
+
const handleNewSubmission = React4__namespace.useCallback(() => {
|
|
433
483
|
form.resetForm();
|
|
434
484
|
onNewSubmission?.();
|
|
435
485
|
}, [form, onNewSubmission]);
|
|
436
|
-
return /* @__PURE__ */
|
|
486
|
+
return /* @__PURE__ */ React4__namespace.createElement(FormContext.Provider, { value: form }, /* @__PURE__ */ React4__namespace.createElement(
|
|
437
487
|
"form",
|
|
438
488
|
{
|
|
439
489
|
onSubmit: handleFormSubmit,
|
|
@@ -443,24 +493,21 @@ function Form({
|
|
|
443
493
|
className,
|
|
444
494
|
...props
|
|
445
495
|
},
|
|
446
|
-
isSubmissionSuccessful ? /* @__PURE__ */
|
|
496
|
+
isSubmissionSuccessful ? /* @__PURE__ */ React4__namespace.createElement("div", { className: "space-y-4" }, shouldRenderCustomComponent ? submissionConfig?.customComponent : /* @__PURE__ */ React4__namespace.createElement(
|
|
447
497
|
FormFeedback,
|
|
448
498
|
{
|
|
449
499
|
successMessage: resolvedSuccessMessage,
|
|
450
500
|
successMessageClassName
|
|
451
501
|
}
|
|
452
|
-
), showNewSubmissionAction ? /* @__PURE__ */
|
|
453
|
-
|
|
502
|
+
), showNewSubmissionAction ? /* @__PURE__ */ React4__namespace.createElement(
|
|
503
|
+
Button,
|
|
454
504
|
{
|
|
455
505
|
type: "button",
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
"inline-flex items-center justify-center whitespace-nowrap rounded-md border border-input bg-transparent px-4 py-2 text-sm font-medium shadow-sm transition-colors",
|
|
459
|
-
"hover:bg-muted focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring"
|
|
460
|
-
)
|
|
506
|
+
variant: "outline",
|
|
507
|
+
onClick: handleNewSubmission
|
|
461
508
|
},
|
|
462
509
|
newSubmissionLabel
|
|
463
|
-
) : null) : /* @__PURE__ */
|
|
510
|
+
) : null) : /* @__PURE__ */ React4__namespace.createElement(React4__namespace.Fragment, null, children, submissionError ? /* @__PURE__ */ React4__namespace.createElement("div", { className: "mt-4" }, /* @__PURE__ */ React4__namespace.createElement(
|
|
464
511
|
FormFeedback,
|
|
465
512
|
{
|
|
466
513
|
submissionError,
|
|
@@ -470,20 +517,46 @@ function Form({
|
|
|
470
517
|
));
|
|
471
518
|
}
|
|
472
519
|
Form.displayName = "Form";
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
520
|
+
function Label({
|
|
521
|
+
className,
|
|
522
|
+
...props
|
|
523
|
+
}) {
|
|
524
|
+
return /* @__PURE__ */ React4__namespace.createElement(
|
|
525
|
+
radixUi.Label.Root,
|
|
476
526
|
{
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
527
|
+
"data-slot": "label",
|
|
528
|
+
className: cn(
|
|
529
|
+
"flex items-center gap-2 text-sm leading-none font-medium select-none group-data-[disabled=true]:pointer-events-none group-data-[disabled=true]:opacity-50 peer-disabled:cursor-not-allowed peer-disabled:opacity-50",
|
|
530
|
+
className
|
|
531
|
+
),
|
|
480
532
|
...props
|
|
481
533
|
}
|
|
482
534
|
);
|
|
483
|
-
}
|
|
535
|
+
}
|
|
536
|
+
|
|
537
|
+
// src/components/ui/field.tsx
|
|
538
|
+
var Field = React4__namespace.forwardRef(
|
|
539
|
+
({ className, orientation = "vertical", invalid = false, ...props }, ref) => {
|
|
540
|
+
return /* @__PURE__ */ React4__namespace.createElement(
|
|
541
|
+
"div",
|
|
542
|
+
{
|
|
543
|
+
ref,
|
|
544
|
+
"data-slot": "field",
|
|
545
|
+
"data-orientation": orientation,
|
|
546
|
+
"data-invalid": invalid || void 0,
|
|
547
|
+
className: cn(
|
|
548
|
+
"flex",
|
|
549
|
+
orientation === "horizontal" ? "items-center gap-2" : "flex-col gap-1.5",
|
|
550
|
+
className
|
|
551
|
+
),
|
|
552
|
+
...props
|
|
553
|
+
}
|
|
554
|
+
);
|
|
555
|
+
}
|
|
556
|
+
);
|
|
484
557
|
Field.displayName = "Field";
|
|
485
|
-
var FieldGroup =
|
|
486
|
-
return /* @__PURE__ */
|
|
558
|
+
var FieldGroup = React4__namespace.forwardRef(({ className, ...props }, ref) => {
|
|
559
|
+
return /* @__PURE__ */ React4__namespace.createElement(
|
|
487
560
|
"div",
|
|
488
561
|
{
|
|
489
562
|
ref,
|
|
@@ -494,9 +567,9 @@ var FieldGroup = React3__namespace.forwardRef(({ className, ...props }, ref) =>
|
|
|
494
567
|
);
|
|
495
568
|
});
|
|
496
569
|
FieldGroup.displayName = "FieldGroup";
|
|
497
|
-
var FieldLabel =
|
|
498
|
-
return /* @__PURE__ */
|
|
499
|
-
|
|
570
|
+
var FieldLabel = React4__namespace.forwardRef(({ className, required, children, ...props }, ref) => {
|
|
571
|
+
return /* @__PURE__ */ React4__namespace.createElement(
|
|
572
|
+
Label,
|
|
500
573
|
{
|
|
501
574
|
ref,
|
|
502
575
|
"data-slot": "field-label",
|
|
@@ -508,12 +581,12 @@ var FieldLabel = React3__namespace.forwardRef(({ className, required, children,
|
|
|
508
581
|
...props
|
|
509
582
|
},
|
|
510
583
|
children,
|
|
511
|
-
required && /* @__PURE__ */
|
|
584
|
+
required && /* @__PURE__ */ React4__namespace.createElement("span", { className: "text-destructive ml-1" }, "*")
|
|
512
585
|
);
|
|
513
586
|
});
|
|
514
587
|
FieldLabel.displayName = "FieldLabel";
|
|
515
|
-
var FieldDescription =
|
|
516
|
-
return /* @__PURE__ */
|
|
588
|
+
var FieldDescription = React4__namespace.forwardRef(({ className, ...props }, ref) => {
|
|
589
|
+
return /* @__PURE__ */ React4__namespace.createElement(
|
|
517
590
|
"p",
|
|
518
591
|
{
|
|
519
592
|
ref,
|
|
@@ -524,8 +597,8 @@ var FieldDescription = React3__namespace.forwardRef(({ className, ...props }, re
|
|
|
524
597
|
);
|
|
525
598
|
});
|
|
526
599
|
FieldDescription.displayName = "FieldDescription";
|
|
527
|
-
var FieldError =
|
|
528
|
-
return /* @__PURE__ */
|
|
600
|
+
var FieldError = React4__namespace.forwardRef(({ className, ...props }, ref) => {
|
|
601
|
+
return /* @__PURE__ */ React4__namespace.createElement(
|
|
529
602
|
"p",
|
|
530
603
|
{
|
|
531
604
|
ref,
|
|
@@ -548,7 +621,7 @@ var FieldFeedback = ({
|
|
|
548
621
|
}) => {
|
|
549
622
|
const errorText = Array.isArray(error) ? error.join(", ") : error;
|
|
550
623
|
if (!errorText || !shouldRenderError) return null;
|
|
551
|
-
return /* @__PURE__ */
|
|
624
|
+
return /* @__PURE__ */ React4__namespace.createElement(FieldError, { id: errorId, className: errorClassName }, errorText);
|
|
552
625
|
};
|
|
553
626
|
var LabelGroup = ({
|
|
554
627
|
labelHtmlFor,
|
|
@@ -565,40 +638,38 @@ var LabelGroup = ({
|
|
|
565
638
|
variant === "legend" ? "mb-1.5" : "mb-1 block",
|
|
566
639
|
primaryClassName
|
|
567
640
|
);
|
|
568
|
-
const requiredIndicator = required ? /* @__PURE__ */
|
|
641
|
+
const requiredIndicator = required && variant !== "label" ? /* @__PURE__ */ React4__namespace.createElement("span", { className: "text-destructive pl-0.5", "aria-label": "required" }, "*") : null;
|
|
569
642
|
let primaryElement = null;
|
|
570
643
|
if (primary) {
|
|
571
644
|
if (variant === "label") {
|
|
572
|
-
primaryElement = /* @__PURE__ */
|
|
573
|
-
|
|
645
|
+
primaryElement = /* @__PURE__ */ React4__namespace.createElement(
|
|
646
|
+
FieldLabel,
|
|
574
647
|
{
|
|
575
648
|
htmlFor: labelHtmlFor,
|
|
576
|
-
|
|
649
|
+
required,
|
|
577
650
|
className: primaryClasses
|
|
578
651
|
},
|
|
579
|
-
primary
|
|
580
|
-
requiredIndicator
|
|
652
|
+
primary
|
|
581
653
|
);
|
|
582
654
|
} else if (variant === "legend") {
|
|
583
|
-
primaryElement = /* @__PURE__ */
|
|
655
|
+
primaryElement = /* @__PURE__ */ React4__namespace.createElement("legend", { "data-slot": "field-legend", className: primaryClasses }, primary, requiredIndicator);
|
|
584
656
|
} else {
|
|
585
|
-
primaryElement = /* @__PURE__ */
|
|
657
|
+
primaryElement = /* @__PURE__ */ React4__namespace.createElement("div", { "data-slot": "field-label", className: primaryClasses }, primary, requiredIndicator);
|
|
586
658
|
}
|
|
587
659
|
}
|
|
588
|
-
const secondaryElement = secondary ? /* @__PURE__ */
|
|
589
|
-
|
|
660
|
+
const secondaryElement = secondary ? /* @__PURE__ */ React4__namespace.createElement(
|
|
661
|
+
FieldDescription,
|
|
590
662
|
{
|
|
591
|
-
"data-slot": "field-description",
|
|
592
663
|
id: secondaryId,
|
|
593
|
-
className: cn("
|
|
664
|
+
className: cn("leading-normal font-normal", secondaryClassName)
|
|
594
665
|
},
|
|
595
666
|
secondary
|
|
596
667
|
) : null;
|
|
597
668
|
if (!primaryElement && !secondaryElement) return null;
|
|
598
669
|
if (variant === "legend") {
|
|
599
|
-
return /* @__PURE__ */
|
|
670
|
+
return /* @__PURE__ */ React4__namespace.createElement(React4__namespace.Fragment, null, primaryElement, secondaryElement);
|
|
600
671
|
}
|
|
601
|
-
return /* @__PURE__ */
|
|
672
|
+
return /* @__PURE__ */ React4__namespace.createElement("div", { className: "flex flex-1 flex-col gap-0.5" }, primaryElement, secondaryElement);
|
|
602
673
|
};
|
|
603
674
|
|
|
604
675
|
// src/core/Field.tsx
|
|
@@ -615,30 +686,40 @@ function Field2({
|
|
|
615
686
|
}) {
|
|
616
687
|
const fieldState = useField({ name, validate });
|
|
617
688
|
const { meta } = fieldState;
|
|
618
|
-
const hasError =
|
|
689
|
+
const hasError = React4__namespace.useMemo(() => {
|
|
619
690
|
return showError && meta.touched && meta.error ? true : false;
|
|
620
691
|
}, [meta?.touched, meta?.error, showError]);
|
|
621
692
|
const errorId = `${name}-error`;
|
|
622
693
|
const descriptionId = `${name}-description`;
|
|
623
|
-
return /* @__PURE__ */
|
|
624
|
-
|
|
625
|
-
{
|
|
626
|
-
labelHtmlFor: name,
|
|
627
|
-
required,
|
|
628
|
-
variant: "label",
|
|
629
|
-
secondaryId: descriptionId,
|
|
630
|
-
secondary: description,
|
|
631
|
-
primary: label
|
|
632
|
-
}
|
|
633
|
-
), /* @__PURE__ */ React3__namespace.createElement("div", null, typeof children === "function" ? children(fieldState) : children), /* @__PURE__ */ React3__namespace.createElement(
|
|
634
|
-
FieldFeedback,
|
|
694
|
+
return /* @__PURE__ */ React4__namespace.createElement(
|
|
695
|
+
Field,
|
|
635
696
|
{
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
697
|
+
className,
|
|
698
|
+
"data-field": name,
|
|
699
|
+
invalid: hasError
|
|
700
|
+
},
|
|
701
|
+
/* @__PURE__ */ React4__namespace.createElement(
|
|
702
|
+
LabelGroup,
|
|
703
|
+
{
|
|
704
|
+
labelHtmlFor: name,
|
|
705
|
+
required,
|
|
706
|
+
variant: "label",
|
|
707
|
+
secondaryId: descriptionId,
|
|
708
|
+
secondary: description,
|
|
709
|
+
primary: label
|
|
710
|
+
}
|
|
711
|
+
),
|
|
712
|
+
/* @__PURE__ */ React4__namespace.createElement("div", { "data-slot": "field-control" }, typeof children === "function" ? children(fieldState) : children),
|
|
713
|
+
/* @__PURE__ */ React4__namespace.createElement(
|
|
714
|
+
FieldFeedback,
|
|
715
|
+
{
|
|
716
|
+
errorId,
|
|
717
|
+
errorClassName,
|
|
718
|
+
shouldRenderError: hasError,
|
|
719
|
+
error: meta.error
|
|
720
|
+
}
|
|
721
|
+
)
|
|
722
|
+
);
|
|
642
723
|
}
|
|
643
724
|
Field2.displayName = "Field";
|
|
644
725
|
|