cr-ui-lib 1.1.19 → 1.1.21

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/index.js CHANGED
@@ -6,6 +6,7 @@ var chart_js = require('chart.js');
6
6
  var React = require('react');
7
7
  var reactChartjs2 = require('react-chartjs-2');
8
8
  var lucideReact = require('lucide-react');
9
+ var reactDom = require('react-dom');
9
10
  var dateFns = require('date-fns');
10
11
  var DatePicker = require('react-datepicker');
11
12
  var ReactPaginate = require('react-paginate');
@@ -2658,12 +2659,17 @@ var MultipleAutoSuggestionInput = ({
2658
2659
  var _a;
2659
2660
  const [filteredOptions, setFilteredOptions] = React.useState(options);
2660
2661
  const [isDropdownOpen, setIsDropdownOpen] = React.useState(false);
2662
+ const [dropdownPosition, setDropdownPosition] = React.useState({
2663
+ top: 0,
2664
+ left: 0,
2665
+ width: 0
2666
+ });
2661
2667
  const inputRef = React.useRef(null);
2662
- const dropdownRef = React.useRef(null);
2668
+ const containerRef = React.useRef(null);
2663
2669
  const selectedList = isMulti ? selectedItems : selectedItems ? [selectedItems] : [];
2664
2670
  React.useEffect(() => {
2665
2671
  const handleClickOutside = (event) => {
2666
- if (dropdownRef.current && !dropdownRef.current.contains(event.target)) {
2672
+ if (containerRef.current && !containerRef.current.contains(event.target)) {
2667
2673
  setIsDropdownOpen(false);
2668
2674
  }
2669
2675
  };
@@ -2683,10 +2689,20 @@ var MultipleAutoSuggestionInput = ({
2683
2689
  setFilteredOptions(filtered);
2684
2690
  if (inputValue) {
2685
2691
  setIsDropdownOpen(true);
2686
- } else {
2692
+ } else if (!isDropdownAutoOpen) {
2687
2693
  setIsDropdownOpen(false);
2688
2694
  }
2689
2695
  }, [inputValue, options, selectedItems]);
2696
+ React.useLayoutEffect(() => {
2697
+ if (isDropdownOpen && containerRef.current) {
2698
+ const rect = containerRef.current.getBoundingClientRect();
2699
+ setDropdownPosition({
2700
+ top: rect.bottom + window.scrollY,
2701
+ left: rect.left + window.scrollX,
2702
+ width: rect.width
2703
+ });
2704
+ }
2705
+ }, [isDropdownOpen]);
2690
2706
  const handleInputChange = (e) => {
2691
2707
  setInputValue(e.target.value);
2692
2708
  onChange(e);
@@ -2696,6 +2712,32 @@ var MultipleAutoSuggestionInput = ({
2696
2712
  setInputValue("");
2697
2713
  setIsDropdownOpen(false);
2698
2714
  };
2715
+ const DropdownMenu = /* @__PURE__ */ jsxRuntime.jsx(
2716
+ "div",
2717
+ {
2718
+ style: {
2719
+ position: "absolute",
2720
+ top: `${dropdownPosition.top + 4}px`,
2721
+ // position based on state
2722
+ left: `${dropdownPosition.left}px`,
2723
+ width: `${dropdownPosition.width}px`
2724
+ },
2725
+ className: tailwindMerge.twMerge(
2726
+ "w-full rounded-lg bg-white shadow-lg z-50 max-h-60 overflow-auto border border-[#E2E2E2]",
2727
+ // Increased z-index
2728
+ dropdownOpenClass
2729
+ ),
2730
+ children: /* @__PURE__ */ jsxRuntime.jsx("div", { className: "py-1 rounded-lg border-[#E2E2E2]", children: filteredOptions.map((option) => /* @__PURE__ */ jsxRuntime.jsx(
2731
+ "div",
2732
+ {
2733
+ className: "px-4 py-2 text-sm cursor-pointer custom-listing-hover",
2734
+ onClick: () => handleOptionSelect(option.key),
2735
+ children: option.name
2736
+ },
2737
+ option.key
2738
+ )) })
2739
+ }
2740
+ );
2699
2741
  return /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
2700
2742
  /* @__PURE__ */ jsxRuntime.jsx(
2701
2743
  "label",
@@ -2707,10 +2749,10 @@ var MultipleAutoSuggestionInput = ({
2707
2749
  children: label
2708
2750
  }
2709
2751
  ),
2710
- /* @__PURE__ */ jsxRuntime.jsxs(
2752
+ /* @__PURE__ */ jsxRuntime.jsx(
2711
2753
  "div",
2712
2754
  {
2713
- ref: dropdownRef,
2755
+ ref: containerRef,
2714
2756
  className: "relative",
2715
2757
  onClick: () => {
2716
2758
  var _a2, _b;
@@ -2719,81 +2761,34 @@ var MultipleAutoSuggestionInput = ({
2719
2761
  setIsDropdownOpen(true);
2720
2762
  }
2721
2763
  },
2722
- children: [
2723
- /* @__PURE__ */ jsxRuntime.jsxs(
2724
- "div",
2725
- {
2726
- className: tailwindMerge.twMerge(
2727
- "border border-[#E2E2E2] focus-within:border-[#4683B4] rounded-lg p-1.5 bg-[#F8F8F8] cursor-pointer flex flex-wrap items-center gap-2 min-h-[2.5rem]",
2728
- buttonClass
2729
- ),
2730
- children: [
2731
- isMulti && Array.isArray(selectedList) ? selectedList.map((itemKey) => {
2732
- const option = options.find((opt) => opt.key === itemKey);
2733
- return /* @__PURE__ */ jsxRuntime.jsxs(
2734
- "div",
2735
- {
2736
- className: tailwindMerge.twMerge(
2737
- "flex flex border-[#E2E2E2] border items-center px-2 py-1 bg-white text-gray-700 rounded-md text-xs font-medium",
2738
- selectedItemsClass
2739
- ),
2740
- children: [
2741
- option ? option.name : itemKey,
2742
- onRemove && /* @__PURE__ */ jsxRuntime.jsx(
2743
- "button",
2744
- {
2745
- onClick: (e) => {
2746
- e.stopPropagation();
2747
- onRemove(itemKey);
2748
- },
2749
- className: tailwindMerge.twMerge(
2750
- "ml-1 text-gray-500 hover:text-gray-700 bg-white",
2751
- removeIconClass
2752
- ),
2753
- children: /* @__PURE__ */ jsxRuntime.jsx(
2754
- "svg",
2755
- {
2756
- xmlns: "http://www.w3.org/2000/svg",
2757
- width: "14",
2758
- height: "14",
2759
- viewBox: "0 0 14 14",
2760
- fill: "none",
2761
- children: /* @__PURE__ */ jsxRuntime.jsx(
2762
- "path",
2763
- {
2764
- d: "M11.0837 3.739L10.2612 2.9165L7.00033 6.17734L3.73949 2.9165L2.91699 3.739L6.17783 6.99984L2.91699 10.2607L3.73949 11.0832L7.00033 7.82234L10.2612 11.0832L11.0837 10.2607L7.82283 6.99984L11.0837 3.739Z",
2765
- fill: "#323232"
2766
- }
2767
- )
2768
- }
2769
- )
2770
- }
2771
- )
2772
- ]
2773
- },
2774
- itemKey
2775
- );
2776
- }) : selectedList.length > 0 && /* @__PURE__ */ jsxRuntime.jsxs(
2764
+ children: /* @__PURE__ */ jsxRuntime.jsxs(
2765
+ "div",
2766
+ {
2767
+ className: tailwindMerge.twMerge(
2768
+ "border border-[#E2E2E2] focus-within:border-[#4683B4] rounded-lg p-1.5 bg-[#F8F8F8] cursor-pointer flex flex-wrap items-center gap-2 min-h-[2.5rem]",
2769
+ buttonClass
2770
+ ),
2771
+ children: [
2772
+ isMulti && Array.isArray(selectedList) ? selectedList.map((itemKey) => {
2773
+ const option = options.find((opt) => opt.key === itemKey);
2774
+ return /* @__PURE__ */ jsxRuntime.jsxs(
2777
2775
  "div",
2778
2776
  {
2779
2777
  className: tailwindMerge.twMerge(
2780
- "flex border-[#E2E2E2] border items-center px-2 py-1 bg-white text-gray-700 rounded-md text-xs font-medium",
2778
+ "flex flex border-[#E2E2E2] border items-center px-2 py-1 bg-white text-gray-700 rounded-md text-xs font-medium",
2781
2779
  selectedItemsClass
2782
2780
  ),
2783
2781
  children: [
2784
- /* @__PURE__ */ jsxRuntime.jsx("span", { className: "text-xs font-medium text-gray-800", children: ((_a = options.find((opt) => opt.key === selectedList[0])) == null ? void 0 : _a.name) || selectedList[0] }),
2782
+ option ? option.name : itemKey,
2785
2783
  onRemove && /* @__PURE__ */ jsxRuntime.jsx(
2786
2784
  "button",
2787
2785
  {
2788
2786
  onClick: (e) => {
2789
- var _a2;
2790
2787
  e.stopPropagation();
2791
- onRemove(
2792
- ((_a2 = options.find((opt) => opt.key === selectedList[0])) == null ? void 0 : _a2.name) || selectedList[0]
2793
- );
2788
+ onRemove(itemKey);
2794
2789
  },
2795
2790
  className: tailwindMerge.twMerge(
2796
- "ml-1 text-gray-500 hover:text-gray-700",
2791
+ "ml-1 text-gray-500 hover:text-gray-700 bg-white",
2797
2792
  removeIconClass
2798
2793
  ),
2799
2794
  children: /* @__PURE__ */ jsxRuntime.jsx(
@@ -2816,49 +2811,77 @@ var MultipleAutoSuggestionInput = ({
2816
2811
  }
2817
2812
  )
2818
2813
  ]
2819
- }
2820
- ),
2821
- !isMulti && !enableTypingSingle && selectedList.length === 0 && /* @__PURE__ */ jsxRuntime.jsx("span", { className: "text-xs text-gray-500 px-1 py-1", children: "Select..." }),
2822
- isMulti && enableTypingSingle && /* @__PURE__ */ jsxRuntime.jsx(
2823
- "input",
2824
- {
2825
- type: "text",
2826
- ref: inputRef,
2827
- value: inputValue,
2828
- onKeyDown: keyDown,
2829
- onChange: handleInputChange,
2830
- className: "w-full flex-1 px-0 py-1 bg-[#F8F8F8] text-xs border-none outline-none focus:ring-0",
2831
- onFocus: () => {
2832
- if (!isDropdownOpen && (!isMulti || inputValue)) {
2833
- setIsDropdownOpen(true);
2814
+ },
2815
+ itemKey
2816
+ );
2817
+ }) : selectedList.length > 0 && /* @__PURE__ */ jsxRuntime.jsxs(
2818
+ "div",
2819
+ {
2820
+ className: tailwindMerge.twMerge(
2821
+ "flex border-[#E2E2E2] border items-center px-2 py-1 bg-white text-gray-700 rounded-md text-xs font-medium",
2822
+ selectedItemsClass
2823
+ ),
2824
+ children: [
2825
+ /* @__PURE__ */ jsxRuntime.jsx("span", { className: "text-xs font-medium text-gray-800", children: ((_a = options.find((opt) => opt.key === selectedList[0])) == null ? void 0 : _a.name) || selectedList[0] }),
2826
+ onRemove && /* @__PURE__ */ jsxRuntime.jsx(
2827
+ "button",
2828
+ {
2829
+ onClick: (e) => {
2830
+ var _a2;
2831
+ e.stopPropagation();
2832
+ onRemove(
2833
+ ((_a2 = options.find((opt) => opt.key === selectedList[0])) == null ? void 0 : _a2.name) || selectedList[0]
2834
+ );
2835
+ },
2836
+ className: tailwindMerge.twMerge(
2837
+ "ml-1 text-gray-500 hover:text-gray-700",
2838
+ removeIconClass
2839
+ ),
2840
+ children: /* @__PURE__ */ jsxRuntime.jsx(
2841
+ "svg",
2842
+ {
2843
+ xmlns: "http://www.w3.org/2000/svg",
2844
+ width: "14",
2845
+ height: "14",
2846
+ viewBox: "0 0 14 14",
2847
+ fill: "none",
2848
+ children: /* @__PURE__ */ jsxRuntime.jsx(
2849
+ "path",
2850
+ {
2851
+ d: "M11.0837 3.739L10.2612 2.9165L7.00033 6.17734L3.73949 2.9165L2.91699 3.739L6.17783 6.99984L2.91699 10.2607L3.73949 11.0832L7.00033 7.82234L10.2612 11.0832L11.0837 10.2607L7.82283 6.99984L11.0837 3.739Z",
2852
+ fill: "#323232"
2853
+ }
2854
+ )
2855
+ }
2856
+ )
2834
2857
  }
2835
- }
2836
- }
2837
- )
2838
- ]
2839
- }
2840
- ),
2841
- isDropdownOpen && filteredOptions.length > 0 && /* @__PURE__ */ jsxRuntime.jsx(
2842
- "div",
2843
- {
2844
- className: tailwindMerge.twMerge(
2845
- "absolute top-full left-0 mt-1 w-full rounded-lg bg-white shadow-lg z-10 max-h-60 overflow-auto border border-[#E2E2E2]",
2846
- dropdownOpenClass
2858
+ )
2859
+ ]
2860
+ }
2847
2861
  ),
2848
- children: /* @__PURE__ */ jsxRuntime.jsx("div", { className: "py-1 rounded-lg border-[#E2E2E2]", children: filteredOptions.map((option) => /* @__PURE__ */ jsxRuntime.jsx(
2849
- "div",
2862
+ (!isMulti || enableTypingSingle) && /* @__PURE__ */ jsxRuntime.jsx(
2863
+ "input",
2850
2864
  {
2851
- className: "px-4 py-2 text-sm cursor-pointer custom-listing-hover",
2852
- onClick: () => handleOptionSelect(option.key),
2853
- children: option.name
2854
- },
2855
- option.key
2856
- )) })
2857
- }
2858
- )
2859
- ]
2865
+ type: "text",
2866
+ ref: inputRef,
2867
+ value: inputValue,
2868
+ onKeyDown: keyDown,
2869
+ onChange: handleInputChange,
2870
+ className: "w-full flex-1 px-0 py-1 bg-[#F8F8F8] text-xs border-none outline-none focus:ring-0",
2871
+ onFocus: () => {
2872
+ if (!isDropdownOpen && (!isMulti || inputValue)) {
2873
+ setIsDropdownOpen(true);
2874
+ }
2875
+ },
2876
+ placeholder: selectedList.length === 0 ? "Type or select..." : ""
2877
+ }
2878
+ )
2879
+ ]
2880
+ }
2881
+ )
2860
2882
  }
2861
- )
2883
+ ),
2884
+ isDropdownOpen && filteredOptions.length > 0 && reactDom.createPortal(DropdownMenu, document.body)
2862
2885
  ] });
2863
2886
  };
2864
2887
  var MultipleAutoSuggestionInput_default = MultipleAutoSuggestionInput;