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.
@@ -1,13 +1,14 @@
1
1
  import { InputLabelProps } from "../Input/InputLabel";
2
2
  import { MenuProps } from "../MenuSelect/types";
3
3
  import { SelectFieldProps } from "../SelectItem";
4
+ export interface SelectOptionItem<T = string | number> {
5
+ label: string;
6
+ description?: string;
7
+ value: T;
8
+ }
4
9
  export interface SelectOption<T = string | number> {
5
10
  groupLabel?: string;
6
- items: {
7
- label: string;
8
- description?: string;
9
- value: T;
10
- }[];
11
+ items: SelectOptionItem<T>[];
11
12
  }
12
13
  type BaseSelectProps<T extends string | number> = Partial<InputLabelProps> & Omit<MenuProps, "groups" | "multi" | "selectedValues" | "onChangeSelected" | "onClickMenu" | "size" | "placeholder"> & Omit<SelectFieldProps, "value" | "onChange"> & {
13
14
  options: SelectOption<T>[];
@@ -25,13 +26,13 @@ export type SingleSelectProps<T extends string | number> = BaseSelectProps<T> &
25
26
  multi?: false;
26
27
  value: T;
27
28
  onChange: (value: T) => void;
28
- displayValue?: (value: SelectOption<T>) => string;
29
+ displayValue?: (item: SelectOptionItem<T>) => string;
29
30
  };
30
31
  export type MultiSelectProps<T extends string | number> = BaseSelectProps<T> & {
31
32
  multi: true;
32
33
  value: T[];
33
34
  onChange: (value: T[]) => void;
34
- displayValue?: (value: SelectOption<T>[]) => string;
35
+ displayValue?: (items: SelectOptionItem<T>[]) => string;
35
36
  };
36
37
  export type SelectProps<T extends string | number> = SingleSelectProps<T> | MultiSelectProps<T>;
37
38
  export {};
package/dist/esm/index.js CHANGED
@@ -73642,45 +73642,21 @@ const FISSelect = forwardRef(({ className, style, size = "md", options, value, d
73642
73642
  strategy: "fixed",
73643
73643
  }), []);
73644
73644
  const { styles, attributes } = usePopper(referenceElement, popperElement, popperOptions);
73645
- const originalOptionsRef = useRef(options);
73646
- useEffect(() => {
73647
- // Keep track of all items including selected ones
73648
- const allItems = new Map();
73649
- // Add items from current options
73650
- options.forEach((group) => {
73651
- group.items.forEach((item) => {
73652
- allItems.set(item.value, item);
73653
- });
73654
- });
73655
- // Add selected items that might not be in current options
73656
- if (multi && Array.isArray(value)) {
73657
- const selectedItems = originalOptionsRef.current
73658
- .flatMap((group) => group.items)
73659
- .filter((item) => value.includes(item.value));
73660
- selectedItems.forEach((item) => {
73661
- allItems.set(item.value, item);
73662
- });
73663
- }
73664
- // Update originalOptionsRef with all items
73665
- originalOptionsRef.current = [
73666
- {
73667
- items: Array.from(allItems.values()),
73668
- },
73669
- ];
73670
- }, [options, value, multi]);
73671
73645
  const selectedItems = useMemo$1(() => {
73672
73646
  const allItems = options.flatMap((group) => group.items);
73673
73647
  if (multi) {
73674
- return allItems.filter((item) => value.includes(item.value));
73648
+ const selectedArray = Array.isArray(value) ? value : [];
73649
+ return allItems.filter((item) => selectedArray.includes(item.value));
73675
73650
  }
73676
73651
  else {
73677
73652
  const found = allItems.find((item) => item.value === value);
73678
73653
  return found ? [found] : [];
73679
73654
  }
73680
73655
  }, [value, multi, options]);
