@form-eng/react-aria 1.5.3 → 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 +537 -25
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +517 -21
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -601,31 +601,496 @@ var CheckboxGroup = (props) => {
|
|
|
601
601
|
};
|
|
602
602
|
var CheckboxGroup_default = CheckboxGroup;
|
|
603
603
|
|
|
604
|
+
// src/fields/Rating.tsx
|
|
605
|
+
import { jsx as jsx15, jsxs as jsxs7 } from "react/jsx-runtime";
|
|
606
|
+
var Rating = (props) => {
|
|
607
|
+
const { fieldName, programName, entityType, entityId, value, readOnly, error, required, config, setFieldValue } = props;
|
|
608
|
+
const max = config?.max ?? 5;
|
|
609
|
+
const rating = value ?? 0;
|
|
610
|
+
if (readOnly) {
|
|
611
|
+
return /* @__PURE__ */ jsx15(ReadOnlyText, { fieldName, value: String(rating) });
|
|
612
|
+
}
|
|
613
|
+
const stars = Array.from({ length: max }, (_, i) => i + 1);
|
|
614
|
+
return /* @__PURE__ */ jsx15(
|
|
615
|
+
"div",
|
|
616
|
+
{
|
|
617
|
+
className: "df-rating",
|
|
618
|
+
role: "radiogroup",
|
|
619
|
+
"aria-label": `Rating, ${rating} of ${max}`,
|
|
620
|
+
"aria-invalid": !!error,
|
|
621
|
+
"aria-required": required,
|
|
622
|
+
"data-field-type": "Rating",
|
|
623
|
+
"data-field-state": getFieldState({ error, required, readOnly }),
|
|
624
|
+
"data-testid": GetFieldDataTestId(fieldName, programName, entityType, entityId),
|
|
625
|
+
children: stars.map((star) => /* @__PURE__ */ jsxs7("label", { className: "df-rating__star-label", children: [
|
|
626
|
+
/* @__PURE__ */ jsx15(
|
|
627
|
+
"input",
|
|
628
|
+
{
|
|
629
|
+
type: "radio",
|
|
630
|
+
className: "df-rating__input",
|
|
631
|
+
name: fieldName,
|
|
632
|
+
value: String(star),
|
|
633
|
+
checked: rating === star,
|
|
634
|
+
onChange: () => setFieldValue(fieldName, star),
|
|
635
|
+
"aria-label": `${star} star${star !== 1 ? "s" : ""}`
|
|
636
|
+
}
|
|
637
|
+
),
|
|
638
|
+
/* @__PURE__ */ jsx15("span", { className: `df-rating__star${star <= rating ? " df-rating__star--filled" : ""}`, "aria-hidden": "true", children: star <= rating ? "\u2605" : "\u2606" })
|
|
639
|
+
] }, star))
|
|
640
|
+
}
|
|
641
|
+
);
|
|
642
|
+
};
|
|
643
|
+
var Rating_default = Rating;
|
|
644
|
+
|
|
645
|
+
// src/fields/Autocomplete.tsx
|
|
646
|
+
import { ComboBox, Input as Input3, Button as Button3, Popover as Popover3, ListBox as ListBox3, ListBoxItem as ListBoxItem3 } from "react-aria-components";
|
|
647
|
+
import { jsx as jsx16, jsxs as jsxs8 } from "react/jsx-runtime";
|
|
648
|
+
var Autocomplete = (props) => {
|
|
649
|
+
const { fieldName, programName, entityType, entityId, value, readOnly, error, required, placeholder, options, setFieldValue } = props;
|
|
650
|
+
const selectedLabel = options?.find((o) => String(o.value) === String(value))?.label ?? value ?? "";
|
|
651
|
+
if (readOnly) {
|
|
652
|
+
return /* @__PURE__ */ jsx16(ReadOnlyText, { fieldName, value: selectedLabel });
|
|
653
|
+
}
|
|
654
|
+
return /* @__PURE__ */ jsxs8(
|
|
655
|
+
ComboBox,
|
|
656
|
+
{
|
|
657
|
+
className: "df-autocomplete",
|
|
658
|
+
"aria-label": fieldName,
|
|
659
|
+
defaultInputValue: selectedLabel,
|
|
660
|
+
onSelectionChange: (key) => {
|
|
661
|
+
if (key !== null) setFieldValue(fieldName, String(key));
|
|
662
|
+
},
|
|
663
|
+
onInputChange: (text) => {
|
|
664
|
+
const match = options?.find((o) => o.label.toLowerCase() === text.toLowerCase());
|
|
665
|
+
setFieldValue(fieldName, match ? String(match.value) : text);
|
|
666
|
+
},
|
|
667
|
+
"data-testid": GetFieldDataTestId(fieldName, programName, entityType, entityId),
|
|
668
|
+
isRequired: required,
|
|
669
|
+
isInvalid: !!error,
|
|
670
|
+
children: [
|
|
671
|
+
/* @__PURE__ */ jsx16(Input3, { className: "df-autocomplete__input", placeholder }),
|
|
672
|
+
/* @__PURE__ */ jsx16(Button3, { className: "df-autocomplete__button", children: "\u25BC" }),
|
|
673
|
+
/* @__PURE__ */ jsx16(Popover3, { children: /* @__PURE__ */ jsx16(ListBox3, { className: "df-autocomplete__listbox", children: options?.map((option) => /* @__PURE__ */ jsx16(ListBoxItem3, { id: String(option.value), children: option.label }, String(option.value))) }) })
|
|
674
|
+
]
|
|
675
|
+
}
|
|
676
|
+
);
|
|
677
|
+
};
|
|
678
|
+
var Autocomplete_default = Autocomplete;
|
|
679
|
+
|
|
680
|
+
// src/fields/DateTime.tsx
|
|
681
|
+
import { formatDateTimeValue } from "@form-eng/core";
|
|
682
|
+
import { jsx as jsx17 } from "react/jsx-runtime";
|
|
683
|
+
var DateTime = (props) => {
|
|
684
|
+
const { fieldName, programName, entityType, entityId, value, readOnly, error, required, config, setFieldValue } = props;
|
|
685
|
+
const minDateTime = config?.minDateTime;
|
|
686
|
+
const maxDateTime = config?.maxDateTime;
|
|
687
|
+
if (readOnly) {
|
|
688
|
+
return /* @__PURE__ */ jsx17(ReadOnlyText, { fieldName, value: formatDateTimeValue(value) });
|
|
689
|
+
}
|
|
690
|
+
const onChange = (event) => {
|
|
691
|
+
setFieldValue(fieldName, event.target.value || null);
|
|
692
|
+
};
|
|
693
|
+
return /* @__PURE__ */ jsx17(
|
|
694
|
+
"input",
|
|
695
|
+
{
|
|
696
|
+
type: "datetime-local",
|
|
697
|
+
className: "df-date-time",
|
|
698
|
+
"data-field-type": "DateTime",
|
|
699
|
+
"data-field-state": getFieldState({ error, required, readOnly }),
|
|
700
|
+
value: value ?? "",
|
|
701
|
+
min: minDateTime,
|
|
702
|
+
max: maxDateTime,
|
|
703
|
+
onChange,
|
|
704
|
+
"aria-invalid": !!error,
|
|
705
|
+
"aria-required": required,
|
|
706
|
+
"data-testid": GetFieldDataTestId(fieldName, programName, entityType, entityId)
|
|
707
|
+
}
|
|
708
|
+
);
|
|
709
|
+
};
|
|
710
|
+
var DateTime_default = DateTime;
|
|
711
|
+
|
|
712
|
+
// src/fields/DateRange.tsx
|
|
713
|
+
import { formatDateRange } from "@form-eng/core";
|
|
714
|
+
import { jsx as jsx18, jsxs as jsxs9 } from "react/jsx-runtime";
|
|
715
|
+
var DateRange = (props) => {
|
|
716
|
+
const { fieldName, programName, entityType, entityId, value, readOnly, error, required, config, setFieldValue } = props;
|
|
717
|
+
const rangeValue = value ?? { start: "", end: "" };
|
|
718
|
+
const minDate = config?.minDate;
|
|
719
|
+
const maxDate = config?.maxDate;
|
|
720
|
+
const rangeError = rangeValue.start && rangeValue.end && rangeValue.start > rangeValue.end ? "Start date must be on or before end date." : void 0;
|
|
721
|
+
if (readOnly) {
|
|
722
|
+
return /* @__PURE__ */ jsx18(ReadOnlyText, { fieldName, value: formatDateRange(value) });
|
|
723
|
+
}
|
|
724
|
+
const onStartChange = (event) => {
|
|
725
|
+
setFieldValue(fieldName, { ...rangeValue, start: event.target.value });
|
|
726
|
+
};
|
|
727
|
+
const onEndChange = (event) => {
|
|
728
|
+
setFieldValue(fieldName, { ...rangeValue, end: event.target.value });
|
|
729
|
+
};
|
|
730
|
+
return /* @__PURE__ */ jsxs9(
|
|
731
|
+
"div",
|
|
732
|
+
{
|
|
733
|
+
className: "fe-date-range",
|
|
734
|
+
"data-field-type": "DateRange",
|
|
735
|
+
"data-field-state": getFieldState({ error, required, readOnly }),
|
|
736
|
+
"data-testid": GetFieldDataTestId(fieldName, programName, entityType, entityId),
|
|
737
|
+
children: [
|
|
738
|
+
/* @__PURE__ */ jsxs9("div", { className: "fe-date-range__inputs", children: [
|
|
739
|
+
/* @__PURE__ */ jsxs9("div", { className: "fe-date-range__from", children: [
|
|
740
|
+
/* @__PURE__ */ jsx18("label", { htmlFor: `${fieldName}-start`, className: "fe-date-range__label", children: "From" }),
|
|
741
|
+
/* @__PURE__ */ jsx18(
|
|
742
|
+
"input",
|
|
743
|
+
{
|
|
744
|
+
id: `${fieldName}-start`,
|
|
745
|
+
type: "date",
|
|
746
|
+
className: "fe-date-range__input fe-date-range__input--start",
|
|
747
|
+
value: rangeValue.start,
|
|
748
|
+
min: minDate,
|
|
749
|
+
max: rangeValue.end || maxDate,
|
|
750
|
+
onChange: onStartChange,
|
|
751
|
+
"aria-invalid": !!error,
|
|
752
|
+
"aria-required": required,
|
|
753
|
+
"aria-label": "Start date"
|
|
754
|
+
}
|
|
755
|
+
)
|
|
756
|
+
] }),
|
|
757
|
+
/* @__PURE__ */ jsxs9("div", { className: "fe-date-range__to", children: [
|
|
758
|
+
/* @__PURE__ */ jsx18("label", { htmlFor: `${fieldName}-end`, className: "fe-date-range__label", children: "To" }),
|
|
759
|
+
/* @__PURE__ */ jsx18(
|
|
760
|
+
"input",
|
|
761
|
+
{
|
|
762
|
+
id: `${fieldName}-end`,
|
|
763
|
+
type: "date",
|
|
764
|
+
className: "fe-date-range__input fe-date-range__input--end",
|
|
765
|
+
value: rangeValue.end,
|
|
766
|
+
min: rangeValue.start || minDate,
|
|
767
|
+
max: maxDate,
|
|
768
|
+
onChange: onEndChange,
|
|
769
|
+
"aria-label": "End date"
|
|
770
|
+
}
|
|
771
|
+
)
|
|
772
|
+
] })
|
|
773
|
+
] }),
|
|
774
|
+
rangeError && /* @__PURE__ */ jsx18("span", { className: "fe-date-range__range-error", role: "alert", children: rangeError })
|
|
775
|
+
]
|
|
776
|
+
}
|
|
777
|
+
);
|
|
778
|
+
};
|
|
779
|
+
var DateRange_default = DateRange;
|
|
780
|
+
|
|
781
|
+
// src/fields/PhoneInput.tsx
|
|
782
|
+
import { extractDigits, formatPhone } from "@form-eng/core";
|
|
783
|
+
import { jsx as jsx19 } from "react/jsx-runtime";
|
|
784
|
+
var PhoneInput = (props) => {
|
|
785
|
+
const { fieldName, programName, entityType, entityId, value, readOnly, error, required, config, setFieldValue } = props;
|
|
786
|
+
const format = config?.format ?? "us";
|
|
787
|
+
if (readOnly) {
|
|
788
|
+
return /* @__PURE__ */ jsx19(ReadOnlyText, { fieldName, value: value ?? "" });
|
|
789
|
+
}
|
|
790
|
+
const onChange = (event) => {
|
|
791
|
+
const digits = extractDigits(event.target.value);
|
|
792
|
+
const formatted = formatPhone(digits, format);
|
|
793
|
+
setFieldValue(fieldName, formatted);
|
|
794
|
+
};
|
|
795
|
+
return /* @__PURE__ */ jsx19(
|
|
796
|
+
"input",
|
|
797
|
+
{
|
|
798
|
+
type: "tel",
|
|
799
|
+
className: "fe-phone-input",
|
|
800
|
+
"data-field-type": "PhoneInput",
|
|
801
|
+
"data-field-state": getFieldState({ error, required, readOnly }),
|
|
802
|
+
value: value ?? "",
|
|
803
|
+
onChange,
|
|
804
|
+
"aria-invalid": !!error,
|
|
805
|
+
"aria-required": required,
|
|
806
|
+
"data-testid": GetFieldDataTestId(fieldName, programName, entityType, entityId)
|
|
807
|
+
}
|
|
808
|
+
);
|
|
809
|
+
};
|
|
810
|
+
var PhoneInput_default = PhoneInput;
|
|
811
|
+
|
|
812
|
+
// src/fields/FileUpload.tsx
|
|
813
|
+
import { MAX_FILE_SIZE_MB_DEFAULT, getFileNames } from "@form-eng/core";
|
|
814
|
+
import React3, { useRef } from "react";
|
|
815
|
+
import { jsx as jsx20, jsxs as jsxs10 } from "react/jsx-runtime";
|
|
816
|
+
var FileUpload = (props) => {
|
|
817
|
+
const { fieldName, programName, entityType, entityId, value, readOnly, error, required, config, setFieldValue } = props;
|
|
818
|
+
const inputRef = useRef(null);
|
|
819
|
+
const multiple = config?.multiple ?? false;
|
|
820
|
+
const accept = config?.accept;
|
|
821
|
+
const maxSizeMb = config?.maxSizeMb ?? MAX_FILE_SIZE_MB_DEFAULT;
|
|
822
|
+
const maxSizeBytes = maxSizeMb * 1024 * 1024;
|
|
823
|
+
const [sizeError, setSizeError] = React3.useState(void 0);
|
|
824
|
+
if (readOnly) {
|
|
825
|
+
return /* @__PURE__ */ jsx20(ReadOnlyText, { fieldName, value: getFileNames(value) });
|
|
826
|
+
}
|
|
827
|
+
const onChange = (event) => {
|
|
828
|
+
const files = event.target.files;
|
|
829
|
+
if (!files || files.length === 0) {
|
|
830
|
+
setFieldValue(fieldName, null);
|
|
831
|
+
setSizeError(void 0);
|
|
832
|
+
return;
|
|
833
|
+
}
|
|
834
|
+
const oversized = Array.from(files).find((f) => f.size > maxSizeBytes);
|
|
835
|
+
if (oversized) {
|
|
836
|
+
setSizeError(`"${oversized.name}" exceeds the ${maxSizeMb} MB size limit.`);
|
|
837
|
+
event.target.value = "";
|
|
838
|
+
setFieldValue(fieldName, null);
|
|
839
|
+
return;
|
|
840
|
+
}
|
|
841
|
+
setSizeError(void 0);
|
|
842
|
+
setFieldValue(fieldName, multiple ? Array.from(files) : files[0]);
|
|
843
|
+
};
|
|
844
|
+
const fileNames = getFileNames(value);
|
|
845
|
+
return /* @__PURE__ */ jsxs10(
|
|
846
|
+
"div",
|
|
847
|
+
{
|
|
848
|
+
className: "fe-file-upload",
|
|
849
|
+
"data-field-type": "FileUpload",
|
|
850
|
+
"data-field-state": getFieldState({ error, required, readOnly }),
|
|
851
|
+
"data-testid": GetFieldDataTestId(fieldName, programName, entityType, entityId),
|
|
852
|
+
children: [
|
|
853
|
+
/* @__PURE__ */ jsx20(
|
|
854
|
+
"input",
|
|
855
|
+
{
|
|
856
|
+
ref: inputRef,
|
|
857
|
+
type: "file",
|
|
858
|
+
className: "fe-file-upload__input",
|
|
859
|
+
multiple,
|
|
860
|
+
accept,
|
|
861
|
+
onChange,
|
|
862
|
+
"aria-invalid": !!error,
|
|
863
|
+
"aria-required": required,
|
|
864
|
+
style: { display: "none" },
|
|
865
|
+
"aria-hidden": "true"
|
|
866
|
+
}
|
|
867
|
+
),
|
|
868
|
+
/* @__PURE__ */ jsx20(
|
|
869
|
+
"button",
|
|
870
|
+
{
|
|
871
|
+
type: "button",
|
|
872
|
+
className: "fe-file-upload__button",
|
|
873
|
+
onClick: () => inputRef.current?.click(),
|
|
874
|
+
children: fileNames ? "Change file" : "Choose file"
|
|
875
|
+
}
|
|
876
|
+
),
|
|
877
|
+
fileNames && /* @__PURE__ */ jsx20("span", { className: "fe-file-upload__filenames", children: fileNames }),
|
|
878
|
+
sizeError && /* @__PURE__ */ jsx20("span", { className: "fe-file-upload__size-error", role: "alert", children: sizeError })
|
|
879
|
+
]
|
|
880
|
+
}
|
|
881
|
+
);
|
|
882
|
+
};
|
|
883
|
+
var FileUpload_default = FileUpload;
|
|
884
|
+
|
|
885
|
+
// src/fields/ColorPicker.tsx
|
|
886
|
+
import { jsx as jsx21, jsxs as jsxs11 } from "react/jsx-runtime";
|
|
887
|
+
var ColorPicker = (props) => {
|
|
888
|
+
const { fieldName, programName, entityType, entityId, value, readOnly, error, required, setFieldValue } = props;
|
|
889
|
+
const color = value ?? "#000000";
|
|
890
|
+
const onChange = (event) => {
|
|
891
|
+
setFieldValue(fieldName, event.target.value);
|
|
892
|
+
};
|
|
893
|
+
if (readOnly) {
|
|
894
|
+
return /* @__PURE__ */ jsx21(ReadOnlyText, { fieldName, value: color });
|
|
895
|
+
}
|
|
896
|
+
return /* @__PURE__ */ jsxs11("div", { className: "fe-color-picker", "data-field-type": "ColorPicker", "data-field-state": getFieldState({ error, required, readOnly }), style: { display: "flex", alignItems: "center", gap: "8px" }, children: [
|
|
897
|
+
/* @__PURE__ */ jsx21("input", { type: "color", className: "fe-color-picker__input", value: color, onChange, "aria-invalid": !!error, "aria-required": required, "data-testid": GetFieldDataTestId(fieldName, programName, entityType, entityId) }),
|
|
898
|
+
/* @__PURE__ */ jsx21("span", { className: "fe-color-picker__value", children: color })
|
|
899
|
+
] });
|
|
900
|
+
};
|
|
901
|
+
var ColorPicker_default = ColorPicker;
|
|
902
|
+
|
|
903
|
+
// src/fields/MultiSelectSearch.tsx
|
|
904
|
+
import { useState as useState2, useMemo } from "react";
|
|
905
|
+
import { jsx as jsx22, jsxs as jsxs12 } from "react/jsx-runtime";
|
|
906
|
+
var MultiSelectSearch = (props) => {
|
|
907
|
+
const { fieldName, programName, entityType, entityId, value, readOnly, error, required, options, setFieldValue } = props;
|
|
908
|
+
const [searchTerm, setSearchTerm] = useState2("");
|
|
909
|
+
const selectedValues = value ?? [];
|
|
910
|
+
const filteredOptions = useMemo(() => {
|
|
911
|
+
if (!searchTerm) return options ?? [];
|
|
912
|
+
const lower = searchTerm.toLowerCase();
|
|
913
|
+
return (options ?? []).filter((o) => o.label.toLowerCase().includes(lower));
|
|
914
|
+
}, [options, searchTerm]);
|
|
915
|
+
const onCheckChange = (optionValue, checked) => {
|
|
916
|
+
const updated = checked ? [...selectedValues, optionValue] : selectedValues.filter((v) => v !== optionValue);
|
|
917
|
+
setFieldValue(fieldName, updated, false, 3e3);
|
|
918
|
+
};
|
|
919
|
+
if (readOnly) {
|
|
920
|
+
return selectedValues.length > 0 ? /* @__PURE__ */ jsx22("ul", { className: "fe-multi-select-search-readonly", "data-field-type": "MultiSelectSearch", "data-field-state": "readonly", children: selectedValues.map((v, i) => /* @__PURE__ */ jsx22("li", { children: v }, i)) }) : /* @__PURE__ */ jsx22("span", { className: "fe-read-only-text", children: "-" });
|
|
921
|
+
}
|
|
922
|
+
return /* @__PURE__ */ jsxs12("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: [
|
|
923
|
+
/* @__PURE__ */ jsx22("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}` }),
|
|
924
|
+
/* @__PURE__ */ jsxs12("fieldset", { className: "fe-multi-select-search__options", "aria-invalid": !!error, "aria-required": required, children: [
|
|
925
|
+
/* @__PURE__ */ jsx22("legend", { className: "fe-sr-only", children: "Options" }),
|
|
926
|
+
filteredOptions.map((option) => {
|
|
927
|
+
const optVal = String(option.value);
|
|
928
|
+
const isChecked = selectedValues.includes(optVal);
|
|
929
|
+
return /* @__PURE__ */ jsxs12("label", { className: "fe-multi-select-search__option", children: [
|
|
930
|
+
/* @__PURE__ */ jsx22("input", { type: "checkbox", checked: isChecked, disabled: option.disabled, onChange: (e) => onCheckChange(optVal, e.target.checked) }),
|
|
931
|
+
/* @__PURE__ */ jsx22("span", { children: option.label })
|
|
932
|
+
] }, optVal);
|
|
933
|
+
})
|
|
934
|
+
] })
|
|
935
|
+
] });
|
|
936
|
+
};
|
|
937
|
+
var MultiSelectSearch_default = MultiSelectSearch;
|
|
938
|
+
|
|
939
|
+
// src/fields/StatusDropdown.tsx
|
|
940
|
+
import { jsx as jsx23, jsxs as jsxs13 } from "react/jsx-runtime";
|
|
941
|
+
var StatusDropdown = (props) => {
|
|
942
|
+
const { fieldName, programName, entityType, entityId, value, readOnly, error, required, config, options, placeholder, setFieldValue } = props;
|
|
943
|
+
const onChange = (event) => {
|
|
944
|
+
setFieldValue(fieldName, event.target.value);
|
|
945
|
+
};
|
|
946
|
+
const statusColor = config?.statusColors?.[value];
|
|
947
|
+
if (readOnly) {
|
|
948
|
+
return /* @__PURE__ */ jsxs13("div", { className: "fe-status-dropdown fe-status-dropdown--readonly", "data-field-type": "StatusDropdown", "data-field-state": "readonly", children: [
|
|
949
|
+
statusColor && /* @__PURE__ */ jsx23("span", { className: "fe-status-dropdown__indicator", style: { backgroundColor: statusColor }, "aria-hidden": "true" }),
|
|
950
|
+
/* @__PURE__ */ jsx23(ReadOnlyText, { fieldName, value })
|
|
951
|
+
] });
|
|
952
|
+
}
|
|
953
|
+
return /* @__PURE__ */ jsxs13("div", { className: "fe-status-dropdown", "data-field-type": "StatusDropdown", "data-field-state": getFieldState({ error, required, readOnly }), children: [
|
|
954
|
+
statusColor && /* @__PURE__ */ jsx23("span", { className: "fe-status-dropdown__indicator", style: { backgroundColor: statusColor }, "aria-hidden": "true" }),
|
|
955
|
+
/* @__PURE__ */ jsxs13("select", { className: "fe-status-dropdown__select", value: value ?? "", onChange, "aria-invalid": !!error, "aria-required": required, "data-testid": GetFieldDataTestId(fieldName, programName, entityType, entityId), children: [
|
|
956
|
+
/* @__PURE__ */ jsx23("option", { value: "", children: placeholder ?? config?.placeHolder ?? "" }),
|
|
957
|
+
options?.map((option) => /* @__PURE__ */ jsx23("option", { value: String(option.value), disabled: option.disabled, children: option.label }, String(option.value)))
|
|
958
|
+
] })
|
|
959
|
+
] });
|
|
960
|
+
};
|
|
961
|
+
var StatusDropdown_default = StatusDropdown;
|
|
962
|
+
|
|
963
|
+
// src/fields/DocumentLinks.tsx
|
|
964
|
+
import { useState as useState3 } from "react";
|
|
965
|
+
import { useFormContext } from "react-hook-form";
|
|
966
|
+
import { jsx as jsx24, jsxs as jsxs14 } from "react/jsx-runtime";
|
|
967
|
+
var DocumentLinks = (props) => {
|
|
968
|
+
const { fieldName, programName, entityType, entityId, value, readOnly, error, required, setFieldValue } = props;
|
|
969
|
+
const { watch } = useFormContext();
|
|
970
|
+
const documentLinks = watch(`${fieldName}`) ?? [];
|
|
971
|
+
const [newUrl, setNewUrl] = useState3("");
|
|
972
|
+
const [newText, setNewText] = useState3("");
|
|
973
|
+
const onAddLink = () => {
|
|
974
|
+
if (!newUrl) return;
|
|
975
|
+
const link = { url: newUrl, title: newText || newUrl };
|
|
976
|
+
setFieldValue(fieldName, [...documentLinks, link]);
|
|
977
|
+
setNewUrl("");
|
|
978
|
+
setNewText("");
|
|
979
|
+
};
|
|
980
|
+
const onDeleteLink = (index) => {
|
|
981
|
+
const updated = [...documentLinks];
|
|
982
|
+
updated.splice(index, 1);
|
|
983
|
+
setFieldValue(fieldName, updated);
|
|
984
|
+
};
|
|
985
|
+
if (readOnly) {
|
|
986
|
+
return /* @__PURE__ */ jsx24("ul", { className: "fe-document-links fe-document-links--readonly", "data-field-type": "DocumentLinks", "data-field-state": "readonly", children: value?.map((link, i) => /* @__PURE__ */ jsx24("li", { className: "fe-document-links__item", children: /* @__PURE__ */ jsx24("a", { href: link.url, target: "_blank", rel: "noopener noreferrer", children: link.title || link.url }) }, i)) });
|
|
987
|
+
}
|
|
988
|
+
return /* @__PURE__ */ jsxs14("div", { className: "fe-document-links", "data-field-type": "DocumentLinks", "data-field-state": getFieldState({ error, required, readOnly }), "data-testid": GetFieldDataTestId(fieldName, programName, entityType, entityId), children: [
|
|
989
|
+
/* @__PURE__ */ jsx24("ul", { className: "fe-document-links__list", children: documentLinks.map((link, i) => /* @__PURE__ */ jsxs14("li", { className: "fe-document-links__item", children: [
|
|
990
|
+
/* @__PURE__ */ jsx24("a", { href: link.url, target: "_blank", rel: "noopener noreferrer", children: link.title || link.url }),
|
|
991
|
+
/* @__PURE__ */ jsx24("button", { type: "button", className: "fe-document-links__delete", onClick: () => onDeleteLink(i), "aria-label": `${DocumentLinksStrings.deleteLink}: ${link.title || link.url}`, children: "\xD7" })
|
|
992
|
+
] }, i)) }),
|
|
993
|
+
/* @__PURE__ */ jsxs14("div", { className: "fe-document-links__add", children: [
|
|
994
|
+
/* @__PURE__ */ jsx24("input", { type: "url", className: "fe-document-links__url-input", placeholder: "URL", value: newUrl, onChange: (e) => setNewUrl(e.target.value), "aria-label": DocumentLinksStrings.link }),
|
|
995
|
+
/* @__PURE__ */ jsx24("input", { type: "text", className: "fe-document-links__text-input", placeholder: "Label (optional)", value: newText, onChange: (e) => setNewText(e.target.value), "aria-label": "Link label" }),
|
|
996
|
+
/* @__PURE__ */ jsx24("button", { type: "button", className: "fe-btn fe-btn--secondary", onClick: onAddLink, disabled: !newUrl, children: documentLinks.length > 0 ? DocumentLinksStrings.addAnotherLink : DocumentLinksStrings.addLink })
|
|
997
|
+
] })
|
|
998
|
+
] });
|
|
999
|
+
};
|
|
1000
|
+
var DocumentLinks_default = DocumentLinks;
|
|
1001
|
+
|
|
604
1002
|
// src/fields/readonly/ReadOnly.tsx
|
|
605
|
-
import { jsx as
|
|
1003
|
+
import { jsx as jsx25 } from "react/jsx-runtime";
|
|
606
1004
|
var ReadOnly = (props) => {
|
|
607
1005
|
const { fieldName, value, config } = props;
|
|
608
|
-
return /* @__PURE__ */
|
|
1006
|
+
return /* @__PURE__ */ jsx25(ReadOnlyText, { fieldName, value, ...config });
|
|
609
1007
|
};
|
|
610
1008
|
var ReadOnly_default = ReadOnly;
|
|
611
1009
|
|
|
1010
|
+
// src/fields/readonly/ReadOnlyArray.tsx
|
|
1011
|
+
import { jsx as jsx26 } from "react/jsx-runtime";
|
|
1012
|
+
var ReadOnlyArray = (props) => {
|
|
1013
|
+
const { fieldName, value } = props;
|
|
1014
|
+
const items = value ?? [];
|
|
1015
|
+
if (items.length === 0) {
|
|
1016
|
+
return /* @__PURE__ */ jsx26("span", { className: "fe-read-only-text", "data-field-type": "ReadOnlyArray", children: "-" });
|
|
1017
|
+
}
|
|
1018
|
+
return /* @__PURE__ */ jsx26("ul", { className: "fe-read-only-array", "data-field-type": "ReadOnlyArray", "data-field-state": "readonly", id: `${fieldName}-read-only`, children: items.map((v, i) => /* @__PURE__ */ jsx26("li", { children: v }, i)) });
|
|
1019
|
+
};
|
|
1020
|
+
var ReadOnlyArray_default = ReadOnlyArray;
|
|
1021
|
+
|
|
1022
|
+
// src/fields/readonly/ReadOnlyDateTime.tsx
|
|
1023
|
+
import { jsx as jsx27 } from "react/jsx-runtime";
|
|
1024
|
+
var ReadOnlyDateTime = (props) => {
|
|
1025
|
+
const { config, value } = props;
|
|
1026
|
+
if (!value) {
|
|
1027
|
+
return /* @__PURE__ */ jsx27("span", { className: "fe-read-only-text", "data-field-type": "ReadOnlyDateTime", children: "-" });
|
|
1028
|
+
}
|
|
1029
|
+
return /* @__PURE__ */ jsx27("time", { className: "fe-read-only-date-time", dateTime: value, "data-field-type": "ReadOnlyDateTime", "data-field-state": "readonly", children: formatDateTime(value, { hideTimestamp: config?.hidetimeStamp }) });
|
|
1030
|
+
};
|
|
1031
|
+
var ReadOnlyDateTime_default = ReadOnlyDateTime;
|
|
1032
|
+
|
|
1033
|
+
// src/fields/readonly/ReadOnlyCumulativeNumber.tsx
|
|
1034
|
+
import { isEmpty } from "@form-eng/core";
|
|
1035
|
+
import React6 from "react";
|
|
1036
|
+
import { useFormContext as useFormContext2 } from "react-hook-form";
|
|
1037
|
+
import { jsx as jsx28 } from "react/jsx-runtime";
|
|
1038
|
+
var ReadOnlyCumulativeNumber = (props) => {
|
|
1039
|
+
const { fieldName, config } = props;
|
|
1040
|
+
const { formState, getValues } = useFormContext2();
|
|
1041
|
+
const [value, setValue] = React6.useState();
|
|
1042
|
+
const { dependencyFields } = config || {};
|
|
1043
|
+
React6.useEffect(() => {
|
|
1044
|
+
const formValues = getValues();
|
|
1045
|
+
if (!isEmpty(dependencyFields)) {
|
|
1046
|
+
let totalCount = 0;
|
|
1047
|
+
dependencyFields.map((fn) => {
|
|
1048
|
+
totalCount += Number(formValues[fn]) || 0;
|
|
1049
|
+
});
|
|
1050
|
+
setValue(totalCount);
|
|
1051
|
+
}
|
|
1052
|
+
}, [formState]);
|
|
1053
|
+
if (!fieldName) return null;
|
|
1054
|
+
return /* @__PURE__ */ jsx28("span", { "data-field-type": "ReadOnlyCumulativeNumber", "data-field-state": "readonly", children: /* @__PURE__ */ jsx28(ReadOnlyText, { fieldName, value: String(value), ...config }) });
|
|
1055
|
+
};
|
|
1056
|
+
var ReadOnlyCumulativeNumber_default = ReadOnlyCumulativeNumber;
|
|
1057
|
+
|
|
1058
|
+
// src/fields/readonly/ReadOnlyRichText.tsx
|
|
1059
|
+
import { jsx as jsx29 } from "react/jsx-runtime";
|
|
1060
|
+
var ReadOnlyRichText = (props) => {
|
|
1061
|
+
const { value } = props;
|
|
1062
|
+
return /* @__PURE__ */ jsx29("div", { className: "fe-read-only-rich-text", "data-field-type": "ReadOnlyRichText", "data-field-state": "readonly", dangerouslySetInnerHTML: { __html: value || "" } });
|
|
1063
|
+
};
|
|
1064
|
+
var ReadOnlyRichText_default = ReadOnlyRichText;
|
|
1065
|
+
|
|
1066
|
+
// src/fields/readonly/ReadOnlyWithButton.tsx
|
|
1067
|
+
import { jsx as jsx30, jsxs as jsxs15 } from "react/jsx-runtime";
|
|
1068
|
+
var ReadOnlyWithButton = (props) => {
|
|
1069
|
+
const { fieldName, value, config } = props;
|
|
1070
|
+
return /* @__PURE__ */ jsxs15("div", { className: `fe-read-only-with-button ${config?.containerClassName ?? ""}`, "data-field-type": "ReadOnlyWithButton", "data-field-state": "readonly", children: [
|
|
1071
|
+
/* @__PURE__ */ jsx30(ReadOnlyText, { fieldName, value: `${value}` }),
|
|
1072
|
+
config?.buttonText && /* @__PURE__ */ jsx30("button", { type: "button", className: "fe-btn fe-btn--secondary", onClick: config.onButtonClick, children: config.buttonText })
|
|
1073
|
+
] });
|
|
1074
|
+
};
|
|
1075
|
+
var ReadOnlyWithButton_default = ReadOnlyWithButton;
|
|
1076
|
+
|
|
612
1077
|
// src/components/FormLoading.tsx
|
|
613
1078
|
import { FormConstants } from "@form-eng/core";
|
|
614
|
-
import { jsx as
|
|
1079
|
+
import { jsx as jsx31, jsxs as jsxs16 } from "react/jsx-runtime";
|
|
615
1080
|
var FormLoading = (props) => {
|
|
616
1081
|
const { loadingShimmerCount, loadingFieldShimmerHeight, inPanel, hideTitleShimmer } = props;
|
|
617
1082
|
const count = loadingShimmerCount || FormConstants.loadingShimmerCount;
|
|
618
1083
|
const height = loadingFieldShimmerHeight || FormConstants.loadingFieldShimmerHeight;
|
|
619
|
-
return /* @__PURE__ */
|
|
1084
|
+
return /* @__PURE__ */ jsx31(
|
|
620
1085
|
"div",
|
|
621
1086
|
{
|
|
622
1087
|
className: `df-form-loading ${inPanel ? "df-form-loading--panel" : ""}`,
|
|
623
1088
|
"data-field-type": "FormLoading",
|
|
624
1089
|
role: "status",
|
|
625
1090
|
"aria-label": "Loading form",
|
|
626
|
-
children: [...Array(count)].map((_, i) => /* @__PURE__ */
|
|
627
|
-
!hideTitleShimmer && /* @__PURE__ */
|
|
628
|
-
/* @__PURE__ */
|
|
1091
|
+
children: [...Array(count)].map((_, i) => /* @__PURE__ */ jsxs16("div", { className: "df-form-loading__field", children: [
|
|
1092
|
+
!hideTitleShimmer && /* @__PURE__ */ jsx31("div", { className: "df-skeleton df-skeleton--label", style: { width: "33%" } }),
|
|
1093
|
+
/* @__PURE__ */ jsx31("div", { className: "df-skeleton df-skeleton--input", style: { height: `${height}px` } })
|
|
629
1094
|
] }, `df-loading-${i}`))
|
|
630
1095
|
}
|
|
631
1096
|
);
|
|
@@ -633,38 +1098,69 @@ var FormLoading = (props) => {
|
|
|
633
1098
|
|
|
634
1099
|
// src/registry.ts
|
|
635
1100
|
import { ComponentTypes } from "@form-eng/core";
|
|
636
|
-
import
|
|
1101
|
+
import React7 from "react";
|
|
637
1102
|
function createReactAriaFieldRegistry() {
|
|
638
1103
|
return {
|
|
639
|
-
[ComponentTypes.Textbox]:
|
|
640
|
-
[ComponentTypes.Number]:
|
|
641
|
-
[ComponentTypes.Toggle]:
|
|
642
|
-
[ComponentTypes.Dropdown]:
|
|
643
|
-
[ComponentTypes.MultiSelect]:
|
|
644
|
-
[ComponentTypes.DateControl]:
|
|
645
|
-
[ComponentTypes.Slider]:
|
|
646
|
-
[ComponentTypes.Fragment]:
|
|
647
|
-
[ComponentTypes.SimpleDropdown]:
|
|
648
|
-
[ComponentTypes.Textarea]:
|
|
649
|
-
[ComponentTypes.RadioGroup]:
|
|
650
|
-
[ComponentTypes.CheckboxGroup]:
|
|
651
|
-
[ComponentTypes.
|
|
1104
|
+
[ComponentTypes.Textbox]: React7.createElement(Textbox_default),
|
|
1105
|
+
[ComponentTypes.Number]: React7.createElement(Number_default),
|
|
1106
|
+
[ComponentTypes.Toggle]: React7.createElement(Toggle_default),
|
|
1107
|
+
[ComponentTypes.Dropdown]: React7.createElement(Dropdown_default),
|
|
1108
|
+
[ComponentTypes.MultiSelect]: React7.createElement(MultiSelect_default),
|
|
1109
|
+
[ComponentTypes.DateControl]: React7.createElement(DateControl_default),
|
|
1110
|
+
[ComponentTypes.Slider]: React7.createElement(Slider_default),
|
|
1111
|
+
[ComponentTypes.Fragment]: React7.createElement(DynamicFragment_default),
|
|
1112
|
+
[ComponentTypes.SimpleDropdown]: React7.createElement(SimpleDropdown_default),
|
|
1113
|
+
[ComponentTypes.Textarea]: React7.createElement(Textarea_default),
|
|
1114
|
+
[ComponentTypes.RadioGroup]: React7.createElement(RadioGroup_default),
|
|
1115
|
+
[ComponentTypes.CheckboxGroup]: React7.createElement(CheckboxGroup_default),
|
|
1116
|
+
[ComponentTypes.Rating]: React7.createElement(Rating_default),
|
|
1117
|
+
[ComponentTypes.Autocomplete]: React7.createElement(Autocomplete_default),
|
|
1118
|
+
[ComponentTypes.DateTime]: React7.createElement(DateTime_default),
|
|
1119
|
+
[ComponentTypes.DateRange]: React7.createElement(DateRange_default),
|
|
1120
|
+
[ComponentTypes.PhoneInput]: React7.createElement(PhoneInput_default),
|
|
1121
|
+
[ComponentTypes.FileUpload]: React7.createElement(FileUpload_default),
|
|
1122
|
+
[ComponentTypes.ReadOnly]: React7.createElement(ReadOnly_default),
|
|
1123
|
+
[ComponentTypes.ColorPicker]: React7.createElement(ColorPicker_default),
|
|
1124
|
+
[ComponentTypes.MultiSelectSearch]: React7.createElement(MultiSelectSearch_default),
|
|
1125
|
+
[ComponentTypes.StatusDropdown]: React7.createElement(StatusDropdown_default),
|
|
1126
|
+
[ComponentTypes.DocumentLinks]: React7.createElement(DocumentLinks_default),
|
|
1127
|
+
[ComponentTypes.ReadOnlyArray]: React7.createElement(ReadOnlyArray_default),
|
|
1128
|
+
[ComponentTypes.ReadOnlyDateTime]: React7.createElement(ReadOnlyDateTime_default),
|
|
1129
|
+
[ComponentTypes.ReadOnlyCumulativeNumber]: React7.createElement(ReadOnlyCumulativeNumber_default),
|
|
1130
|
+
[ComponentTypes.ReadOnlyRichText]: React7.createElement(ReadOnlyRichText_default),
|
|
1131
|
+
[ComponentTypes.ReadOnlyWithButton]: React7.createElement(ReadOnlyWithButton_default)
|
|
652
1132
|
};
|
|
653
1133
|
}
|
|
654
1134
|
export {
|
|
1135
|
+
Autocomplete_default as Autocomplete,
|
|
655
1136
|
CheckboxGroup_default as CheckboxGroup,
|
|
1137
|
+
ColorPicker_default as ColorPicker,
|
|
656
1138
|
DateControl_default as DateControl,
|
|
1139
|
+
DateRange_default as DateRange,
|
|
1140
|
+
DateTime_default as DateTime,
|
|
1141
|
+
DocumentLinks_default as DocumentLinks,
|
|
1142
|
+
DocumentLinksStrings,
|
|
657
1143
|
Dropdown_default as Dropdown,
|
|
658
1144
|
DynamicFragment_default as DynamicFragment,
|
|
1145
|
+
FileUpload_default as FileUpload,
|
|
659
1146
|
FormLoading,
|
|
660
1147
|
GetFieldDataTestId,
|
|
661
1148
|
MultiSelect_default as MultiSelect,
|
|
1149
|
+
MultiSelectSearch_default as MultiSelectSearch,
|
|
662
1150
|
Number_default as Number,
|
|
1151
|
+
PhoneInput_default as PhoneInput,
|
|
663
1152
|
RadioGroup_default as RadioGroup,
|
|
1153
|
+
Rating_default as Rating,
|
|
664
1154
|
ReadOnly_default as ReadOnly,
|
|
1155
|
+
ReadOnlyArray_default as ReadOnlyArray,
|
|
1156
|
+
ReadOnlyCumulativeNumber_default as ReadOnlyCumulativeNumber,
|
|
1157
|
+
ReadOnlyDateTime_default as ReadOnlyDateTime,
|
|
1158
|
+
ReadOnlyRichText_default as ReadOnlyRichText,
|
|
665
1159
|
ReadOnlyText,
|
|
1160
|
+
ReadOnlyWithButton_default as ReadOnlyWithButton,
|
|
666
1161
|
SimpleDropdown_default as SimpleDropdown,
|
|
667
1162
|
Slider_default as Slider,
|
|
1163
|
+
StatusDropdown_default as StatusDropdown,
|
|
668
1164
|
StatusMessage,
|
|
669
1165
|
Textarea_default as Textarea,
|
|
670
1166
|
Textbox_default as Textbox,
|