@form-eng/mantine 1.5.2 → 1.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/dist/index.d.mts +49 -3
- package/dist/index.d.ts +49 -3
- package/dist/index.js +645 -33
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +622 -25
- package/dist/index.mjs.map +1 -1
- package/package.json +8 -2
package/dist/index.mjs
CHANGED
|
@@ -22,6 +22,7 @@ var ReadOnlyText = (props) => {
|
|
|
22
22
|
import {
|
|
23
23
|
FieldClassName,
|
|
24
24
|
GetFieldDataTestId,
|
|
25
|
+
getFieldState,
|
|
25
26
|
formatDateTime,
|
|
26
27
|
DocumentLinksStrings,
|
|
27
28
|
convertBooleanToYesOrNoText,
|
|
@@ -430,45 +431,610 @@ var DynamicFragment = (props) => {
|
|
|
430
431
|
};
|
|
431
432
|
var DynamicFragment_default = DynamicFragment;
|
|
432
433
|
|
|
433
|
-
// src/fields/
|
|
434
|
+
// src/fields/Rating.tsx
|
|
435
|
+
import { Rating as MantineRating } from "@mantine/core";
|
|
434
436
|
import { jsx as jsx14 } from "react/jsx-runtime";
|
|
437
|
+
var Rating = (props) => {
|
|
438
|
+
const { fieldName, programName, entityType, entityId, value, readOnly, error, required, config, setFieldValue } = props;
|
|
439
|
+
const max = config?.max ?? 5;
|
|
440
|
+
const rating = value ?? 0;
|
|
441
|
+
if (readOnly) {
|
|
442
|
+
return /* @__PURE__ */ jsx14(ReadOnlyText, { fieldName, value: String(rating) });
|
|
443
|
+
}
|
|
444
|
+
return /* @__PURE__ */ jsx14(
|
|
445
|
+
MantineRating,
|
|
446
|
+
{
|
|
447
|
+
className: "fe-rating",
|
|
448
|
+
count: max,
|
|
449
|
+
value: rating,
|
|
450
|
+
onChange: (val) => setFieldValue(fieldName, val),
|
|
451
|
+
"data-testid": GetFieldDataTestId(fieldName, programName, entityType, entityId)
|
|
452
|
+
}
|
|
453
|
+
);
|
|
454
|
+
};
|
|
455
|
+
var Rating_default = Rating;
|
|
456
|
+
|
|
457
|
+
// src/fields/Autocomplete.tsx
|
|
458
|
+
import { Autocomplete as MantineAutocomplete } from "@mantine/core";
|
|
459
|
+
import { jsx as jsx15 } from "react/jsx-runtime";
|
|
460
|
+
var Autocomplete = (props) => {
|
|
461
|
+
const { fieldName, programName, entityType, entityId, value, readOnly, error, required, placeholder, options, setFieldValue } = props;
|
|
462
|
+
const selectedLabel = options?.find((o) => String(o.value) === String(value))?.label ?? value ?? "";
|
|
463
|
+
if (readOnly) {
|
|
464
|
+
return /* @__PURE__ */ jsx15(ReadOnlyText, { fieldName, value: selectedLabel });
|
|
465
|
+
}
|
|
466
|
+
const data = options?.map((o) => ({ value: String(o.value), label: o.label })) ?? [];
|
|
467
|
+
return /* @__PURE__ */ jsx15(
|
|
468
|
+
MantineAutocomplete,
|
|
469
|
+
{
|
|
470
|
+
className: "fe-autocomplete",
|
|
471
|
+
data,
|
|
472
|
+
defaultValue: selectedLabel,
|
|
473
|
+
onChange: (val) => {
|
|
474
|
+
const match = options?.find((o) => o.label === val);
|
|
475
|
+
setFieldValue(fieldName, match ? String(match.value) : val);
|
|
476
|
+
},
|
|
477
|
+
placeholder,
|
|
478
|
+
error: !!error,
|
|
479
|
+
required,
|
|
480
|
+
"data-testid": GetFieldDataTestId(fieldName, programName, entityType, entityId)
|
|
481
|
+
}
|
|
482
|
+
);
|
|
483
|
+
};
|
|
484
|
+
var Autocomplete_default = Autocomplete;
|
|
485
|
+
|
|
486
|
+
// src/fields/DateTime.tsx
|
|
487
|
+
import { formatDateTimeValue } from "@form-eng/core";
|
|
488
|
+
import { DateTimePicker } from "@mantine/dates";
|
|
489
|
+
import { jsx as jsx16 } from "react/jsx-runtime";
|
|
490
|
+
var DateTime = (props) => {
|
|
491
|
+
const { fieldName, programName, entityType, entityId, value, readOnly, error, required, config, setFieldValue } = props;
|
|
492
|
+
if (readOnly) {
|
|
493
|
+
return /* @__PURE__ */ jsx16(ReadOnlyText, { fieldName, value: formatDateTimeValue(value) });
|
|
494
|
+
}
|
|
495
|
+
const dateValue = value ? new Date(value) : null;
|
|
496
|
+
const onChange = (date) => {
|
|
497
|
+
setFieldValue(fieldName, date ? date.toISOString() : null);
|
|
498
|
+
};
|
|
499
|
+
return /* @__PURE__ */ jsx16(
|
|
500
|
+
DateTimePicker,
|
|
501
|
+
{
|
|
502
|
+
className: "fe-date-time",
|
|
503
|
+
value: dateValue,
|
|
504
|
+
onChange,
|
|
505
|
+
error: !!error,
|
|
506
|
+
required,
|
|
507
|
+
"data-testid": GetFieldDataTestId(fieldName, programName, entityType, entityId)
|
|
508
|
+
}
|
|
509
|
+
);
|
|
510
|
+
};
|
|
511
|
+
var DateTime_default = DateTime;
|
|
512
|
+
|
|
513
|
+
// src/fields/DateRange.tsx
|
|
514
|
+
import { formatDateRange } from "@form-eng/core";
|
|
515
|
+
import { jsx as jsx17, jsxs as jsxs2 } from "react/jsx-runtime";
|
|
516
|
+
var DateRange = (props) => {
|
|
517
|
+
const { fieldName, programName, entityType, entityId, value, readOnly, error, required, config, setFieldValue } = props;
|
|
518
|
+
const rangeValue = value ?? { start: "", end: "" };
|
|
519
|
+
const minDate = config?.minDate;
|
|
520
|
+
const maxDate = config?.maxDate;
|
|
521
|
+
const rangeError = rangeValue.start && rangeValue.end && rangeValue.start > rangeValue.end ? "Start date must be on or before end date." : void 0;
|
|
522
|
+
if (readOnly) {
|
|
523
|
+
return /* @__PURE__ */ jsx17(ReadOnlyText, { fieldName, value: formatDateRange(value) });
|
|
524
|
+
}
|
|
525
|
+
const onStartChange = (event) => {
|
|
526
|
+
setFieldValue(fieldName, { ...rangeValue, start: event.target.value });
|
|
527
|
+
};
|
|
528
|
+
const onEndChange = (event) => {
|
|
529
|
+
setFieldValue(fieldName, { ...rangeValue, end: event.target.value });
|
|
530
|
+
};
|
|
531
|
+
return /* @__PURE__ */ jsxs2(
|
|
532
|
+
"div",
|
|
533
|
+
{
|
|
534
|
+
className: "fe-date-range",
|
|
535
|
+
"data-field-type": "DateRange",
|
|
536
|
+
"data-field-state": getFieldState({ error, required, readOnly }),
|
|
537
|
+
"data-testid": GetFieldDataTestId(fieldName, programName, entityType, entityId),
|
|
538
|
+
children: [
|
|
539
|
+
/* @__PURE__ */ jsxs2("div", { className: "fe-date-range__inputs", children: [
|
|
540
|
+
/* @__PURE__ */ jsxs2("div", { className: "fe-date-range__from", children: [
|
|
541
|
+
/* @__PURE__ */ jsx17("label", { htmlFor: `${fieldName}-start`, className: "fe-date-range__label", children: "From" }),
|
|
542
|
+
/* @__PURE__ */ jsx17(
|
|
543
|
+
"input",
|
|
544
|
+
{
|
|
545
|
+
id: `${fieldName}-start`,
|
|
546
|
+
type: "date",
|
|
547
|
+
className: "fe-date-range__input fe-date-range__input--start",
|
|
548
|
+
value: rangeValue.start,
|
|
549
|
+
min: minDate,
|
|
550
|
+
max: rangeValue.end || maxDate,
|
|
551
|
+
onChange: onStartChange,
|
|
552
|
+
"aria-invalid": !!error,
|
|
553
|
+
"aria-required": required,
|
|
554
|
+
"aria-label": "Start date"
|
|
555
|
+
}
|
|
556
|
+
)
|
|
557
|
+
] }),
|
|
558
|
+
/* @__PURE__ */ jsxs2("div", { className: "fe-date-range__to", children: [
|
|
559
|
+
/* @__PURE__ */ jsx17("label", { htmlFor: `${fieldName}-end`, className: "fe-date-range__label", children: "To" }),
|
|
560
|
+
/* @__PURE__ */ jsx17(
|
|
561
|
+
"input",
|
|
562
|
+
{
|
|
563
|
+
id: `${fieldName}-end`,
|
|
564
|
+
type: "date",
|
|
565
|
+
className: "fe-date-range__input fe-date-range__input--end",
|
|
566
|
+
value: rangeValue.end,
|
|
567
|
+
min: rangeValue.start || minDate,
|
|
568
|
+
max: maxDate,
|
|
569
|
+
onChange: onEndChange,
|
|
570
|
+
"aria-label": "End date"
|
|
571
|
+
}
|
|
572
|
+
)
|
|
573
|
+
] })
|
|
574
|
+
] }),
|
|
575
|
+
rangeError && /* @__PURE__ */ jsx17("span", { className: "fe-date-range__range-error", role: "alert", children: rangeError })
|
|
576
|
+
]
|
|
577
|
+
}
|
|
578
|
+
);
|
|
579
|
+
};
|
|
580
|
+
var DateRange_default = DateRange;
|
|
581
|
+
|
|
582
|
+
// src/fields/PhoneInput.tsx
|
|
583
|
+
import { extractDigits, formatPhone } from "@form-eng/core";
|
|
584
|
+
import { jsx as jsx18 } from "react/jsx-runtime";
|
|
585
|
+
var PhoneInput = (props) => {
|
|
586
|
+
const { fieldName, programName, entityType, entityId, value, readOnly, error, required, config, setFieldValue } = props;
|
|
587
|
+
const format = config?.format ?? "us";
|
|
588
|
+
if (readOnly) {
|
|
589
|
+
return /* @__PURE__ */ jsx18(ReadOnlyText, { fieldName, value: value ?? "" });
|
|
590
|
+
}
|
|
591
|
+
const onChange = (event) => {
|
|
592
|
+
const digits = extractDigits(event.target.value);
|
|
593
|
+
const formatted = formatPhone(digits, format);
|
|
594
|
+
setFieldValue(fieldName, formatted);
|
|
595
|
+
};
|
|
596
|
+
return /* @__PURE__ */ jsx18(
|
|
597
|
+
"input",
|
|
598
|
+
{
|
|
599
|
+
type: "tel",
|
|
600
|
+
className: "fe-phone-input",
|
|
601
|
+
"data-field-type": "PhoneInput",
|
|
602
|
+
"data-field-state": getFieldState({ error, required, readOnly }),
|
|
603
|
+
value: value ?? "",
|
|
604
|
+
onChange,
|
|
605
|
+
"aria-invalid": !!error,
|
|
606
|
+
"aria-required": required,
|
|
607
|
+
"data-testid": GetFieldDataTestId(fieldName, programName, entityType, entityId)
|
|
608
|
+
}
|
|
609
|
+
);
|
|
610
|
+
};
|
|
611
|
+
var PhoneInput_default = PhoneInput;
|
|
612
|
+
|
|
613
|
+
// src/fields/FileUpload.tsx
|
|
614
|
+
import { MAX_FILE_SIZE_MB_DEFAULT, getFileNames } from "@form-eng/core";
|
|
615
|
+
import React2 from "react";
|
|
616
|
+
import { FileInput } from "@mantine/core";
|
|
617
|
+
import { jsx as jsx19, jsxs as jsxs3 } from "react/jsx-runtime";
|
|
618
|
+
var FileUpload = (props) => {
|
|
619
|
+
const { fieldName, programName, entityType, entityId, value, readOnly, error, required, config, setFieldValue } = props;
|
|
620
|
+
const multiple = config?.multiple ?? false;
|
|
621
|
+
const accept = config?.accept;
|
|
622
|
+
const maxSizeMb = config?.maxSizeMb ?? MAX_FILE_SIZE_MB_DEFAULT;
|
|
623
|
+
const maxSizeBytes = maxSizeMb * 1024 * 1024;
|
|
624
|
+
const [sizeError, setSizeError] = React2.useState(void 0);
|
|
625
|
+
if (readOnly) {
|
|
626
|
+
return /* @__PURE__ */ jsx19(ReadOnlyText, { fieldName, value: getFileNames(value) });
|
|
627
|
+
}
|
|
628
|
+
const onChange = (files) => {
|
|
629
|
+
if (!files || Array.isArray(files) && files.length === 0) {
|
|
630
|
+
setFieldValue(fieldName, null);
|
|
631
|
+
setSizeError(void 0);
|
|
632
|
+
return;
|
|
633
|
+
}
|
|
634
|
+
const fileArray = Array.isArray(files) ? files : [files];
|
|
635
|
+
const oversized = fileArray.find((f) => f.size > maxSizeBytes);
|
|
636
|
+
if (oversized) {
|
|
637
|
+
setSizeError(`"${oversized.name}" exceeds the ${maxSizeMb} MB size limit.`);
|
|
638
|
+
setFieldValue(fieldName, null);
|
|
639
|
+
return;
|
|
640
|
+
}
|
|
641
|
+
setSizeError(void 0);
|
|
642
|
+
setFieldValue(fieldName, multiple ? fileArray : fileArray[0]);
|
|
643
|
+
};
|
|
644
|
+
return /* @__PURE__ */ jsxs3(
|
|
645
|
+
"div",
|
|
646
|
+
{
|
|
647
|
+
className: "fe-file-upload",
|
|
648
|
+
"data-field-type": "FileUpload",
|
|
649
|
+
"data-field-state": getFieldState({ error, required, readOnly }),
|
|
650
|
+
"data-testid": GetFieldDataTestId(fieldName, programName, entityType, entityId),
|
|
651
|
+
children: [
|
|
652
|
+
/* @__PURE__ */ jsx19(
|
|
653
|
+
FileInput,
|
|
654
|
+
{
|
|
655
|
+
accept,
|
|
656
|
+
multiple,
|
|
657
|
+
onChange,
|
|
658
|
+
error: !!error,
|
|
659
|
+
required,
|
|
660
|
+
placeholder: getFileNames(value) || "Choose file"
|
|
661
|
+
}
|
|
662
|
+
),
|
|
663
|
+
sizeError && /* @__PURE__ */ jsx19("span", { className: "fe-file-upload__size-error", role: "alert", children: sizeError })
|
|
664
|
+
]
|
|
665
|
+
}
|
|
666
|
+
);
|
|
667
|
+
};
|
|
668
|
+
var FileUpload_default = FileUpload;
|
|
669
|
+
|
|
670
|
+
// src/fields/ColorPicker.tsx
|
|
671
|
+
import { ColorInput } from "@mantine/core";
|
|
672
|
+
import { jsx as jsx20 } from "react/jsx-runtime";
|
|
673
|
+
var ColorPicker = (props) => {
|
|
674
|
+
const { fieldName, programName, entityType, entityId, value, readOnly, error, required, setFieldValue } = props;
|
|
675
|
+
const color = value ?? "#000000";
|
|
676
|
+
if (readOnly) {
|
|
677
|
+
return /* @__PURE__ */ jsx20(ReadOnlyText, { fieldName, value: color });
|
|
678
|
+
}
|
|
679
|
+
return /* @__PURE__ */ jsx20(
|
|
680
|
+
ColorInput,
|
|
681
|
+
{
|
|
682
|
+
className: "fe-color-picker",
|
|
683
|
+
value: color,
|
|
684
|
+
onChange: (val) => setFieldValue(fieldName, val),
|
|
685
|
+
error: !!error,
|
|
686
|
+
required,
|
|
687
|
+
"data-field-type": "ColorPicker",
|
|
688
|
+
"data-field-state": getFieldState({ error, required, readOnly }),
|
|
689
|
+
"data-testid": GetFieldDataTestId(fieldName, programName, entityType, entityId)
|
|
690
|
+
}
|
|
691
|
+
);
|
|
692
|
+
};
|
|
693
|
+
var ColorPicker_default = ColorPicker;
|
|
694
|
+
|
|
695
|
+
// src/fields/MultiSelectSearch.tsx
|
|
696
|
+
import { useState, useMemo } from "react";
|
|
697
|
+
import { jsx as jsx21, jsxs as jsxs4 } from "react/jsx-runtime";
|
|
698
|
+
var MultiSelectSearch = (props) => {
|
|
699
|
+
const { fieldName, programName, entityType, entityId, value, readOnly, error, required, options, setFieldValue } = props;
|
|
700
|
+
const [searchTerm, setSearchTerm] = useState("");
|
|
701
|
+
const selectedValues = value ?? [];
|
|
702
|
+
const filteredOptions = useMemo(() => {
|
|
703
|
+
if (!searchTerm) return options ?? [];
|
|
704
|
+
const lower = searchTerm.toLowerCase();
|
|
705
|
+
return (options ?? []).filter((o) => o.label.toLowerCase().includes(lower));
|
|
706
|
+
}, [options, searchTerm]);
|
|
707
|
+
const onCheckChange = (optionValue, checked) => {
|
|
708
|
+
const updated = checked ? [...selectedValues, optionValue] : selectedValues.filter((v) => v !== optionValue);
|
|
709
|
+
setFieldValue(fieldName, updated, false, 3e3);
|
|
710
|
+
};
|
|
711
|
+
if (readOnly) {
|
|
712
|
+
return selectedValues.length > 0 ? /* @__PURE__ */ jsx21("ul", { className: "fe-multi-select-search-readonly", "data-field-type": "MultiSelectSearch", "data-field-state": "readonly", children: selectedValues.map((v, i) => /* @__PURE__ */ jsx21("li", { children: v }, i)) }) : /* @__PURE__ */ jsx21("span", { className: "fe-read-only-text", children: "-" });
|
|
713
|
+
}
|
|
714
|
+
return /* @__PURE__ */ jsxs4("div", { className: "fe-multi-select-search", "data-field-type": "MultiSelectSearch", "data-field-state": getFieldState({ error, required, readOnly }), "data-testid": GetFieldDataTestId(fieldName, programName, entityType, entityId), children: [
|
|
715
|
+
/* @__PURE__ */ jsx21("input", { type: "search", className: "fe-multi-select-search__input", placeholder: "Search...", value: searchTerm, onChange: (e) => setSearchTerm(e.target.value), "aria-label": `Search options for ${fieldName}` }),
|
|
716
|
+
/* @__PURE__ */ jsxs4("fieldset", { className: "fe-multi-select-search__options", "aria-invalid": !!error, "aria-required": required, children: [
|
|
717
|
+
/* @__PURE__ */ jsx21("legend", { className: "fe-sr-only", children: "Options" }),
|
|
718
|
+
filteredOptions.map((option) => {
|
|
719
|
+
const optVal = String(option.value);
|
|
720
|
+
const isChecked = selectedValues.includes(optVal);
|
|
721
|
+
return /* @__PURE__ */ jsxs4("label", { className: "fe-multi-select-search__option", children: [
|
|
722
|
+
/* @__PURE__ */ jsx21("input", { type: "checkbox", checked: isChecked, disabled: option.disabled, onChange: (e) => onCheckChange(optVal, e.target.checked) }),
|
|
723
|
+
/* @__PURE__ */ jsx21("span", { children: option.label })
|
|
724
|
+
] }, optVal);
|
|
725
|
+
})
|
|
726
|
+
] })
|
|
727
|
+
] });
|
|
728
|
+
};
|
|
729
|
+
var MultiSelectSearch_default = MultiSelectSearch;
|
|
730
|
+
|
|
731
|
+
// src/fields/StatusDropdown.tsx
|
|
732
|
+
import { jsx as jsx22, jsxs as jsxs5 } from "react/jsx-runtime";
|
|
733
|
+
var StatusDropdown = (props) => {
|
|
734
|
+
const { fieldName, programName, entityType, entityId, value, readOnly, error, required, config, options, placeholder, setFieldValue } = props;
|
|
735
|
+
const onChange = (event) => {
|
|
736
|
+
setFieldValue(fieldName, event.target.value);
|
|
737
|
+
};
|
|
738
|
+
const statusColor = config?.statusColors?.[value];
|
|
739
|
+
if (readOnly) {
|
|
740
|
+
return /* @__PURE__ */ jsxs5(
|
|
741
|
+
"div",
|
|
742
|
+
{
|
|
743
|
+
className: "fe-status-dropdown fe-status-dropdown--readonly",
|
|
744
|
+
"data-field-type": "StatusDropdown",
|
|
745
|
+
"data-field-state": "readonly",
|
|
746
|
+
children: [
|
|
747
|
+
statusColor && /* @__PURE__ */ jsx22(
|
|
748
|
+
"span",
|
|
749
|
+
{
|
|
750
|
+
className: "fe-status-dropdown__indicator",
|
|
751
|
+
style: { backgroundColor: statusColor },
|
|
752
|
+
"aria-hidden": "true"
|
|
753
|
+
}
|
|
754
|
+
),
|
|
755
|
+
/* @__PURE__ */ jsx22(ReadOnlyText, { fieldName, value })
|
|
756
|
+
]
|
|
757
|
+
}
|
|
758
|
+
);
|
|
759
|
+
}
|
|
760
|
+
return /* @__PURE__ */ jsxs5(
|
|
761
|
+
"div",
|
|
762
|
+
{
|
|
763
|
+
className: "fe-status-dropdown",
|
|
764
|
+
"data-field-type": "StatusDropdown",
|
|
765
|
+
"data-field-state": getFieldState({ error, required, readOnly }),
|
|
766
|
+
children: [
|
|
767
|
+
statusColor && /* @__PURE__ */ jsx22(
|
|
768
|
+
"span",
|
|
769
|
+
{
|
|
770
|
+
className: "fe-status-dropdown__indicator",
|
|
771
|
+
style: { backgroundColor: statusColor },
|
|
772
|
+
"aria-hidden": "true"
|
|
773
|
+
}
|
|
774
|
+
),
|
|
775
|
+
/* @__PURE__ */ jsxs5(
|
|
776
|
+
"select",
|
|
777
|
+
{
|
|
778
|
+
className: "fe-status-dropdown__select",
|
|
779
|
+
value: value ?? "",
|
|
780
|
+
onChange,
|
|
781
|
+
"aria-invalid": !!error,
|
|
782
|
+
"aria-required": required,
|
|
783
|
+
"data-testid": GetFieldDataTestId(fieldName, programName, entityType, entityId),
|
|
784
|
+
children: [
|
|
785
|
+
/* @__PURE__ */ jsx22("option", { value: "", children: placeholder ?? config?.placeHolder ?? "" }),
|
|
786
|
+
options?.map((option) => /* @__PURE__ */ jsx22("option", { value: String(option.value), disabled: option.disabled, children: option.label }, String(option.value)))
|
|
787
|
+
]
|
|
788
|
+
}
|
|
789
|
+
)
|
|
790
|
+
]
|
|
791
|
+
}
|
|
792
|
+
);
|
|
793
|
+
};
|
|
794
|
+
var StatusDropdown_default = StatusDropdown;
|
|
795
|
+
|
|
796
|
+
// src/fields/DocumentLinks.tsx
|
|
797
|
+
import { useState as useState2 } from "react";
|
|
798
|
+
import { useFormContext } from "react-hook-form";
|
|
799
|
+
import { jsx as jsx23, jsxs as jsxs6 } from "react/jsx-runtime";
|
|
800
|
+
var DocumentLinks = (props) => {
|
|
801
|
+
const { fieldName, programName, entityType, entityId, value, readOnly, error, required, setFieldValue } = props;
|
|
802
|
+
const { watch } = useFormContext();
|
|
803
|
+
const documentLinks = watch(`${fieldName}`) ?? [];
|
|
804
|
+
const [newUrl, setNewUrl] = useState2("");
|
|
805
|
+
const [newText, setNewText] = useState2("");
|
|
806
|
+
const onAddLink = () => {
|
|
807
|
+
if (!newUrl) return;
|
|
808
|
+
const link = { url: newUrl, title: newText || newUrl };
|
|
809
|
+
setFieldValue(fieldName, [...documentLinks, link]);
|
|
810
|
+
setNewUrl("");
|
|
811
|
+
setNewText("");
|
|
812
|
+
};
|
|
813
|
+
const onDeleteLink = (index) => {
|
|
814
|
+
const updated = [...documentLinks];
|
|
815
|
+
updated.splice(index, 1);
|
|
816
|
+
setFieldValue(fieldName, updated);
|
|
817
|
+
};
|
|
818
|
+
if (readOnly) {
|
|
819
|
+
return /* @__PURE__ */ jsx23(
|
|
820
|
+
"ul",
|
|
821
|
+
{
|
|
822
|
+
className: "fe-document-links fe-document-links--readonly",
|
|
823
|
+
"data-field-type": "DocumentLinks",
|
|
824
|
+
"data-field-state": "readonly",
|
|
825
|
+
children: value?.map((link, i) => /* @__PURE__ */ jsx23("li", { className: "fe-document-links__item", children: /* @__PURE__ */ jsx23("a", { href: link.url, target: "_blank", rel: "noopener noreferrer", children: link.title || link.url }) }, i))
|
|
826
|
+
}
|
|
827
|
+
);
|
|
828
|
+
}
|
|
829
|
+
return /* @__PURE__ */ jsxs6(
|
|
830
|
+
"div",
|
|
831
|
+
{
|
|
832
|
+
className: "fe-document-links",
|
|
833
|
+
"data-field-type": "DocumentLinks",
|
|
834
|
+
"data-field-state": getFieldState({ error, required, readOnly }),
|
|
835
|
+
"data-testid": GetFieldDataTestId(fieldName, programName, entityType, entityId),
|
|
836
|
+
children: [
|
|
837
|
+
/* @__PURE__ */ jsx23("ul", { className: "fe-document-links__list", children: documentLinks.map((link, i) => /* @__PURE__ */ jsxs6("li", { className: "fe-document-links__item", children: [
|
|
838
|
+
/* @__PURE__ */ jsx23("a", { href: link.url, target: "_blank", rel: "noopener noreferrer", children: link.title || link.url }),
|
|
839
|
+
/* @__PURE__ */ jsx23(
|
|
840
|
+
"button",
|
|
841
|
+
{
|
|
842
|
+
type: "button",
|
|
843
|
+
className: "fe-document-links__delete",
|
|
844
|
+
onClick: () => onDeleteLink(i),
|
|
845
|
+
"aria-label": `${DocumentLinksStrings.deleteLink}: ${link.title || link.url}`,
|
|
846
|
+
children: "\xD7"
|
|
847
|
+
}
|
|
848
|
+
)
|
|
849
|
+
] }, i)) }),
|
|
850
|
+
/* @__PURE__ */ jsxs6("div", { className: "fe-document-links__add", children: [
|
|
851
|
+
/* @__PURE__ */ jsx23(
|
|
852
|
+
"input",
|
|
853
|
+
{
|
|
854
|
+
type: "url",
|
|
855
|
+
className: "fe-document-links__url-input",
|
|
856
|
+
placeholder: "URL",
|
|
857
|
+
value: newUrl,
|
|
858
|
+
onChange: (e) => setNewUrl(e.target.value),
|
|
859
|
+
"aria-label": DocumentLinksStrings.link
|
|
860
|
+
}
|
|
861
|
+
),
|
|
862
|
+
/* @__PURE__ */ jsx23(
|
|
863
|
+
"input",
|
|
864
|
+
{
|
|
865
|
+
type: "text",
|
|
866
|
+
className: "fe-document-links__text-input",
|
|
867
|
+
placeholder: "Label (optional)",
|
|
868
|
+
value: newText,
|
|
869
|
+
onChange: (e) => setNewText(e.target.value),
|
|
870
|
+
"aria-label": "Link label"
|
|
871
|
+
}
|
|
872
|
+
),
|
|
873
|
+
/* @__PURE__ */ jsx23(
|
|
874
|
+
"button",
|
|
875
|
+
{
|
|
876
|
+
type: "button",
|
|
877
|
+
className: "fe-btn fe-btn--secondary",
|
|
878
|
+
onClick: onAddLink,
|
|
879
|
+
disabled: !newUrl,
|
|
880
|
+
children: documentLinks.length > 0 ? DocumentLinksStrings.addAnotherLink : DocumentLinksStrings.addLink
|
|
881
|
+
}
|
|
882
|
+
)
|
|
883
|
+
] })
|
|
884
|
+
]
|
|
885
|
+
}
|
|
886
|
+
);
|
|
887
|
+
};
|
|
888
|
+
var DocumentLinks_default = DocumentLinks;
|
|
889
|
+
|
|
890
|
+
// src/fields/readonly/ReadOnly.tsx
|
|
891
|
+
import { jsx as jsx24 } from "react/jsx-runtime";
|
|
435
892
|
var ReadOnly = (props) => {
|
|
436
893
|
const { fieldName, value, config } = props;
|
|
437
|
-
return /* @__PURE__ */
|
|
894
|
+
return /* @__PURE__ */ jsx24(ReadOnlyText, { fieldName, value, ...config });
|
|
438
895
|
};
|
|
439
896
|
var ReadOnly_default = ReadOnly;
|
|
440
897
|
|
|
898
|
+
// src/fields/readonly/ReadOnlyArray.tsx
|
|
899
|
+
import { jsx as jsx25 } from "react/jsx-runtime";
|
|
900
|
+
var ReadOnlyArray = (props) => {
|
|
901
|
+
const { fieldName, value } = props;
|
|
902
|
+
const items = value ?? [];
|
|
903
|
+
if (items.length === 0) {
|
|
904
|
+
return /* @__PURE__ */ jsx25("span", { className: "fe-read-only-text", "data-field-type": "ReadOnlyArray", children: "-" });
|
|
905
|
+
}
|
|
906
|
+
return /* @__PURE__ */ jsx25(
|
|
907
|
+
"ul",
|
|
908
|
+
{
|
|
909
|
+
className: "fe-read-only-array",
|
|
910
|
+
"data-field-type": "ReadOnlyArray",
|
|
911
|
+
"data-field-state": "readonly",
|
|
912
|
+
id: `${fieldName}-read-only`,
|
|
913
|
+
children: items.map((v, i) => /* @__PURE__ */ jsx25("li", { children: v }, i))
|
|
914
|
+
}
|
|
915
|
+
);
|
|
916
|
+
};
|
|
917
|
+
var ReadOnlyArray_default = ReadOnlyArray;
|
|
918
|
+
|
|
919
|
+
// src/fields/readonly/ReadOnlyDateTime.tsx
|
|
920
|
+
import { jsx as jsx26 } from "react/jsx-runtime";
|
|
921
|
+
var ReadOnlyDateTime = (props) => {
|
|
922
|
+
const { config, value } = props;
|
|
923
|
+
if (!value) {
|
|
924
|
+
return /* @__PURE__ */ jsx26("span", { className: "fe-read-only-text", "data-field-type": "ReadOnlyDateTime", children: "-" });
|
|
925
|
+
}
|
|
926
|
+
return /* @__PURE__ */ jsx26(
|
|
927
|
+
"time",
|
|
928
|
+
{
|
|
929
|
+
className: "fe-read-only-date-time",
|
|
930
|
+
dateTime: value,
|
|
931
|
+
"data-field-type": "ReadOnlyDateTime",
|
|
932
|
+
"data-field-state": "readonly",
|
|
933
|
+
children: formatDateTime(value, { hideTimestamp: config?.hidetimeStamp })
|
|
934
|
+
}
|
|
935
|
+
);
|
|
936
|
+
};
|
|
937
|
+
var ReadOnlyDateTime_default = ReadOnlyDateTime;
|
|
938
|
+
|
|
939
|
+
// src/fields/readonly/ReadOnlyCumulativeNumber.tsx
|
|
940
|
+
import { isEmpty } from "@form-eng/core";
|
|
941
|
+
import React5 from "react";
|
|
942
|
+
import { useFormContext as useFormContext2 } from "react-hook-form";
|
|
943
|
+
import { jsx as jsx27 } from "react/jsx-runtime";
|
|
944
|
+
var ReadOnlyCumulativeNumber = (props) => {
|
|
945
|
+
const { fieldName, config } = props;
|
|
946
|
+
const { formState, getValues } = useFormContext2();
|
|
947
|
+
const [value, setValue] = React5.useState();
|
|
948
|
+
const { dependencyFields } = config || {};
|
|
949
|
+
React5.useEffect(() => {
|
|
950
|
+
const formValues = getValues();
|
|
951
|
+
if (!isEmpty(dependencyFields)) {
|
|
952
|
+
let totalCount = 0;
|
|
953
|
+
dependencyFields.map((fn) => {
|
|
954
|
+
totalCount += Number(formValues[fn]) || 0;
|
|
955
|
+
});
|
|
956
|
+
setValue(totalCount);
|
|
957
|
+
}
|
|
958
|
+
}, [formState]);
|
|
959
|
+
if (!fieldName) return null;
|
|
960
|
+
return /* @__PURE__ */ jsx27("span", { "data-field-type": "ReadOnlyCumulativeNumber", "data-field-state": "readonly", children: /* @__PURE__ */ jsx27(ReadOnlyText, { fieldName, value: String(value), ...config }) });
|
|
961
|
+
};
|
|
962
|
+
var ReadOnlyCumulativeNumber_default = ReadOnlyCumulativeNumber;
|
|
963
|
+
|
|
964
|
+
// src/fields/readonly/ReadOnlyRichText.tsx
|
|
965
|
+
import { jsx as jsx28 } from "react/jsx-runtime";
|
|
966
|
+
var ReadOnlyRichText = (props) => {
|
|
967
|
+
const { value } = props;
|
|
968
|
+
return /* @__PURE__ */ jsx28(
|
|
969
|
+
"div",
|
|
970
|
+
{
|
|
971
|
+
className: "fe-read-only-rich-text",
|
|
972
|
+
"data-field-type": "ReadOnlyRichText",
|
|
973
|
+
"data-field-state": "readonly",
|
|
974
|
+
dangerouslySetInnerHTML: { __html: value || "" }
|
|
975
|
+
}
|
|
976
|
+
);
|
|
977
|
+
};
|
|
978
|
+
var ReadOnlyRichText_default = ReadOnlyRichText;
|
|
979
|
+
|
|
980
|
+
// src/fields/readonly/ReadOnlyWithButton.tsx
|
|
981
|
+
import { jsx as jsx29, jsxs as jsxs7 } from "react/jsx-runtime";
|
|
982
|
+
var ReadOnlyWithButton = (props) => {
|
|
983
|
+
const { fieldName, value, config } = props;
|
|
984
|
+
return /* @__PURE__ */ jsxs7(
|
|
985
|
+
"div",
|
|
986
|
+
{
|
|
987
|
+
className: `fe-read-only-with-button ${config?.containerClassName ?? ""}`,
|
|
988
|
+
"data-field-type": "ReadOnlyWithButton",
|
|
989
|
+
"data-field-state": "readonly",
|
|
990
|
+
children: [
|
|
991
|
+
/* @__PURE__ */ jsx29(ReadOnlyText, { fieldName, value: `${value}` }),
|
|
992
|
+
config?.buttonText && /* @__PURE__ */ jsx29(
|
|
993
|
+
"button",
|
|
994
|
+
{
|
|
995
|
+
type: "button",
|
|
996
|
+
className: "fe-btn fe-btn--secondary",
|
|
997
|
+
onClick: config.onButtonClick,
|
|
998
|
+
children: config.buttonText
|
|
999
|
+
}
|
|
1000
|
+
)
|
|
1001
|
+
]
|
|
1002
|
+
}
|
|
1003
|
+
);
|
|
1004
|
+
};
|
|
1005
|
+
var ReadOnlyWithButton_default = ReadOnlyWithButton;
|
|
1006
|
+
|
|
441
1007
|
// src/components/StatusMessage.tsx
|
|
442
1008
|
import { FormStrings as FormStrings2 } from "@form-eng/core";
|
|
443
|
-
import { jsx as
|
|
1009
|
+
import { jsx as jsx30, jsxs as jsxs8 } from "react/jsx-runtime";
|
|
444
1010
|
var StatusMessage = (props) => {
|
|
445
1011
|
const { id, error, errorCount, savePending, saving } = props;
|
|
446
|
-
return /* @__PURE__ */
|
|
1012
|
+
return /* @__PURE__ */ jsx30("div", { className: "fe-status-message", children: error ? /* @__PURE__ */ jsx30("span", { id, role: "alert", style: { color: "var(--mantine-color-red-6, #fa5252)" }, children: error.message || "Error" }) : savePending ? /* @__PURE__ */ jsxs8("span", { id, role: "alert", style: { color: "var(--mantine-color-orange-6, #fd7e14)" }, children: [
|
|
447
1013
|
FormStrings2.autoSavePending,
|
|
448
1014
|
" (",
|
|
449
1015
|
errorCount,
|
|
450
1016
|
" ",
|
|
451
1017
|
FormStrings2.remaining,
|
|
452
1018
|
")"
|
|
453
|
-
] }) : saving ? /* @__PURE__ */
|
|
1019
|
+
] }) : saving ? /* @__PURE__ */ jsx30("span", { id, role: "status", style: { color: "var(--mantine-color-gray-6, #868e96)" }, children: FormStrings2.saving }) : null });
|
|
454
1020
|
};
|
|
455
1021
|
|
|
456
1022
|
// src/components/FormLoading.tsx
|
|
457
1023
|
import { FormConstants } from "@form-eng/core";
|
|
458
|
-
import { jsx as
|
|
1024
|
+
import { jsx as jsx31, jsxs as jsxs9 } from "react/jsx-runtime";
|
|
459
1025
|
var FormLoading = (props) => {
|
|
460
1026
|
const { loadingShimmerCount, loadingFieldShimmerHeight, inPanel, hideTitleShimmer } = props;
|
|
461
1027
|
const count = loadingShimmerCount || FormConstants.loadingShimmerCount;
|
|
462
1028
|
const height = loadingFieldShimmerHeight || FormConstants.loadingFieldShimmerHeight;
|
|
463
|
-
return /* @__PURE__ */
|
|
1029
|
+
return /* @__PURE__ */ jsx31(
|
|
464
1030
|
"div",
|
|
465
1031
|
{
|
|
466
1032
|
className: `fe-form-loading ${inPanel ? "fe-form-loading--panel" : ""}`,
|
|
467
1033
|
role: "status",
|
|
468
1034
|
"aria-label": "Loading form",
|
|
469
|
-
children: [...Array(count)].map((_, i) => /* @__PURE__ */
|
|
470
|
-
!hideTitleShimmer && /* @__PURE__ */
|
|
471
|
-
/* @__PURE__ */
|
|
1035
|
+
children: [...Array(count)].map((_, i) => /* @__PURE__ */ jsxs9("div", { style: { marginBottom: 16 }, children: [
|
|
1036
|
+
!hideTitleShimmer && /* @__PURE__ */ jsx31("div", { className: "fe-skeleton", style: { width: "33%", height: 16, marginBottom: 8, background: "var(--mantine-color-gray-2, #e9ecef)", borderRadius: 4 } }),
|
|
1037
|
+
/* @__PURE__ */ jsx31("div", { className: "fe-skeleton", style: { width: "100%", height, background: "var(--mantine-color-gray-2, #e9ecef)", borderRadius: 4 } })
|
|
472
1038
|
] }, `fe-loading-${i}`))
|
|
473
1039
|
}
|
|
474
1040
|
);
|
|
@@ -476,45 +1042,76 @@ var FormLoading = (props) => {
|
|
|
476
1042
|
|
|
477
1043
|
// src/registry.ts
|
|
478
1044
|
import { ComponentTypes } from "@form-eng/core";
|
|
479
|
-
import
|
|
1045
|
+
import React6 from "react";
|
|
480
1046
|
function createMantineFieldRegistry() {
|
|
481
1047
|
return {
|
|
482
|
-
[ComponentTypes.Textbox]:
|
|
483
|
-
[ComponentTypes.Number]:
|
|
484
|
-
[ComponentTypes.Toggle]:
|
|
485
|
-
[ComponentTypes.Dropdown]:
|
|
486
|
-
[ComponentTypes.SimpleDropdown]:
|
|
487
|
-
[ComponentTypes.MultiSelect]:
|
|
488
|
-
[ComponentTypes.DateControl]:
|
|
489
|
-
[ComponentTypes.Slider]:
|
|
490
|
-
[ComponentTypes.RadioGroup]:
|
|
491
|
-
[ComponentTypes.CheckboxGroup]:
|
|
492
|
-
[ComponentTypes.Textarea]:
|
|
493
|
-
[ComponentTypes.Fragment]:
|
|
494
|
-
[ComponentTypes.ReadOnly]:
|
|
1048
|
+
[ComponentTypes.Textbox]: React6.createElement(Textbox_default),
|
|
1049
|
+
[ComponentTypes.Number]: React6.createElement(Number_default),
|
|
1050
|
+
[ComponentTypes.Toggle]: React6.createElement(Toggle_default),
|
|
1051
|
+
[ComponentTypes.Dropdown]: React6.createElement(Dropdown_default),
|
|
1052
|
+
[ComponentTypes.SimpleDropdown]: React6.createElement(SimpleDropdown_default),
|
|
1053
|
+
[ComponentTypes.MultiSelect]: React6.createElement(MultiSelect_default),
|
|
1054
|
+
[ComponentTypes.DateControl]: React6.createElement(DateControl_default),
|
|
1055
|
+
[ComponentTypes.Slider]: React6.createElement(Slider_default),
|
|
1056
|
+
[ComponentTypes.RadioGroup]: React6.createElement(RadioGroup_default),
|
|
1057
|
+
[ComponentTypes.CheckboxGroup]: React6.createElement(CheckboxGroup_default),
|
|
1058
|
+
[ComponentTypes.Textarea]: React6.createElement(Textarea_default),
|
|
1059
|
+
[ComponentTypes.Fragment]: React6.createElement(DynamicFragment_default),
|
|
1060
|
+
[ComponentTypes.ReadOnly]: React6.createElement(ReadOnly_default),
|
|
1061
|
+
[ComponentTypes.Rating]: React6.createElement(Rating_default),
|
|
1062
|
+
[ComponentTypes.Autocomplete]: React6.createElement(Autocomplete_default),
|
|
1063
|
+
[ComponentTypes.DateTime]: React6.createElement(DateTime_default),
|
|
1064
|
+
[ComponentTypes.DateRange]: React6.createElement(DateRange_default),
|
|
1065
|
+
[ComponentTypes.PhoneInput]: React6.createElement(PhoneInput_default),
|
|
1066
|
+
[ComponentTypes.FileUpload]: React6.createElement(FileUpload_default),
|
|
1067
|
+
[ComponentTypes.ColorPicker]: React6.createElement(ColorPicker_default),
|
|
1068
|
+
[ComponentTypes.MultiSelectSearch]: React6.createElement(MultiSelectSearch_default),
|
|
1069
|
+
[ComponentTypes.StatusDropdown]: React6.createElement(StatusDropdown_default),
|
|
1070
|
+
[ComponentTypes.DocumentLinks]: React6.createElement(DocumentLinks_default),
|
|
1071
|
+
[ComponentTypes.ReadOnlyArray]: React6.createElement(ReadOnlyArray_default),
|
|
1072
|
+
[ComponentTypes.ReadOnlyDateTime]: React6.createElement(ReadOnlyDateTime_default),
|
|
1073
|
+
[ComponentTypes.ReadOnlyCumulativeNumber]: React6.createElement(ReadOnlyCumulativeNumber_default),
|
|
1074
|
+
[ComponentTypes.ReadOnlyRichText]: React6.createElement(ReadOnlyRichText_default),
|
|
1075
|
+
[ComponentTypes.ReadOnlyWithButton]: React6.createElement(ReadOnlyWithButton_default)
|
|
495
1076
|
};
|
|
496
1077
|
}
|
|
497
1078
|
export {
|
|
1079
|
+
Autocomplete_default as Autocomplete,
|
|
498
1080
|
CheckboxGroup_default as CheckboxGroup,
|
|
1081
|
+
ColorPicker_default as ColorPicker,
|
|
499
1082
|
DateControl_default as DateControl,
|
|
1083
|
+
DateRange_default as DateRange,
|
|
1084
|
+
DateTime_default as DateTime,
|
|
1085
|
+
DocumentLinks_default as DocumentLinks,
|
|
500
1086
|
DocumentLinksStrings,
|
|
501
1087
|
Dropdown_default as Dropdown,
|
|
502
1088
|
DynamicFragment_default as DynamicFragment,
|
|
503
1089
|
FieldClassName,
|
|
1090
|
+
FileUpload_default as FileUpload,
|
|
504
1091
|
FormLoading,
|
|
505
1092
|
GetFieldDataTestId,
|
|
506
1093
|
MultiSelect_default as MultiSelect,
|
|
1094
|
+
MultiSelectSearch_default as MultiSelectSearch,
|
|
507
1095
|
Number_default as Number,
|
|
1096
|
+
PhoneInput_default as PhoneInput,
|
|
508
1097
|
RadioGroup_default as RadioGroup,
|
|
1098
|
+
Rating_default as Rating,
|
|
509
1099
|
ReadOnly_default as ReadOnly,
|
|
1100
|
+
ReadOnlyArray_default as ReadOnlyArray,
|
|
1101
|
+
ReadOnlyCumulativeNumber_default as ReadOnlyCumulativeNumber,
|
|
1102
|
+
ReadOnlyDateTime_default as ReadOnlyDateTime,
|
|
1103
|
+
ReadOnlyRichText_default as ReadOnlyRichText,
|
|
510
1104
|
ReadOnlyText,
|
|
1105
|
+
ReadOnlyWithButton_default as ReadOnlyWithButton,
|
|
511
1106
|
SimpleDropdown_default as SimpleDropdown,
|
|
512
1107
|
Slider_default as Slider,
|
|
1108
|
+
StatusDropdown_default as StatusDropdown,
|
|
513
1109
|
StatusMessage,
|
|
514
1110
|
Textarea_default as Textarea,
|
|
515
1111
|
Textbox_default as Textbox,
|
|
516
1112
|
Toggle_default as Toggle,
|
|
517
1113
|
createMantineFieldRegistry,
|
|
518
|
-
formatDateTime
|
|
1114
|
+
formatDateTime,
|
|
1115
|
+
getFieldState
|
|
519
1116
|
};
|
|
520
1117
|
//# sourceMappingURL=index.mjs.map
|