73681
- const computedDisplayValue = () => {
73656
+ const computedDisplayValue = useMemo$1(() => {
73682
73657
  if (multi) {
73683
- const count = value.length;
73658
+ const selectedArray = Array.isArray(value) ? value : [];
73659
+ const count = selectedArray.length;
73684
73660
  if (count === 0) {
73685
73661
  return "";
73686
73662
  }
@@ -73689,17 +73665,18 @@ const FISSelect = forwardRef(({ className, style, size = "md", options, value, d
73689
73665
  : `Selected ${count.toString().padStart(2, "0")} option${count !== 1 ? "s" : ""}`;
73690
73666
  }
73691
73667
  else {
73692
- if (!selectedItems[0])
73668
+ const firstItem = selectedItems[0];
73669
+ if (!firstItem)
73693
73670
  return "";
73694
- return (displayValue?.(selectedItems[0]) || selectedItems[0].label);
73671
+ return displayValue?.(firstItem) || firstItem.label;
73695
73672
  }
73696
- };
73673
+ }, [multi, value, multiDisplayText, selectedItems, displayValue]);
73697
73674
  const handleToggle = useCallback(() => {
73698
73675
  if (!disabled)
73699
73676
  setIsOpen((prev) => !prev);
73700
73677
  }, [disabled]);
73701
73678
  const handleOptionRemove = useCallback((option) => {
73702
- if (multi) {
73679
+ if (multi && Array.isArray(value)) {
73703
73680
  const newValues = value.filter((v) => v !== option.value);
73704
73681
  onChange(newValues);
73705
73682
  }
@@ -73727,8 +73704,10 @@ const FISSelect = forwardRef(({ className, style, size = "md", options, value, d
73727
73704
  multi,
73728
73705
  size: isMenuSize(size) ? size : "md",
73729
73706
  selectedValues: multi
73730
- ? value
73731
- : value
73707
+ ? Array.isArray(value)
73708
+ ? value
73709
+ : []
73710
+ : value !== undefined && value !== null
73732
73711
  ? [value]
73733
73712
  : [],
73734
73713
  onChangeSelected: handleMenuChange,
@@ -73752,18 +73731,21 @@ const FISSelect = forwardRef(({ className, style, size = "md", options, value, d
73752
73731
  restProps,
73753
73732
  ]);
73754
73733
  useEffect(() => {
73734
+ if (!isOpen)
73735
+ return;
73755
73736
  const handleClickOutside = (event) => {
73737
+ const target = event.target;
73756
73738
  if (referenceElement &&
73757
- !referenceElement.contains(event.target) &&
73739
+ !referenceElement.contains(target) &&
73758
73740
  popperElement &&
73759
- !popperElement.contains(event.target)) {
73741
+ !popperElement.contains(target)) {
73760
73742
  setIsOpen(false);
73761
73743
  }
73762
73744
  };
73763
73745
  document.addEventListener("mousedown", handleClickOutside);
73764
73746
  return () => document.removeEventListener("mousedown", handleClickOutside);
73765
- }, [referenceElement, popperElement]);
73766
- return (jsxs(DivWrapperSC$1, { className: className, style: style, children: [(textLabel || iconLabel) && (jsx(FISInputLabel, { textLabel: textLabel, required: required, iconLabel: iconLabel, onClickIconLabel: onClickIconLabel })), jsx(DivInputWrapperSC, { ref: setReferenceElement, onClick: handleToggle, "$hasValue": !!value, children: jsx(FISSelectItem, { ...restProps, ref: ref, size: size, placeholder: placeholder, iconSuffix: isOpen ? jsx(ArrowUpIcon, {}) : jsx(ArrowDownIcon, {}), value: computedDisplayValue(), disabled: disabled, activeDropdown: isOpen, negative: negative }) }), message && (jsx(SpanHintSC$3, { className: classNames({ disabled, negative, positive }), children: message })), multi && value.length > 0 && (jsx(SelectedTagsWrapper, { children: jsx(MultipleValue, { options: selectedItems, onRemove: handleOptionRemove }) })), isOpen && (jsx(Portal, { portal: portal, children: jsx(DivDropdownMenuSC, { ref: setPopperElement, style: {
73747
+ }, [isOpen, referenceElement, popperElement]);
73748
+ return (jsxs(DivWrapperSC$1, { className: className, style: style, children: [(textLabel || iconLabel) && (jsx(FISInputLabel, { textLabel: textLabel, required: required, iconLabel: iconLabel, onClickIconLabel: onClickIconLabel })), jsx(DivInputWrapperSC, { ref: setReferenceElement, onClick: handleToggle, "$hasValue": !!value, children: jsx(FISSelectItem, { ...restProps, ref: ref, size: size, placeholder: placeholder, iconSuffix: isOpen ? jsx(ArrowUpIcon, {}) : jsx(ArrowDownIcon, {}), value: computedDisplayValue, disabled: disabled, activeDropdown: isOpen, negative: negative }) }), message && (jsx(SpanHintSC$3, { className: classNames({ disabled, negative, positive }), children: message })), multi && Array.isArray(value) && value.length > 0 && (jsx(SelectedTagsWrapper, { children: jsx(MultipleValue, { options: selectedItems, onRemove: handleOptionRemove }) })), isOpen && (jsx(Portal, { portal: portal, children: jsx(DivDropdownMenuSC, { ref: setPopperElement, style: {
73767
73749
  ...styles.popper,
73768
73750
  width: referenceElement?.offsetWidth,
73769
73751
  zIndex: 9999,