fis-component 0.0.88 → 0.0.89
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 +21 -39
- 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 +21 -39
- 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
|
}
|
|
@@ -73747,8 +73724,10 @@ const FISSelect = React.forwardRef(({ className, style, size = "md", options, va
|
|
|
73747
73724
|
multi,
|
|
73748
73725
|
size: isMenuSize(size) ? size : "md",
|
|
73749
73726
|
selectedValues: multi
|
|
73750
|
-
? value
|
|
73751
|
-
|
|
73727
|
+
? Array.isArray(value)
|
|
73728
|
+
? value
|
|
73729
|
+
: []
|
|
73730
|
+
: value !== undefined && value !== null
|
|
73752
73731
|
? [value]
|
|
73753
73732
|
: [],
|
|
73754
73733
|
onChangeSelected: handleMenuChange,
|
|
@@ -73772,18 +73751,21 @@ const FISSelect = React.forwardRef(({ className, style, size = "md", options, va
|
|
|
73772
73751
|
restProps,
|
|
73773
73752
|
]);
|
|
73774
73753
|
React.useEffect(() => {
|
|
73754
|
+
if (!isOpen)
|
|
73755
|
+
return;
|
|
73775
73756
|
const handleClickOutside = (event) => {
|
|
73757
|
+
const target = event.target;
|
|
73776
73758
|
if (referenceElement &&
|
|
73777
|
-
!referenceElement.contains(
|
|
73759
|
+
!referenceElement.contains(target) &&
|
|
73778
73760
|
popperElement &&
|
|
73779
|
-
!popperElement.contains(
|
|
73761
|
+
!popperElement.contains(target)) {
|
|
73780
73762
|
setIsOpen(false);
|
|
73781
73763
|
}
|
|
73782
73764
|
};
|
|
73783
73765
|
document.addEventListener("mousedown", handleClickOutside);
|
|
73784
73766
|
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.jsx(DivInputWrapperSC, { ref: setReferenceElement, onClick: handleToggle, "$hasValue": !!value, children: jsxRuntime.jsx(FISSelectItem, { ...restProps, ref: ref, size: size, placeholder: placeholder, iconSuffix: isOpen ? jsxRuntime.jsx(ArrowUpIcon, {}) : jsxRuntime.jsx(ArrowDownIcon, {}), value: computedDisplayValue
|
|
73767
|
+
}, [isOpen, referenceElement, popperElement]);
|
|
73768
|
+
return (jsxRuntime.jsxs(DivWrapperSC$1, { className: className, style: style, children: [(textLabel || iconLabel) && (jsxRuntime.jsx(FISInputLabel, { textLabel: textLabel, required: required, iconLabel: iconLabel, onClickIconLabel: onClickIconLabel })), jsxRuntime.jsx(DivInputWrapperSC, { ref: setReferenceElement, onClick: handleToggle, "$hasValue": !!value, children: jsxRuntime.jsx(FISSelectItem, { ...restProps, ref: ref, size: size, placeholder: placeholder, iconSuffix: isOpen ? jsxRuntime.jsx(ArrowUpIcon, {}) : jsxRuntime.jsx(ArrowDownIcon, {}), value: computedDisplayValue, disabled: disabled, activeDropdown: isOpen, negative: negative }) }), 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
73769
|
...styles.popper,
|
|
73788
73770
|
width: referenceElement?.offsetWidth,
|
|
73789
73771
|
zIndex: 9999,
|