fis-component 0.0.88 → 0.0.90
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/dist/cjs/index.js +29 -41
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/types/src/components/Select/types.d.ts +8 -7
- package/dist/esm/index.js +29 -41
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/types/src/components/Select/types.d.ts +8 -7
- package/dist/index.d.ts +8 -7
- package/package.json +1 -1
package/dist/cjs/index.js
CHANGED
|
@@ -73662,45 +73662,21 @@ const FISSelect = React.forwardRef(({ className, style, size = "md", options, va
|
|
|
73662
73662
|
strategy: "fixed",
|
|
73663
73663
|
}), []);
|
|
73664
73664
|
const { styles, attributes } = usePopper(referenceElement, popperElement, popperOptions);
|
|
73665
|
-
const originalOptionsRef = React.useRef(options);
|
|
73666
|
-
React.useEffect(() => {
|
|
73667
|
-
// Keep track of all items including selected ones
|
|
73668
|
-
const allItems = new Map();
|
|
73669
|
-
// Add items from current options
|
|
73670
|
-
options.forEach((group) => {
|
|
73671
|
-
group.items.forEach((item) => {
|
|
73672
|
-
allItems.set(item.value, item);
|
|
73673
|
-
});
|
|
73674
|
-
});
|
|
73675
|
-
// Add selected items that might not be in current options
|
|
73676
|
-
if (multi && Array.isArray(value)) {
|
|
73677
|
-
const selectedItems = originalOptionsRef.current
|
|
73678
|
-
.flatMap((group) => group.items)
|
|
73679
|
-
.filter((item) => value.includes(item.value));
|
|
73680
|
-
selectedItems.forEach((item) => {
|
|
73681
|
-
allItems.set(item.value, item);
|
|
73682
|
-
});
|
|
73683
|
-
}
|
|
73684
|
-
// Update originalOptionsRef with all items
|
|
73685
|
-
originalOptionsRef.current = [
|
|
73686
|
-
{
|
|
73687
|
-
items: Array.from(allItems.values()),
|
|
73688
|
-
},
|
|
73689
|
-
];
|
|
73690
|
-
}, [options, value, multi]);
|
|
73691
73665
|
const selectedItems = React.useMemo(() => {
|
|
73692
73666
|
const allItems = options.flatMap((group) => group.items);
|
|
73693
73667
|
if (multi) {
|
|
73694
|
-
|
|
73668
|
+
const selectedArray = Array.isArray(value) ? value : [];
|
|
73669
|
+
return allItems.filter((item) => selectedArray.includes(item.value));
|
|
73695
73670
|
}
|
|
73696
73671
|
else {
|
|
73697
73672
|
const found = allItems.find((item) => item.value === value);
|
|
73698
73673
|
return found ? [found] : [];
|
|
73699
73674
|
}
|
|
73700
73675
|
}, [value, multi, options]);
|
|
73701
|
-
const computedDisplayValue = () => {
|
|
73676
|
+
const computedDisplayValue = React.useMemo(() => {
|
|
73702
73677
|
if (multi) {
|
|
73703
|
-
const
|
|
73678
|
+
const selectedArray = Array.isArray(value) ? value : [];
|
|
73679
|
+
const count = selectedArray.length;
|
|
73704
73680
|
if (count === 0) {
|
|
73705
73681
|
return "";
|
|
73706
73682
|
}
|
|
@@ -73709,17 +73685,18 @@ const FISSelect = React.forwardRef(({ className, style, size = "md", options, va
|
|
|
73709
73685
|
: `Selected ${count.toString().padStart(2, "0")} option${count !== 1 ? "s" : ""}`;
|
|
73710
73686
|
}
|
|
73711
73687
|
else {
|
|
73712
|
-
|
|
73688
|
+
const firstItem = selectedItems[0];
|
|
73689
|
+
if (!firstItem)
|
|
73713
73690
|
return "";
|
|
73714
|
-
return
|
|
73691
|
+
return displayValue?.(firstItem) || firstItem.label;
|
|
73715
73692
|
}
|
|
73716
|
-
};
|
|
73693
|
+
}, [multi, value, multiDisplayText, selectedItems, displayValue]);
|
|
73717
73694
|
const handleToggle = React.useCallback(() => {
|
|
73718
73695
|
if (!disabled)
|
|
73719
73696
|
setIsOpen((prev) => !prev);
|
|
73720
73697
|
}, [disabled]);
|
|
73721
73698
|
const handleOptionRemove = React.useCallback((option) => {
|
|
73722
|
-
if (multi) {
|
|
73699
|
+
if (multi && Array.isArray(value)) {
|
|
73723
73700
|
const newValues = value.filter((v) => v !== option.value);
|
|
73724
73701
|
onChange(newValues);
|
|
73725
73702
|
}
|
|
@@ -73731,13 +73708,15 @@ const FISSelect = React.forwardRef(({ className, style, size = "md", options, va
|
|
|
73731
73708
|
else {
|
|
73732
73709
|
if (values.length > 0) {
|
|
73733
73710
|
onChange(values[0]);
|
|
73734
|
-
|
|
73711
|
+
// Delay closing to ensure react-hook-form processes the change first
|
|
73712
|
+
setTimeout(() => setIsOpen(false), 0);
|
|
73735
73713
|
}
|
|
73736
73714
|
}
|
|
73737
73715
|
}, [multi, onChange]);
|
|
73738
73716
|
const handleMenuClick = React.useCallback(() => {
|
|
73739
73717
|
if (!multi) {
|
|
73740
|
-
|
|
73718
|
+
// Delay closing to ensure react-hook-form processes the change first
|
|
73719
|
+
setTimeout(() => setIsOpen(false), 0);
|
|
73741
73720
|
}
|
|
73742
73721
|
}, [multi]);
|
|
73743
73722
|
const menuProps = React.useMemo(() => ({
|
|
@@ -73747,8 +73726,10 @@ const FISSelect = React.forwardRef(({ className, style, size = "md", options, va
|
|
|
73747
73726
|
multi,
|
|
73748
73727
|
size: isMenuSize(size) ? size : "md",
|
|
73749
73728
|
selectedValues: multi
|
|
73750
|
-
? value
|
|
73751
|
-
|
|
73729
|
+
? Array.isArray(value)
|
|
73730
|
+
? value
|
|
73731
|
+
: []
|
|
73732
|
+
: value !== undefined && value !== null
|
|
73752
73733
|
? [value]
|
|
73753
73734
|
: [],
|
|
73754
73735
|
onChangeSelected: handleMenuChange,
|
|
@@ -73772,18 +73753,25 @@ const FISSelect = React.forwardRef(({ className, style, size = "md", options, va
|
|
|
73772
73753
|
restProps,
|
|
73773
73754
|
]);
|
|
73774
73755
|
React.useEffect(() => {
|
|
73756
|
+
if (!isOpen)
|
|
73757
|
+
return;
|
|
73775
73758
|
const handleClickOutside = (event) => {
|
|
73759
|
+
const target = event.target;
|
|
73776
73760
|
if (referenceElement &&
|
|
73777
|
-
!referenceElement.contains(
|
|
73761
|
+
!referenceElement.contains(target) &&
|
|
73778
73762
|
popperElement &&
|
|
73779
|
-
!popperElement.contains(
|
|
73763
|
+
!popperElement.contains(target)) {
|
|
73780
73764
|
setIsOpen(false);
|
|
73781
73765
|
}
|
|
73782
73766
|
};
|
|
73783
73767
|
document.addEventListener("mousedown", handleClickOutside);
|
|
73784
73768
|
return () => document.removeEventListener("mousedown", handleClickOutside);
|
|
73785
|
-
}, [referenceElement, popperElement]);
|
|
73786
|
-
return (jsxRuntime.jsxs(DivWrapperSC$1, { className: className, style: style, children: [(textLabel || iconLabel) && (jsxRuntime.jsx(FISInputLabel, { textLabel: textLabel, required: required, iconLabel: iconLabel, onClickIconLabel: onClickIconLabel })), jsxRuntime.
|
|
73769
|
+
}, [isOpen, referenceElement, popperElement]);
|
|
73770
|
+
return (jsxRuntime.jsxs(DivWrapperSC$1, { className: className, style: style, children: [(textLabel || iconLabel) && (jsxRuntime.jsx(FISInputLabel, { textLabel: textLabel, required: required, iconLabel: iconLabel, onClickIconLabel: onClickIconLabel })), jsxRuntime.jsxs(DivInputWrapperSC, { ref: setReferenceElement, onClick: handleToggle, "$hasValue": !!value, children: [jsxRuntime.jsx("input", { ...restProps, ref: ref, type: "hidden", value: multi
|
|
73771
|
+
? Array.isArray(value)
|
|
73772
|
+
? value.join(",")
|
|
73773
|
+
: ""
|
|
73774
|
+
: (value ?? "") }), jsxRuntime.jsx(FISSelectItem, { size: size, placeholder: placeholder, iconSuffix: isOpen ? jsxRuntime.jsx(ArrowUpIcon, {}) : jsxRuntime.jsx(ArrowDownIcon, {}), value: computedDisplayValue, disabled: disabled, activeDropdown: isOpen, negative: negative, readOnly: true })] }), message && (jsxRuntime.jsx(SpanHintSC$3, { className: classNames({ disabled, negative, positive }), children: message })), multi && Array.isArray(value) && value.length > 0 && (jsxRuntime.jsx(SelectedTagsWrapper, { children: jsxRuntime.jsx(MultipleValue, { options: selectedItems, onRemove: handleOptionRemove }) })), isOpen && (jsxRuntime.jsx(Portal, { portal: portal, children: jsxRuntime.jsx(DivDropdownMenuSC, { ref: setPopperElement, style: {
|
|
73787
73775
|
...styles.popper,
|
|
73788
73776
|
width: referenceElement?.offsetWidth,
|
|
73789
73777
|
zIndex: 9999,
|