hi-tm 0.8.9 → 0.9.1
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.
|
@@ -41,7 +41,7 @@ const defaultStyles = {
|
|
|
41
41
|
trigger: 'flex items-center border rounded-md px-3 py-2 bg-white cursor-pointer',
|
|
42
42
|
input: 'w-full outline-none',
|
|
43
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',
|
|
44
|
+
option: 'py-2 px-3 cursor-pointer flex items-center gap-2', // Added gap-2 for spacing
|
|
45
45
|
selectedOption: 'font-medium',
|
|
46
46
|
highlightedOption: 'bg-blue-100',
|
|
47
47
|
createOption: 'flex items-center gap-2 py-2 px-3 cursor-pointer hover:bg-blue-50',
|
|
@@ -50,20 +50,34 @@ const defaultStyles = {
|
|
|
50
50
|
noResults: 'py-4 px-3 text-gray-500 flex flex-col items-center justify-center gap-2',
|
|
51
51
|
clearButton: 'p-1 rounded-full hover:bg-gray-100',
|
|
52
52
|
icon: 'w-4 h-4 text-gray-400',
|
|
53
|
-
separator: 'h-4 border-l mx-2',
|
|
53
|
+
separator: 'h-4 border-l mx-2',
|
|
54
|
+
selectedOptionIcon: 'w-4 h-4 mr-2 text-blue-500 flex-shrink-0', // Added style for selected option icon
|
|
54
55
|
};
|
|
55
56
|
// Helper function to render different icon types
|
|
56
57
|
const renderIcon = (icon, className = '') => {
|
|
58
|
+
if (react_1.default.isValidElement(icon)) {
|
|
59
|
+
// Check if the element can accept className
|
|
60
|
+
if ('props' in icon && typeof icon.props === 'object' && icon.props !== null) {
|
|
61
|
+
// Create a new object with existing props plus className
|
|
62
|
+
const props = {
|
|
63
|
+
...icon.props,
|
|
64
|
+
className: `${icon.props.className || ''} ${className}`.trim(),
|
|
65
|
+
};
|
|
66
|
+
// Return a new element with the updated props
|
|
67
|
+
return react_1.default.cloneElement(icon, props);
|
|
68
|
+
}
|
|
69
|
+
// If we can't add className, just return the element as-is
|
|
70
|
+
return icon;
|
|
71
|
+
}
|
|
57
72
|
if (typeof icon === 'string') {
|
|
58
|
-
return react_1.default.createElement("
|
|
73
|
+
return react_1.default.createElement("span", { className: className }, icon);
|
|
59
74
|
}
|
|
60
|
-
|
|
75
|
+
if (typeof icon === 'object' && icon && 'src' in icon) {
|
|
61
76
|
const img = icon;
|
|
62
77
|
return react_1.default.createElement("img", { src: img.src || '/placeholder.svg', alt: img.alt || '', className: className });
|
|
63
78
|
}
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
}
|
|
79
|
+
// For any other case (like JSX.Element or null/undefined)
|
|
80
|
+
return icon;
|
|
67
81
|
};
|
|
68
82
|
// Helper function to render the no results message
|
|
69
83
|
const renderNoResults = (noResults, className, searchIcon) => {
|
|
@@ -349,7 +363,6 @@ function CreatableSelect({ options = [], value, onChange, onClick, onValueChange
|
|
|
349
363
|
setHasSearched(false);
|
|
350
364
|
}
|
|
351
365
|
}, [isMultiSelect, selectedValues, deriveValue, emitSelection]);
|
|
352
|
-
const showLoading = isLoading || internalLoading;
|
|
353
366
|
const handleAddIconClick = (0, react_1.useCallback)((e) => {
|
|
354
367
|
e.preventDefault();
|
|
355
368
|
e.stopPropagation();
|
|
@@ -366,6 +379,11 @@ function CreatableSelect({ options = [], value, onChange, onClick, onValueChange
|
|
|
366
379
|
}
|
|
367
380
|
}
|
|
368
381
|
}, [isDisabled, isOpen]);
|
|
382
|
+
const showLoading = isLoading || internalLoading;
|
|
383
|
+
// Helper function to check if an option is selected
|
|
384
|
+
const isOptionSelected = (0, react_1.useCallback)((option) => {
|
|
385
|
+
return selectedValues.some((val) => deriveValue(val) === deriveValue(option));
|
|
386
|
+
}, [selectedValues, deriveValue]);
|
|
369
387
|
return (react_1.default.createElement("div", { ref: containerRef, className: `relative w-full ${className} ${styles.container}`, onKeyDown: handleKeyDown },
|
|
370
388
|
label && react_1.default.createElement("label", { className: "block text-sm font-medium text-gray-700 mb-1" }, label),
|
|
371
389
|
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 },
|
|
@@ -385,12 +403,12 @@ function CreatableSelect({ options = [], value, onChange, onClick, onValueChange
|
|
|
385
403
|
isOpen && (react_1.default.createElement("div", { className: styles.dropdown }, showLoading ? (react_1.default.createElement("div", { className: styles.loadingState },
|
|
386
404
|
renderIcon(iconSrc.loading, `animate-spin mr-2 ${styles.icon}`),
|
|
387
405
|
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) =>
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
406
|
+
filteredOptions.length > 0 && (react_1.default.createElement(react_1.default.Fragment, null, filteredOptions.map((option, index) => {
|
|
407
|
+
const isSelected = isOptionSelected(option);
|
|
408
|
+
return (react_1.default.createElement("div", { key: deriveValue(option), className: `${styles.option} ${index === highlightedIndex ? styles.highlightedOption : 'hover:bg-gray-50'}`, onClick: () => selectOption(option), onMouseEnter: () => setHighlightedIndex(index) },
|
|
409
|
+
isSelected && (react_1.default.createElement("span", { className: styles.selectedOptionIcon }, renderIcon(icons.checkmark, styles.selectedOptionIcon))),
|
|
410
|
+
react_1.default.createElement("span", { className: isSelected ? styles.selectedOption : '' }, deriveLabel(option) || deriveValue(option))));
|
|
411
|
+
}))),
|
|
394
412
|
filteredOptions.length === 0 && !inputValue && (react_1.default.createElement("div", { className: styles.noOptions }, noOptionsMessage)),
|
|
395
413
|
filteredOptions.length === 0 &&
|
|
396
414
|
inputValue &&
|