hi-tm 0.9.5 → 0.9.7
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,3 +1,3 @@
|
|
|
1
|
-
import React from
|
|
2
|
-
import type { SelectOption, CreatableSelectProps } from
|
|
1
|
+
import React from "react";
|
|
2
|
+
import type { SelectOption, CreatableSelectProps } from "../../types/DropDown/CreatableDropDown";
|
|
3
3
|
export default function CreatableSelect<T = SelectOption>({ options, value, onChange, onClick, onValueChange, onCreateOption, placeholder, isLoading, isDisabled, isCreatable, isMultiSelect, noOptionsMessage, noResultsFound, loadingMessage, createOptionMessage, className, tailwindStyle, iconSrc, fetchOptions, label, onAddClick, getOptionLabel, getOptionValue, }: CreatableSelectProps<T>): React.JSX.Element;
|
|
@@ -37,29 +37,29 @@ exports.default = CreatableSelect;
|
|
|
37
37
|
const react_1 = __importStar(require("react"));
|
|
38
38
|
// Default Tailwind styles
|
|
39
39
|
const defaultStyles = {
|
|
40
|
-
container:
|
|
41
|
-
trigger:
|
|
42
|
-
input:
|
|
43
|
-
dropdown:
|
|
44
|
-
option:
|
|
45
|
-
selectedOption:
|
|
46
|
-
highlightedOption:
|
|
47
|
-
createOption:
|
|
48
|
-
loadingState:
|
|
49
|
-
noOptions:
|
|
50
|
-
noResults:
|
|
51
|
-
clearButton:
|
|
52
|
-
icon:
|
|
53
|
-
separator:
|
|
40
|
+
container: "",
|
|
41
|
+
trigger: "flex items-center border rounded-md px-3 py-2 bg-white cursor-pointer",
|
|
42
|
+
input: "w-full outline-none",
|
|
43
|
+
dropdown: "absolute z-10 w-full mt-1 bg-white border border-gray-300 rounded-md shadow-lg max-h-60 overflow-y-auto",
|
|
44
|
+
option: "py-2 px-3 cursor-pointer flex items-center",
|
|
45
|
+
selectedOption: "font-medium",
|
|
46
|
+
highlightedOption: "bg-blue-100",
|
|
47
|
+
createOption: "flex items-center gap-2 py-2 px-3 cursor-pointer hover:bg-blue-50",
|
|
48
|
+
loadingState: "flex items-center justify-center py-2 text-gray-500",
|
|
49
|
+
noOptions: "py-2 px-3 text-gray-500",
|
|
50
|
+
noResults: "py-4 px-3 text-gray-500 flex flex-col items-center justify-center gap-2",
|
|
51
|
+
clearButton: "p-1 rounded-full hover:bg-gray-100",
|
|
52
|
+
icon: "w-4 h-4 text-gray-400",
|
|
53
|
+
separator: "h-4 border-l mx-2", // Style for the vertical line separator
|
|
54
54
|
};
|
|
55
55
|
// Helper function to render different icon types
|
|
56
|
-
const renderIcon = (icon, className =
|
|
57
|
-
if (typeof icon ===
|
|
58
|
-
return react_1.default.createElement("img", { src: icon ||
|
|
56
|
+
const renderIcon = (icon, className = "") => {
|
|
57
|
+
if (typeof icon === "string") {
|
|
58
|
+
return (react_1.default.createElement("img", { src: icon || "/placeholder.svg", alt: "", className: className }));
|
|
59
59
|
}
|
|
60
|
-
else if (typeof icon ===
|
|
60
|
+
else if (typeof icon === "object" && "src" in icon) {
|
|
61
61
|
const img = icon;
|
|
62
|
-
return react_1.default.createElement("img", { src: img.src ||
|
|
62
|
+
return (react_1.default.createElement("img", { src: img.src || "/placeholder.svg", alt: img.alt || "", className: className }));
|
|
63
63
|
}
|
|
64
64
|
else {
|
|
65
65
|
return icon;
|
|
@@ -69,35 +69,37 @@ const renderIcon = (icon, className = '') => {
|
|
|
69
69
|
const renderNoResults = (noResults, className, searchIcon) => {
|
|
70
70
|
if (!noResults) {
|
|
71
71
|
return (react_1.default.createElement("div", { className: className },
|
|
72
|
-
renderIcon(searchIcon,
|
|
72
|
+
renderIcon(searchIcon, "w-6 h-6 mb-1"),
|
|
73
73
|
react_1.default.createElement("span", null, "\u0645\u0648\u0631\u062F\u06CC \u06CC\u0627\u0641\u062A \u0646\u0634\u062F")));
|
|
74
74
|
}
|
|
75
|
-
if (typeof noResults ===
|
|
75
|
+
if (typeof noResults === "string") {
|
|
76
76
|
return react_1.default.createElement("div", { className: className }, noResults);
|
|
77
77
|
}
|
|
78
|
-
else if (typeof noResults ===
|
|
78
|
+
else if (typeof noResults === "object" &&
|
|
79
|
+
noResults &&
|
|
80
|
+
"text" in noResults) {
|
|
79
81
|
const withText = noResults;
|
|
80
82
|
return (react_1.default.createElement("div", { className: className },
|
|
81
83
|
withText.icon
|
|
82
|
-
? renderIcon(withText.icon,
|
|
83
|
-
: renderIcon(searchIcon,
|
|
84
|
+
? renderIcon(withText.icon, "w-6 h-6 mb-1")
|
|
85
|
+
: renderIcon(searchIcon, "w-6 h-6 mb-1"),
|
|
84
86
|
react_1.default.createElement("span", null, withText.text)));
|
|
85
87
|
}
|
|
86
88
|
else {
|
|
87
89
|
return noResults;
|
|
88
90
|
}
|
|
89
91
|
};
|
|
90
|
-
function CreatableSelect({ options = [], value, onChange, onClick, onValueChange, onCreateOption, placeholder =
|
|
92
|
+
function CreatableSelect({ options = [], value, onChange, onClick, onValueChange, onCreateOption, placeholder = "جستوجو", isLoading = false, isDisabled = false, isCreatable = true, isMultiSelect = false, noOptionsMessage = "مقدار پیشفرضی وجود ندارد", noResultsFound, loadingMessage = "در حال بارگذاری...", createOptionMessage = "ایجاد ", className = "", tailwindStyle = {}, iconSrc = {}, fetchOptions, label, onAddClick, getOptionLabel, getOptionValue, }) {
|
|
91
93
|
// Default icons
|
|
92
94
|
const defaultIcons = {
|
|
93
|
-
dropdownOpen:
|
|
94
|
-
dropdownClosed:
|
|
95
|
-
checkmark:
|
|
96
|
-
loading:
|
|
97
|
-
clear:
|
|
98
|
-
create:
|
|
99
|
-
xmark:
|
|
100
|
-
hasAdd:
|
|
95
|
+
dropdownOpen: "▼",
|
|
96
|
+
dropdownClosed: "▶",
|
|
97
|
+
checkmark: "✓",
|
|
98
|
+
loading: "⏳",
|
|
99
|
+
clear: "✕",
|
|
100
|
+
create: "➕",
|
|
101
|
+
xmark: "✕",
|
|
102
|
+
hasAdd: "➕",
|
|
101
103
|
};
|
|
102
104
|
// Merge provided icons with defaults
|
|
103
105
|
const icons = { ...defaultIcons, ...iconSrc };
|
|
@@ -111,7 +113,7 @@ function CreatableSelect({ options = [], value, onChange, onClick, onValueChange
|
|
|
111
113
|
return getOptionLabel(option);
|
|
112
114
|
const anyOption = option;
|
|
113
115
|
const label = anyOption.label ?? anyOption.content ?? anyOption.value;
|
|
114
|
-
const result = String(label ??
|
|
116
|
+
const result = String(label ?? "");
|
|
115
117
|
return result;
|
|
116
118
|
}, [getOptionLabel]);
|
|
117
119
|
const deriveValue = (0, react_1.useCallback)((option) => {
|
|
@@ -123,12 +125,13 @@ function CreatableSelect({ options = [], value, onChange, onClick, onValueChange
|
|
|
123
125
|
return str;
|
|
124
126
|
}, [getOptionValue, deriveLabel]);
|
|
125
127
|
const [isOpen, setIsOpen] = (0, react_1.useState)(false);
|
|
126
|
-
const [inputValue, setInputValue] = (0, react_1.useState)(
|
|
128
|
+
const [inputValue, setInputValue] = (0, react_1.useState)("");
|
|
127
129
|
const [filteredOptions, setFilteredOptions] = (0, react_1.useState)(options ?? []);
|
|
128
130
|
const [highlightedIndex, setHighlightedIndex] = (0, react_1.useState)(0);
|
|
129
131
|
const [internalLoading, setInternalLoading] = (0, react_1.useState)(false);
|
|
130
132
|
const [hasSearched, setHasSearched] = (0, react_1.useState)(false);
|
|
131
133
|
const [selectedValues, setSelectedValues] = (0, react_1.useState)([]);
|
|
134
|
+
const [showAllOptions, setShowAllOptions] = (0, react_1.useState)(false);
|
|
132
135
|
const containerRef = (0, react_1.useRef)(null);
|
|
133
136
|
const inputRef = (0, react_1.useRef)(null);
|
|
134
137
|
// Sync external value (ids or option objects) with internal selectedValues state
|
|
@@ -145,7 +148,7 @@ function CreatableSelect({ options = [], value, onChange, onClick, onValueChange
|
|
|
145
148
|
const external = Array.isArray(value) ? value : [value];
|
|
146
149
|
const desiredKeys = external.map((v) => {
|
|
147
150
|
const t = typeof v;
|
|
148
|
-
if (t ===
|
|
151
|
+
if (t === "string" || t === "number")
|
|
149
152
|
return String(v);
|
|
150
153
|
return deriveValue(v);
|
|
151
154
|
});
|
|
@@ -159,7 +162,7 @@ function CreatableSelect({ options = [], value, onChange, onClick, onValueChange
|
|
|
159
162
|
}
|
|
160
163
|
else {
|
|
161
164
|
const original = external[idx];
|
|
162
|
-
if (typeof original ===
|
|
165
|
+
if (typeof original === "object" && original !== null) {
|
|
163
166
|
orderedMatched.push(original);
|
|
164
167
|
}
|
|
165
168
|
}
|
|
@@ -187,7 +190,7 @@ function CreatableSelect({ options = [], value, onChange, onClick, onValueChange
|
|
|
187
190
|
}, [options, hasSearched]);
|
|
188
191
|
// Reset filtered list when input cleared
|
|
189
192
|
(0, react_1.useEffect)(() => {
|
|
190
|
-
if (inputValue ===
|
|
193
|
+
if (inputValue === "") {
|
|
191
194
|
setFilteredOptions(options ?? []);
|
|
192
195
|
setHasSearched(false);
|
|
193
196
|
}
|
|
@@ -195,22 +198,54 @@ function CreatableSelect({ options = [], value, onChange, onClick, onValueChange
|
|
|
195
198
|
// Close on outside click
|
|
196
199
|
(0, react_1.useEffect)(() => {
|
|
197
200
|
const handler = (e) => {
|
|
198
|
-
if (containerRef.current &&
|
|
201
|
+
if (containerRef.current &&
|
|
202
|
+
!containerRef.current.contains(e.target)) {
|
|
199
203
|
setIsOpen(false);
|
|
200
204
|
}
|
|
201
205
|
};
|
|
202
|
-
document.addEventListener(
|
|
206
|
+
document.addEventListener("click", handler);
|
|
203
207
|
return () => {
|
|
204
|
-
document.removeEventListener(
|
|
208
|
+
document.removeEventListener("click", handler);
|
|
205
209
|
};
|
|
206
210
|
}, []);
|
|
211
|
+
// const handleInputChange = useCallback(
|
|
212
|
+
// async (e: ChangeEvent<HTMLInputElement>) => {
|
|
213
|
+
// const next = e.target.value;
|
|
214
|
+
// setInputValue(next);
|
|
215
|
+
// setIsOpen(true);
|
|
216
|
+
// if (onChange) onChange(e);
|
|
217
|
+
// if (fetchOptions && next.trim() !== "") {
|
|
218
|
+
// setInternalLoading(true);
|
|
219
|
+
// setHasSearched(true);
|
|
220
|
+
// try {
|
|
221
|
+
// const newOptions = await fetchOptions(next);
|
|
222
|
+
// setFilteredOptions(newOptions ?? []);
|
|
223
|
+
// } catch {
|
|
224
|
+
// } finally {
|
|
225
|
+
// setInternalLoading(false);
|
|
226
|
+
// }
|
|
227
|
+
// } else if (next.trim() === "") {
|
|
228
|
+
// setFilteredOptions(options ?? []);
|
|
229
|
+
// setHasSearched(false);
|
|
230
|
+
// } else {
|
|
231
|
+
// const searchText = String(next).trim().toLowerCase();
|
|
232
|
+
// const filtered = (options ?? []).filter((option) =>
|
|
233
|
+
// deriveLabel(option).toLowerCase().includes(searchText)
|
|
234
|
+
// );
|
|
235
|
+
// setFilteredOptions(filtered);
|
|
236
|
+
// setHasSearched(true);
|
|
237
|
+
// }
|
|
238
|
+
// },
|
|
239
|
+
// [onChange, fetchOptions, options, deriveLabel]
|
|
240
|
+
// );
|
|
207
241
|
const handleInputChange = (0, react_1.useCallback)(async (e) => {
|
|
208
242
|
const next = e.target.value;
|
|
209
243
|
setInputValue(next);
|
|
210
244
|
setIsOpen(true);
|
|
245
|
+
setShowAllOptions(false); // ریست کردن حالت نمایش همه
|
|
211
246
|
if (onChange)
|
|
212
247
|
onChange(e);
|
|
213
|
-
if (fetchOptions && next.trim() !==
|
|
248
|
+
if (fetchOptions && next.trim() !== "") {
|
|
214
249
|
setInternalLoading(true);
|
|
215
250
|
setHasSearched(true);
|
|
216
251
|
try {
|
|
@@ -223,7 +258,7 @@ function CreatableSelect({ options = [], value, onChange, onClick, onValueChange
|
|
|
223
258
|
setInternalLoading(false);
|
|
224
259
|
}
|
|
225
260
|
}
|
|
226
|
-
else if (next.trim() ===
|
|
261
|
+
else if (next.trim() === "") {
|
|
227
262
|
setFilteredOptions(options ?? []);
|
|
228
263
|
setHasSearched(false);
|
|
229
264
|
}
|
|
@@ -238,10 +273,11 @@ function CreatableSelect({ options = [], value, onChange, onClick, onValueChange
|
|
|
238
273
|
if (isDisabled)
|
|
239
274
|
return;
|
|
240
275
|
switch (e.key) {
|
|
241
|
-
case
|
|
276
|
+
case "Enter":
|
|
242
277
|
e.preventDefault();
|
|
243
278
|
if (isOpen) {
|
|
244
|
-
if (filteredOptions.length > 0 &&
|
|
279
|
+
if (filteredOptions.length > 0 &&
|
|
280
|
+
highlightedIndex < filteredOptions.length) {
|
|
245
281
|
selectOption(filteredOptions[highlightedIndex]);
|
|
246
282
|
}
|
|
247
283
|
else if (isCreatable &&
|
|
@@ -255,29 +291,37 @@ function CreatableSelect({ options = [], value, onChange, onClick, onValueChange
|
|
|
255
291
|
setIsOpen(true);
|
|
256
292
|
}
|
|
257
293
|
break;
|
|
258
|
-
case
|
|
294
|
+
case "Escape":
|
|
259
295
|
setIsOpen(false);
|
|
260
296
|
break;
|
|
261
|
-
case
|
|
297
|
+
case "ArrowUp":
|
|
262
298
|
e.preventDefault();
|
|
263
299
|
if (isOpen) {
|
|
264
|
-
setHighlightedIndex((prev) =>
|
|
300
|
+
setHighlightedIndex((prev) => prev > 0 ? prev - 1 : filteredOptions.length - 1);
|
|
265
301
|
}
|
|
266
302
|
else {
|
|
267
303
|
setIsOpen(true);
|
|
268
304
|
}
|
|
269
305
|
break;
|
|
270
|
-
case
|
|
306
|
+
case "ArrowDown":
|
|
271
307
|
e.preventDefault();
|
|
272
308
|
if (isOpen) {
|
|
273
|
-
setHighlightedIndex((prev) =>
|
|
309
|
+
setHighlightedIndex((prev) => prev < filteredOptions.length - 1 ? prev + 1 : 0);
|
|
274
310
|
}
|
|
275
311
|
else {
|
|
276
312
|
setIsOpen(true);
|
|
277
313
|
}
|
|
278
314
|
break;
|
|
279
315
|
}
|
|
280
|
-
}, [
|
|
316
|
+
}, [
|
|
317
|
+
isDisabled,
|
|
318
|
+
isOpen,
|
|
319
|
+
filteredOptions,
|
|
320
|
+
highlightedIndex,
|
|
321
|
+
isCreatable,
|
|
322
|
+
inputValue,
|
|
323
|
+
deriveLabel,
|
|
324
|
+
]);
|
|
281
325
|
const emitSelection = (0, react_1.useCallback)((next) => {
|
|
282
326
|
// Backward-compatible callback
|
|
283
327
|
if (onClick) {
|
|
@@ -292,16 +336,18 @@ function CreatableSelect({ options = [], value, onChange, onClick, onValueChange
|
|
|
292
336
|
return;
|
|
293
337
|
setInternalLoading(true);
|
|
294
338
|
try {
|
|
295
|
-
const created = onCreateOption
|
|
339
|
+
const created = onCreateOption
|
|
340
|
+
? await onCreateOption(inputValue)
|
|
341
|
+
: undefined;
|
|
296
342
|
const safeInputValue = String(inputValue);
|
|
297
343
|
const fallback = {
|
|
298
344
|
label: safeInputValue,
|
|
299
345
|
content: safeInputValue,
|
|
300
|
-
value: safeInputValue.replace(/\s+/g,
|
|
346
|
+
value: safeInputValue.replace(/\s+/g, "-"),
|
|
301
347
|
};
|
|
302
348
|
const optionToAdd = created ?? fallback;
|
|
303
349
|
selectOption(optionToAdd);
|
|
304
|
-
setInputValue(
|
|
350
|
+
setInputValue("");
|
|
305
351
|
setHasSearched(false);
|
|
306
352
|
}
|
|
307
353
|
catch {
|
|
@@ -336,7 +382,7 @@ function CreatableSelect({ options = [], value, onChange, onClick, onValueChange
|
|
|
336
382
|
setSelectedValues(next);
|
|
337
383
|
emitSelection(next);
|
|
338
384
|
// In multi-select mode, keep the input open and clear input for next search
|
|
339
|
-
setInputValue(
|
|
385
|
+
setInputValue("");
|
|
340
386
|
setHasSearched(false);
|
|
341
387
|
// Don't close dropdown in multi-select mode
|
|
342
388
|
}
|
|
@@ -344,7 +390,7 @@ function CreatableSelect({ options = [], value, onChange, onClick, onValueChange
|
|
|
344
390
|
const next = [option];
|
|
345
391
|
setSelectedValues(next);
|
|
346
392
|
emitSelection(next);
|
|
347
|
-
setInputValue(
|
|
393
|
+
setInputValue("");
|
|
348
394
|
setIsOpen(false);
|
|
349
395
|
setHasSearched(false);
|
|
350
396
|
}
|
|
@@ -357,45 +403,73 @@ function CreatableSelect({ options = [], value, onChange, onClick, onValueChange
|
|
|
357
403
|
onAddClick(true);
|
|
358
404
|
}
|
|
359
405
|
}, [onAddClick]);
|
|
360
|
-
const handleTriggerClick =
|
|
406
|
+
// const handleTriggerClick = useCallback(
|
|
407
|
+
// (e: React.MouseEvent) => {
|
|
408
|
+
// e.preventDefault();
|
|
409
|
+
// if (!isDisabled) {
|
|
410
|
+
// setIsOpen((prev) => !prev);
|
|
411
|
+
// if (!isOpen && inputRef.current) {
|
|
412
|
+
// inputRef.current.focus({ preventScroll: true });
|
|
413
|
+
// }
|
|
414
|
+
// }
|
|
415
|
+
// },
|
|
416
|
+
// [isDisabled, isOpen]
|
|
417
|
+
// );
|
|
418
|
+
const handleTriggerClick = (0, react_1.useCallback)(async (e) => {
|
|
361
419
|
e.preventDefault();
|
|
362
420
|
if (!isDisabled) {
|
|
363
421
|
setIsOpen((prev) => !prev);
|
|
364
422
|
if (!isOpen && inputRef.current) {
|
|
365
423
|
inputRef.current.focus({ preventScroll: true });
|
|
366
424
|
}
|
|
425
|
+
// اگر اینپوت خالی است و روی آن کلیک شد، لیست کامل را نمایش دهید
|
|
426
|
+
if (inputValue.trim() === "" && fetchOptions) {
|
|
427
|
+
setInternalLoading(true);
|
|
428
|
+
try {
|
|
429
|
+
const allOptions = await fetchOptions("");
|
|
430
|
+
setFilteredOptions(allOptions ?? []);
|
|
431
|
+
setShowAllOptions(true);
|
|
432
|
+
}
|
|
433
|
+
catch {
|
|
434
|
+
}
|
|
435
|
+
finally {
|
|
436
|
+
setInternalLoading(false);
|
|
437
|
+
}
|
|
438
|
+
}
|
|
367
439
|
}
|
|
368
|
-
}, [isDisabled, isOpen]);
|
|
440
|
+
}, [isDisabled, isOpen, inputValue, fetchOptions]);
|
|
369
441
|
return (react_1.default.createElement("div", { ref: containerRef, className: `relative w-full ${className} ${styles.container}`, onKeyDown: handleKeyDown },
|
|
370
|
-
label && react_1.default.createElement("label", { className: "block text-sm font-medium text-gray-700 mb-1" }, label),
|
|
371
|
-
react_1.default.createElement("div", { className: `${styles.trigger} ${isDisabled ?
|
|
442
|
+
label && (react_1.default.createElement("label", { className: "block text-sm font-medium text-gray-700 mb-1" }, label)),
|
|
443
|
+
react_1.default.createElement("div", { className: `${styles.trigger} ${isDisabled ? "bg-gray-100 cursor-not-allowed" : ""} ${isOpen ? "border-blue-500 ring-2 ring-blue-100" : "border-gray-300"}`, onClick: handleTriggerClick },
|
|
372
444
|
react_1.default.createElement("div", { className: "flex-grow flex items-center overflow-x-auto no-scrollbar" },
|
|
373
445
|
react_1.default.createElement("div", { className: "flex items-center gap-2 flex-nowrap" },
|
|
374
446
|
selectedValues.length > 0 &&
|
|
375
447
|
selectedValues.map((val) => (react_1.default.createElement("div", { key: deriveValue(val), className: "flex-shrink-0 flex items-center bg-gray-200 rounded-md px-2 py-1" },
|
|
376
448
|
react_1.default.createElement("span", { className: "truncate" }, deriveLabel(val)),
|
|
377
449
|
react_1.default.createElement("button", { type: "button", onClick: (e) => clearValue(e, val), className: styles.clearButton }, renderIcon(icons.clear, styles.icon))))),
|
|
378
|
-
react_1.default.createElement("input", { ref: inputRef, type: "text", className: `${styles.input} ${isDisabled ?
|
|
450
|
+
react_1.default.createElement("input", { ref: inputRef, type: "text", className: `${styles.input} ${isDisabled ? "bg-gray-100" : ""} min-w-[80px] flex-shrink-0`, placeholder: selectedValues.length > 0 ? "" : placeholder, value: inputValue, onChange: handleInputChange, disabled: isDisabled, onClick: (e) => e.stopPropagation() }))),
|
|
379
451
|
react_1.default.createElement("div", { className: "flex-shrink-0 flex items-center gap-1 ml-2" },
|
|
380
452
|
iconSrc.hasAdd && (react_1.default.createElement("button", { type: "button", onClick: handleAddIconClick, className: styles.clearButton }, renderIcon(iconSrc.hasAdd, styles.icon))),
|
|
381
453
|
styles.separator && react_1.default.createElement("div", { className: styles.separator }),
|
|
382
454
|
react_1.default.createElement("button", { type: "button", onClick: toggleDropdown }, isOpen
|
|
383
|
-
? renderIcon(iconSrc.dropdownOpen, `${styles.icon} ${styles.spinAnimation ||
|
|
455
|
+
? renderIcon(iconSrc.dropdownOpen, `${styles.icon} ${styles.spinAnimation || ""}`)
|
|
384
456
|
: renderIcon(iconSrc.dropdownClosed, styles.icon)))),
|
|
385
457
|
isOpen && (react_1.default.createElement("div", { className: styles.dropdown }, showLoading ? (react_1.default.createElement("div", { className: styles.loadingState },
|
|
386
458
|
renderIcon(iconSrc.loading, `animate-spin mr-2 ${styles.icon}`),
|
|
387
459
|
loadingMessage)) : (react_1.default.createElement(react_1.default.Fragment, null,
|
|
388
|
-
filteredOptions.length > 0 && (react_1.default.createElement(react_1.default.Fragment, null, filteredOptions.map((option, index) => (react_1.default.createElement("div", { key: deriveValue(option), className: `${styles.option} ${index === highlightedIndex
|
|
460
|
+
filteredOptions.length > 0 && (react_1.default.createElement(react_1.default.Fragment, null, filteredOptions.map((option, index) => (react_1.default.createElement("div", { key: deriveValue(option), className: `${styles.option} ${index === highlightedIndex
|
|
461
|
+
? styles.highlightedOption
|
|
462
|
+
: "hover:bg-gray-50"}`, onClick: () => selectOption(option), onMouseEnter: () => setHighlightedIndex(index) },
|
|
389
463
|
selectedValues.some((val) => deriveValue(val) === deriveValue(option)) &&
|
|
390
|
-
renderIcon(iconSrc.checkmark,
|
|
464
|
+
renderIcon(iconSrc.checkmark, "w-4 h-4 mr-2 text-blue-500"),
|
|
391
465
|
react_1.default.createElement("span", { className: selectedValues.some((val) => deriveValue(val) === deriveValue(option))
|
|
392
466
|
? styles.selectedOption
|
|
393
|
-
:
|
|
467
|
+
: "" }, deriveLabel(option) || deriveValue(option))))))),
|
|
394
468
|
filteredOptions.length === 0 && !inputValue && (react_1.default.createElement("div", { className: styles.noOptions }, noOptionsMessage)),
|
|
395
469
|
filteredOptions.length === 0 &&
|
|
396
470
|
inputValue &&
|
|
397
471
|
hasSearched &&
|
|
398
|
-
renderNoResults(noResultsFound, styles.noResults ??
|
|
472
|
+
renderNoResults(noResultsFound, styles.noResults ?? "", iconSrc.create),
|
|
399
473
|
isCreatable &&
|
|
400
474
|
inputValue &&
|
|
401
475
|
!options?.some((o) => deriveLabel(o) === inputValue) && (react_1.default.createElement("div", { className: styles.createOption, onClick: handleCreateOption },
|