cr-ui-lib 1.1.21 → 1.1.22
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 +108 -95
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +108 -95
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -3000,8 +3000,14 @@ function SingleSelectDropdown({
|
|
|
3000
3000
|
const [searchTerm, setSearchTerm] = React.useState("");
|
|
3001
3001
|
const dropdownRef = React.useRef(null);
|
|
3002
3002
|
const listRef = React.useRef(null);
|
|
3003
|
+
const portalRef = React.useRef(null);
|
|
3003
3004
|
const searchTimeoutRef = React.useRef();
|
|
3004
|
-
const [
|
|
3005
|
+
const [_, setHoveredId] = React.useState(null);
|
|
3006
|
+
const [dropdownPosition, setDropdownPosition] = React.useState({
|
|
3007
|
+
top: 0,
|
|
3008
|
+
left: 0,
|
|
3009
|
+
width: 0
|
|
3010
|
+
});
|
|
3005
3011
|
const selectedOption = options.find((opt) => opt.id === value) || null;
|
|
3006
3012
|
const handleScroll = React.useCallback(() => {
|
|
3007
3013
|
if (!listRef.current || isLoading || !hasMore) return;
|
|
@@ -3031,28 +3037,13 @@ function SingleSelectDropdown({
|
|
|
3031
3037
|
}
|
|
3032
3038
|
};
|
|
3033
3039
|
}, []);
|
|
3034
|
-
const
|
|
3035
|
-
|
|
3036
|
-
|
|
3037
|
-
|
|
3038
|
-
return options.filter(
|
|
3039
|
-
(opt) => {
|
|
3040
|
-
var _a;
|
|
3041
|
-
return ((_a = opt.name) != null ? _a : "").toLowerCase().includes(searchTerm.toLowerCase());
|
|
3042
|
-
}
|
|
3043
|
-
);
|
|
3044
|
-
}
|
|
3045
|
-
};
|
|
3046
|
-
const filteredOptions = getFilteredOptions();
|
|
3047
|
-
const getDisplayOptions = () => {
|
|
3048
|
-
if (requiresSearch && onSearch) {
|
|
3049
|
-
if (searchTerm.length < minSearchLength) {
|
|
3050
|
-
return selectedOption ? [selectedOption] : [];
|
|
3051
|
-
}
|
|
3040
|
+
const filteredOptions = onSearch ? options : options.filter(
|
|
3041
|
+
(opt) => {
|
|
3042
|
+
var _a;
|
|
3043
|
+
return ((_a = opt.name) != null ? _a : "").toLowerCase().includes(searchTerm.toLowerCase());
|
|
3052
3044
|
}
|
|
3053
|
-
|
|
3054
|
-
|
|
3055
|
-
const displayOptions = getDisplayOptions();
|
|
3045
|
+
);
|
|
3046
|
+
const displayOptions = requiresSearch && onSearch && searchTerm.length < minSearchLength ? selectedOption ? [selectedOption] : [] : filteredOptions;
|
|
3056
3047
|
const getEmptyStateContent = () => {
|
|
3057
3048
|
if (requiresSearch && onSearch && searchTerm.length < minSearchLength) {
|
|
3058
3049
|
return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "px-4 py-8 text-center", children: [
|
|
@@ -3087,7 +3078,7 @@ function SingleSelectDropdown({
|
|
|
3087
3078
|
return /* @__PURE__ */ jsxRuntime.jsx("div", { className: "px-2 py-2 text-sm text-gray-500", children: !isLoading && options.length === 0 && emptyMessage });
|
|
3088
3079
|
};
|
|
3089
3080
|
const handleClickOutside = (event) => {
|
|
3090
|
-
if (dropdownRef.current && !dropdownRef.current.contains(event.target)) {
|
|
3081
|
+
if (dropdownRef.current && !dropdownRef.current.contains(event.target) && portalRef.current && !portalRef.current.contains(event.target)) {
|
|
3091
3082
|
setIsOpen(false);
|
|
3092
3083
|
}
|
|
3093
3084
|
};
|
|
@@ -3101,86 +3092,39 @@ function SingleSelectDropdown({
|
|
|
3101
3092
|
onSearch("");
|
|
3102
3093
|
}
|
|
3103
3094
|
}, [isOpen]);
|
|
3095
|
+
React.useLayoutEffect(() => {
|
|
3096
|
+
if (isOpen && dropdownRef.current) {
|
|
3097
|
+
const rect = dropdownRef.current.getBoundingClientRect();
|
|
3098
|
+
setDropdownPosition({
|
|
3099
|
+
top: rect.bottom + window.scrollY,
|
|
3100
|
+
left: rect.left + window.scrollX,
|
|
3101
|
+
width: rect.width
|
|
3102
|
+
});
|
|
3103
|
+
}
|
|
3104
|
+
}, [isOpen]);
|
|
3104
3105
|
const handleToggle = () => {
|
|
3105
3106
|
if (!disabled) {
|
|
3106
3107
|
setIsOpen(!isOpen);
|
|
3107
3108
|
}
|
|
3108
3109
|
};
|
|
3109
|
-
|
|
3110
|
-
|
|
3111
|
-
|
|
3112
|
-
|
|
3113
|
-
|
|
3114
|
-
|
|
3115
|
-
|
|
3116
|
-
|
|
3117
|
-
|
|
3118
|
-
|
|
3119
|
-
|
|
3120
|
-
|
|
3121
|
-
/* @__PURE__ */ jsxRuntime.jsxs("div", { ref: dropdownRef, className: "relative", children: [
|
|
3122
|
-
/* @__PURE__ */ jsxRuntime.jsxs(
|
|
3123
|
-
"div",
|
|
3124
|
-
{
|
|
3125
|
-
onClick: handleToggle,
|
|
3126
|
-
className: tailwindMerge.twMerge(
|
|
3127
|
-
`border-[1.5px] rounded-md h-[40px] pl-3 pr-2 py-2 bg-[#F8F8F8] cursor-pointer flex items-center justify-between ${disabled ? "bg-gray-100 cursor-not-allowed border-gray-200" : isOpen ? "border-[#4683B4]" : "border-[#E2E2E2]"}`,
|
|
3128
|
-
buttonClass
|
|
3129
|
-
),
|
|
3130
|
-
children: [
|
|
3131
|
-
/* @__PURE__ */ jsxRuntime.jsx(
|
|
3132
|
-
"span",
|
|
3133
|
-
{
|
|
3134
|
-
className: `text-sm ${disabled ? "text-gray-400" : selectedOption ? "text-gray-700" : "text-gray-400"}`,
|
|
3135
|
-
children: (selectedOption == null ? void 0 : selectedOption.name) || placeholder
|
|
3136
|
-
}
|
|
3137
|
-
),
|
|
3138
|
-
/* @__PURE__ */ jsxRuntime.jsx(
|
|
3139
|
-
"div",
|
|
3140
|
-
{
|
|
3141
|
-
className: `transition-transform duration-200 ${isOpen ? "rotate-180" : ""} ${disabled ? "text-gray-400" : ""}
|
|
3142
|
-
${hasIcon ? "block" : "hidden"}
|
|
3143
|
-
`,
|
|
3144
|
-
children: /* @__PURE__ */ jsxRuntime.jsxs(
|
|
3145
|
-
"svg",
|
|
3146
|
-
{
|
|
3147
|
-
className: "transform rotate-180",
|
|
3148
|
-
width: "20",
|
|
3149
|
-
height: "20",
|
|
3150
|
-
viewBox: "0 0 20 20",
|
|
3151
|
-
fill: "none",
|
|
3152
|
-
xmlns: "http://www.w3.org/2000/svg",
|
|
3153
|
-
children: [
|
|
3154
|
-
/* @__PURE__ */ jsxRuntime.jsx("g", { clipPath: "url(#clip0_10508_5931)", children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
3155
|
-
"path",
|
|
3156
|
-
{
|
|
3157
|
-
d: "M5.83333 11.6665L10 7.49984L14.1667 11.6665H5.83333Z",
|
|
3158
|
-
fill: "currentColor"
|
|
3159
|
-
}
|
|
3160
|
-
) }),
|
|
3161
|
-
/* @__PURE__ */ jsxRuntime.jsx("defs", { children: /* @__PURE__ */ jsxRuntime.jsx("clipPath", { id: "clip0_10508_5931", children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
3162
|
-
"rect",
|
|
3163
|
-
{
|
|
3164
|
-
width: "20",
|
|
3165
|
-
height: "20",
|
|
3166
|
-
fill: "white",
|
|
3167
|
-
transform: "matrix(1 0 0 -1 0 20)"
|
|
3168
|
-
}
|
|
3169
|
-
) }) })
|
|
3170
|
-
]
|
|
3171
|
-
}
|
|
3172
|
-
)
|
|
3173
|
-
}
|
|
3174
|
-
)
|
|
3175
|
-
]
|
|
3176
|
-
}
|
|
3177
|
-
),
|
|
3178
|
-
isOpen && !disabled && /* @__PURE__ */ jsxRuntime.jsx("div", { className: "absolute mt-1 w-full rounded-md bg-white shadow-lg z-20", children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "p-2 shadow-md border rounded-md max-h-[410px] flex flex-col", children: [
|
|
3110
|
+
const DropdownMenu = /* @__PURE__ */ jsxRuntime.jsx(
|
|
3111
|
+
"div",
|
|
3112
|
+
{
|
|
3113
|
+
ref: portalRef,
|
|
3114
|
+
style: {
|
|
3115
|
+
position: "absolute",
|
|
3116
|
+
top: `${dropdownPosition.top + 4}px`,
|
|
3117
|
+
left: `${dropdownPosition.left}px`,
|
|
3118
|
+
width: `${dropdownPosition.width}px`
|
|
3119
|
+
},
|
|
3120
|
+
className: "rounded-md bg-white shadow-lg z-50",
|
|
3121
|
+
children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "p-2 shadow-md border rounded-md max-h-[410px] flex flex-col", children: [
|
|
3179
3122
|
searchable && /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "relative", children: [
|
|
3180
3123
|
/* @__PURE__ */ jsxRuntime.jsx(
|
|
3181
3124
|
"input",
|
|
3182
3125
|
{
|
|
3183
3126
|
type: "text",
|
|
3127
|
+
autoFocus: true,
|
|
3184
3128
|
className: tailwindMerge.twMerge(
|
|
3185
3129
|
"input-placeholder-ellipsis w-full pr-[30px] h-[40px] px-2 py-1 rounded-md border border-gray-300 text-sm focus:border-1 focus:border-[#4683B4] focus:outline-none",
|
|
3186
3130
|
searchInputClass
|
|
@@ -3242,7 +3186,7 @@ function SingleSelectDropdown({
|
|
|
3242
3186
|
"div",
|
|
3243
3187
|
{
|
|
3244
3188
|
className: tailwindMerge.twMerge(
|
|
3245
|
-
`h-[40px] px-2 py-2 my-1 text-sm cursor-pointer select-none ${opt.id === value
|
|
3189
|
+
`h-[40px] px-2 py-2 my-1 text-sm cursor-pointer select-none rounded-md hover:bg-gray-100 ${opt.id === value ? "bg-[#ECF3F7] text-[#131414] font-semibold" : "text-[#131414]"}`,
|
|
3246
3190
|
displayItemClass
|
|
3247
3191
|
),
|
|
3248
3192
|
onClick: () => {
|
|
@@ -3260,7 +3204,76 @@ function SingleSelectDropdown({
|
|
|
3260
3204
|
]
|
|
3261
3205
|
}
|
|
3262
3206
|
)
|
|
3263
|
-
] })
|
|
3207
|
+
] })
|
|
3208
|
+
}
|
|
3209
|
+
);
|
|
3210
|
+
return /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
|
|
3211
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
3212
|
+
"label",
|
|
3213
|
+
{
|
|
3214
|
+
className: tailwindMerge.twMerge(
|
|
3215
|
+
"block py-1 pt-1 text-[14px] font-semibold mb-1 text-[#545454]",
|
|
3216
|
+
labelClass
|
|
3217
|
+
),
|
|
3218
|
+
style: { letterSpacing: "0.2px" },
|
|
3219
|
+
children: label
|
|
3220
|
+
}
|
|
3221
|
+
),
|
|
3222
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { ref: dropdownRef, className: "relative", children: [
|
|
3223
|
+
/* @__PURE__ */ jsxRuntime.jsxs(
|
|
3224
|
+
"div",
|
|
3225
|
+
{
|
|
3226
|
+
onClick: handleToggle,
|
|
3227
|
+
className: tailwindMerge.twMerge(
|
|
3228
|
+
`border-[1.5px] rounded-md h-[40px] pl-3 pr-2 py-2 bg-[#F8F8F8] cursor-pointer flex items-center justify-between ${disabled ? "bg-gray-100 cursor-not-allowed border-gray-200" : isOpen ? "border-[#4683B4]" : "border-[#E2E2E2]"}`,
|
|
3229
|
+
buttonClass
|
|
3230
|
+
),
|
|
3231
|
+
children: [
|
|
3232
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
3233
|
+
"span",
|
|
3234
|
+
{
|
|
3235
|
+
className: `text-sm ${disabled ? "text-gray-400" : selectedOption ? "text-gray-700" : "text-gray-400"}`,
|
|
3236
|
+
children: (selectedOption == null ? void 0 : selectedOption.name) || placeholder
|
|
3237
|
+
}
|
|
3238
|
+
),
|
|
3239
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
3240
|
+
"div",
|
|
3241
|
+
{
|
|
3242
|
+
className: `transition-transform duration-200 ${!isOpen ? "rotate-180" : ""} ${disabled ? "text-gray-400" : ""} ${hasIcon ? "block" : "hidden"}`,
|
|
3243
|
+
children: /* @__PURE__ */ jsxRuntime.jsxs(
|
|
3244
|
+
"svg",
|
|
3245
|
+
{
|
|
3246
|
+
width: "20",
|
|
3247
|
+
height: "20",
|
|
3248
|
+
viewBox: "0 0 20 20",
|
|
3249
|
+
fill: "none",
|
|
3250
|
+
xmlns: "http://www.w3.org/2000/svg",
|
|
3251
|
+
children: [
|
|
3252
|
+
/* @__PURE__ */ jsxRuntime.jsx("g", { clipPath: "url(#clip0_10508_5931)", children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
3253
|
+
"path",
|
|
3254
|
+
{
|
|
3255
|
+
d: "M5.83333 11.6665L10 7.49984L14.1667 11.6665H5.83333Z",
|
|
3256
|
+
fill: "currentColor"
|
|
3257
|
+
}
|
|
3258
|
+
) }),
|
|
3259
|
+
/* @__PURE__ */ jsxRuntime.jsx("defs", { children: /* @__PURE__ */ jsxRuntime.jsx("clipPath", { id: "clip0_10508_5931", children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
3260
|
+
"rect",
|
|
3261
|
+
{
|
|
3262
|
+
width: "20",
|
|
3263
|
+
height: "20",
|
|
3264
|
+
fill: "white",
|
|
3265
|
+
transform: "matrix(1 0 0 -1 0 20)"
|
|
3266
|
+
}
|
|
3267
|
+
) }) })
|
|
3268
|
+
]
|
|
3269
|
+
}
|
|
3270
|
+
)
|
|
3271
|
+
}
|
|
3272
|
+
)
|
|
3273
|
+
]
|
|
3274
|
+
}
|
|
3275
|
+
),
|
|
3276
|
+
isOpen && !disabled && reactDom.createPortal(DropdownMenu, document.body)
|
|
3264
3277
|
] })
|
|
3265
3278
|
] });
|
|
3266
3279
|
}
|