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 +129 -106
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +130 -107
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import { twMerge } from 'tailwind-merge';
|
|
2
2
|
import { jsx, jsxs, Fragment } from 'react/jsx-runtime';
|
|
3
3
|
import { Chart, CategoryScale, LinearScale, PointElement, LineElement, Title, Tooltip, Filler, Legend } from 'chart.js';
|
|
4
|
-
import React, { useRef, useState, useEffect, useMemo, useCallback } from 'react';
|
|
4
|
+
import React, { useRef, useState, useEffect, useMemo, useLayoutEffect, useCallback } from 'react';
|
|
5
5
|
import { Line } from 'react-chartjs-2';
|
|
6
6
|
import { ChevronLeft, ChevronRight } from 'lucide-react';
|
|
7
|
+
import { createPortal } from 'react-dom';
|
|
7
8
|
import { isValid, parseISO, startOfDay, isToday, format } from 'date-fns';
|
|
8
9
|
import DatePicker from 'react-datepicker';
|
|
9
10
|
import ReactPaginate from 'react-paginate';
|
|
@@ -2650,12 +2651,17 @@ var MultipleAutoSuggestionInput = ({
|
|
|
2650
2651
|
var _a;
|
|
2651
2652
|
const [filteredOptions, setFilteredOptions] = useState(options);
|
|
2652
2653
|
const [isDropdownOpen, setIsDropdownOpen] = useState(false);
|
|
2654
|
+
const [dropdownPosition, setDropdownPosition] = useState({
|
|
2655
|
+
top: 0,
|
|
2656
|
+
left: 0,
|
|
2657
|
+
width: 0
|
|
2658
|
+
});
|
|
2653
2659
|
const inputRef = useRef(null);
|
|
2654
|
-
const
|
|
2660
|
+
const containerRef = useRef(null);
|
|
2655
2661
|
const selectedList = isMulti ? selectedItems : selectedItems ? [selectedItems] : [];
|
|
2656
2662
|
useEffect(() => {
|
|
2657
2663
|
const handleClickOutside = (event) => {
|
|
2658
|
-
if (
|
|
2664
|
+
if (containerRef.current && !containerRef.current.contains(event.target)) {
|
|
2659
2665
|
setIsDropdownOpen(false);
|
|
2660
2666
|
}
|
|
2661
2667
|
};
|
|
@@ -2675,10 +2681,20 @@ var MultipleAutoSuggestionInput = ({
|
|
|
2675
2681
|
setFilteredOptions(filtered);
|
|
2676
2682
|
if (inputValue) {
|
|
2677
2683
|
setIsDropdownOpen(true);
|
|
2678
|
-
} else {
|
|
2684
|
+
} else if (!isDropdownAutoOpen) {
|
|
2679
2685
|
setIsDropdownOpen(false);
|
|
2680
2686
|
}
|
|
2681
2687
|
}, [inputValue, options, selectedItems]);
|
|
2688
|
+
useLayoutEffect(() => {
|
|
2689
|
+
if (isDropdownOpen && containerRef.current) {
|
|
2690
|
+
const rect = containerRef.current.getBoundingClientRect();
|
|
2691
|
+
setDropdownPosition({
|
|
2692
|
+
top: rect.bottom + window.scrollY,
|
|
2693
|
+
left: rect.left + window.scrollX,
|
|
2694
|
+
width: rect.width
|
|
2695
|
+
});
|
|
2696
|
+
}
|
|
2697
|
+
}, [isDropdownOpen]);
|
|
2682
2698
|
const handleInputChange = (e) => {
|
|
2683
2699
|
setInputValue(e.target.value);
|
|
2684
2700
|
onChange(e);
|
|
@@ -2688,6 +2704,32 @@ var MultipleAutoSuggestionInput = ({
|
|
|
2688
2704
|
setInputValue("");
|
|
2689
2705
|
setIsDropdownOpen(false);
|
|
2690
2706
|
};
|
|
2707
|
+
const DropdownMenu = /* @__PURE__ */ jsx(
|
|
2708
|
+
"div",
|
|
2709
|
+
{
|
|
2710
|
+
style: {
|
|
2711
|
+
position: "absolute",
|
|
2712
|
+
top: `${dropdownPosition.top + 4}px`,
|
|
2713
|
+
// position based on state
|
|
2714
|
+
left: `${dropdownPosition.left}px`,
|
|
2715
|
+
width: `${dropdownPosition.width}px`
|
|
2716
|
+
},
|
|
2717
|
+
className: twMerge(
|
|
2718
|
+
"w-full rounded-lg bg-white shadow-lg z-50 max-h-60 overflow-auto border border-[#E2E2E2]",
|
|
2719
|
+
// Increased z-index
|
|
2720
|
+
dropdownOpenClass
|
|
2721
|
+
),
|
|
2722
|
+
children: /* @__PURE__ */ jsx("div", { className: "py-1 rounded-lg border-[#E2E2E2]", children: filteredOptions.map((option) => /* @__PURE__ */ jsx(
|
|
2723
|
+
"div",
|
|
2724
|
+
{
|
|
2725
|
+
className: "px-4 py-2 text-sm cursor-pointer custom-listing-hover",
|
|
2726
|
+
onClick: () => handleOptionSelect(option.key),
|
|
2727
|
+
children: option.name
|
|
2728
|
+
},
|
|
2729
|
+
option.key
|
|
2730
|
+
)) })
|
|
2731
|
+
}
|
|
2732
|
+
);
|
|
2691
2733
|
return /* @__PURE__ */ jsxs("div", { children: [
|
|
2692
2734
|
/* @__PURE__ */ jsx(
|
|
2693
2735
|
"label",
|
|
@@ -2699,10 +2741,10 @@ var MultipleAutoSuggestionInput = ({
|
|
|
2699
2741
|
children: label
|
|
2700
2742
|
}
|
|
2701
2743
|
),
|
|
2702
|
-
/* @__PURE__ */
|
|
2744
|
+
/* @__PURE__ */ jsx(
|
|
2703
2745
|
"div",
|
|
2704
2746
|
{
|
|
2705
|
-
ref:
|
|
2747
|
+
ref: containerRef,
|
|
2706
2748
|
className: "relative",
|
|
2707
2749
|
onClick: () => {
|
|
2708
2750
|
var _a2, _b;
|
|
@@ -2711,81 +2753,34 @@ var MultipleAutoSuggestionInput = ({
|
|
|
2711
2753
|
setIsDropdownOpen(true);
|
|
2712
2754
|
}
|
|
2713
2755
|
},
|
|
2714
|
-
children:
|
|
2715
|
-
|
|
2716
|
-
|
|
2717
|
-
|
|
2718
|
-
|
|
2719
|
-
|
|
2720
|
-
|
|
2721
|
-
|
|
2722
|
-
|
|
2723
|
-
|
|
2724
|
-
|
|
2725
|
-
return /* @__PURE__ */ jsxs(
|
|
2726
|
-
"div",
|
|
2727
|
-
{
|
|
2728
|
-
className: twMerge(
|
|
2729
|
-
"flex flex border-[#E2E2E2] border items-center px-2 py-1 bg-white text-gray-700 rounded-md text-xs font-medium",
|
|
2730
|
-
selectedItemsClass
|
|
2731
|
-
),
|
|
2732
|
-
children: [
|
|
2733
|
-
option ? option.name : itemKey,
|
|
2734
|
-
onRemove && /* @__PURE__ */ jsx(
|
|
2735
|
-
"button",
|
|
2736
|
-
{
|
|
2737
|
-
onClick: (e) => {
|
|
2738
|
-
e.stopPropagation();
|
|
2739
|
-
onRemove(itemKey);
|
|
2740
|
-
},
|
|
2741
|
-
className: twMerge(
|
|
2742
|
-
"ml-1 text-gray-500 hover:text-gray-700 bg-white",
|
|
2743
|
-
removeIconClass
|
|
2744
|
-
),
|
|
2745
|
-
children: /* @__PURE__ */ jsx(
|
|
2746
|
-
"svg",
|
|
2747
|
-
{
|
|
2748
|
-
xmlns: "http://www.w3.org/2000/svg",
|
|
2749
|
-
width: "14",
|
|
2750
|
-
height: "14",
|
|
2751
|
-
viewBox: "0 0 14 14",
|
|
2752
|
-
fill: "none",
|
|
2753
|
-
children: /* @__PURE__ */ jsx(
|
|
2754
|
-
"path",
|
|
2755
|
-
{
|
|
2756
|
-
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",
|
|
2757
|
-
fill: "#323232"
|
|
2758
|
-
}
|
|
2759
|
-
)
|
|
2760
|
-
}
|
|
2761
|
-
)
|
|
2762
|
-
}
|
|
2763
|
-
)
|
|
2764
|
-
]
|
|
2765
|
-
},
|
|
2766
|
-
itemKey
|
|
2767
|
-
);
|
|
2768
|
-
}) : selectedList.length > 0 && /* @__PURE__ */ jsxs(
|
|
2756
|
+
children: /* @__PURE__ */ jsxs(
|
|
2757
|
+
"div",
|
|
2758
|
+
{
|
|
2759
|
+
className: twMerge(
|
|
2760
|
+
"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]",
|
|
2761
|
+
buttonClass
|
|
2762
|
+
),
|
|
2763
|
+
children: [
|
|
2764
|
+
isMulti && Array.isArray(selectedList) ? selectedList.map((itemKey) => {
|
|
2765
|
+
const option = options.find((opt) => opt.key === itemKey);
|
|
2766
|
+
return /* @__PURE__ */ jsxs(
|
|
2769
2767
|
"div",
|
|
2770
2768
|
{
|
|
2771
2769
|
className: twMerge(
|
|
2772
|
-
"flex border-[#E2E2E2] border items-center px-2 py-1 bg-white text-gray-700 rounded-md text-xs font-medium",
|
|
2770
|
+
"flex flex border-[#E2E2E2] border items-center px-2 py-1 bg-white text-gray-700 rounded-md text-xs font-medium",
|
|
2773
2771
|
selectedItemsClass
|
|
2774
2772
|
),
|
|
2775
2773
|
children: [
|
|
2776
|
-
|
|
2774
|
+
option ? option.name : itemKey,
|
|
2777
2775
|
onRemove && /* @__PURE__ */ jsx(
|
|
2778
2776
|
"button",
|
|
2779
2777
|
{
|
|
2780
2778
|
onClick: (e) => {
|
|
2781
|
-
var _a2;
|
|
2782
2779
|
e.stopPropagation();
|
|
2783
|
-
onRemove(
|
|
2784
|
-
((_a2 = options.find((opt) => opt.key === selectedList[0])) == null ? void 0 : _a2.name) || selectedList[0]
|
|
2785
|
-
);
|
|
2780
|
+
onRemove(itemKey);
|
|
2786
2781
|
},
|
|
2787
2782
|
className: twMerge(
|
|
2788
|
-
"ml-1 text-gray-500 hover:text-gray-700",
|
|
2783
|
+
"ml-1 text-gray-500 hover:text-gray-700 bg-white",
|
|
2789
2784
|
removeIconClass
|
|
2790
2785
|
),
|
|
2791
2786
|
children: /* @__PURE__ */ jsx(
|
|
@@ -2808,49 +2803,77 @@ var MultipleAutoSuggestionInput = ({
|
|
|
2808
2803
|
}
|
|
2809
2804
|
)
|
|
2810
2805
|
]
|
|
2811
|
-
}
|
|
2812
|
-
|
|
2813
|
-
|
|
2814
|
-
|
|
2815
|
-
|
|
2816
|
-
|
|
2817
|
-
|
|
2818
|
-
|
|
2819
|
-
|
|
2820
|
-
|
|
2821
|
-
|
|
2822
|
-
className: "
|
|
2823
|
-
|
|
2824
|
-
|
|
2825
|
-
|
|
2806
|
+
},
|
|
2807
|
+
itemKey
|
|
2808
|
+
);
|
|
2809
|
+
}) : selectedList.length > 0 && /* @__PURE__ */ jsxs(
|
|
2810
|
+
"div",
|
|
2811
|
+
{
|
|
2812
|
+
className: twMerge(
|
|
2813
|
+
"flex border-[#E2E2E2] border items-center px-2 py-1 bg-white text-gray-700 rounded-md text-xs font-medium",
|
|
2814
|
+
selectedItemsClass
|
|
2815
|
+
),
|
|
2816
|
+
children: [
|
|
2817
|
+
/* @__PURE__ */ 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] }),
|
|
2818
|
+
onRemove && /* @__PURE__ */ jsx(
|
|
2819
|
+
"button",
|
|
2820
|
+
{
|
|
2821
|
+
onClick: (e) => {
|
|
2822
|
+
var _a2;
|
|
2823
|
+
e.stopPropagation();
|
|
2824
|
+
onRemove(
|
|
2825
|
+
((_a2 = options.find((opt) => opt.key === selectedList[0])) == null ? void 0 : _a2.name) || selectedList[0]
|
|
2826
|
+
);
|
|
2827
|
+
},
|
|
2828
|
+
className: twMerge(
|
|
2829
|
+
"ml-1 text-gray-500 hover:text-gray-700",
|
|
2830
|
+
removeIconClass
|
|
2831
|
+
),
|
|
2832
|
+
children: /* @__PURE__ */ jsx(
|
|
2833
|
+
"svg",
|
|
2834
|
+
{
|
|
2835
|
+
xmlns: "http://www.w3.org/2000/svg",
|
|
2836
|
+
width: "14",
|
|
2837
|
+
height: "14",
|
|
2838
|
+
viewBox: "0 0 14 14",
|
|
2839
|
+
fill: "none",
|
|
2840
|
+
children: /* @__PURE__ */ jsx(
|
|
2841
|
+
"path",
|
|
2842
|
+
{
|
|
2843
|
+
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",
|
|
2844
|
+
fill: "#323232"
|
|
2845
|
+
}
|
|
2846
|
+
)
|
|
2847
|
+
}
|
|
2848
|
+
)
|
|
2826
2849
|
}
|
|
2827
|
-
|
|
2828
|
-
|
|
2829
|
-
|
|
2830
|
-
]
|
|
2831
|
-
}
|
|
2832
|
-
),
|
|
2833
|
-
isDropdownOpen && filteredOptions.length > 0 && /* @__PURE__ */ jsx(
|
|
2834
|
-
"div",
|
|
2835
|
-
{
|
|
2836
|
-
className: twMerge(
|
|
2837
|
-
"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]",
|
|
2838
|
-
dropdownOpenClass
|
|
2850
|
+
)
|
|
2851
|
+
]
|
|
2852
|
+
}
|
|
2839
2853
|
),
|
|
2840
|
-
|
|
2841
|
-
"
|
|
2854
|
+
(!isMulti || enableTypingSingle) && /* @__PURE__ */ jsx(
|
|
2855
|
+
"input",
|
|
2842
2856
|
{
|
|
2843
|
-
|
|
2844
|
-
|
|
2845
|
-
|
|
2846
|
-
|
|
2847
|
-
|
|
2848
|
-
|
|
2849
|
-
|
|
2850
|
-
|
|
2851
|
-
|
|
2857
|
+
type: "text",
|
|
2858
|
+
ref: inputRef,
|
|
2859
|
+
value: inputValue,
|
|
2860
|
+
onKeyDown: keyDown,
|
|
2861
|
+
onChange: handleInputChange,
|
|
2862
|
+
className: "w-full flex-1 px-0 py-1 bg-[#F8F8F8] text-xs border-none outline-none focus:ring-0",
|
|
2863
|
+
onFocus: () => {
|
|
2864
|
+
if (!isDropdownOpen && (!isMulti || inputValue)) {
|
|
2865
|
+
setIsDropdownOpen(true);
|
|
2866
|
+
}
|
|
2867
|
+
},
|
|
2868
|
+
placeholder: selectedList.length === 0 ? "Type or select..." : ""
|
|
2869
|
+
}
|
|
2870
|
+
)
|
|
2871
|
+
]
|
|
2872
|
+
}
|
|
2873
|
+
)
|
|
2852
2874
|
}
|
|
2853
|
-
)
|
|
2875
|
+
),
|
|
2876
|
+
isDropdownOpen && filteredOptions.length > 0 && createPortal(DropdownMenu, document.body)
|
|
2854
2877
|
] });
|
|
2855
2878
|
};
|
|
2856
2879
|
var MultipleAutoSuggestionInput_default = MultipleAutoSuggestionInput;
|