hi-tm 0.5.9 → 0.6.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.
|
@@ -87,7 +87,20 @@ const renderNoResults = (noResults, className, searchIcon) => {
|
|
|
87
87
|
return noResults;
|
|
88
88
|
}
|
|
89
89
|
};
|
|
90
|
-
function CreatableSelect({ options = [], value, onChange, onClick, onValueChange, onCreateOption, placeholder = 'Select...', isLoading = false, isDisabled = false, isCreatable = true, isMultiSelect = false, noOptionsMessage = 'No options available', noResultsFound, loadingMessage = 'Loading...', createOptionMessage = 'Create option', className = '', tailwindStyle = {}, iconSrc, fetchOptions, label, onAddClick, getOptionLabel, getOptionValue, }) {
|
|
90
|
+
function CreatableSelect({ options = [], value, onChange, onClick, onValueChange, onCreateOption, placeholder = 'Select...', isLoading = false, isDisabled = false, isCreatable = true, isMultiSelect = false, noOptionsMessage = 'No options available', noResultsFound, loadingMessage = 'Loading...', createOptionMessage = 'Create option', className = '', tailwindStyle = {}, iconSrc = {}, fetchOptions, label, onAddClick, getOptionLabel, getOptionValue, }) {
|
|
91
|
+
// Default icons
|
|
92
|
+
const defaultIcons = {
|
|
93
|
+
dropdownOpen: '▼',
|
|
94
|
+
dropdownClosed: '▶',
|
|
95
|
+
checkmark: '✓',
|
|
96
|
+
loading: '⏳',
|
|
97
|
+
clear: '✕',
|
|
98
|
+
create: '➕',
|
|
99
|
+
xmark: '✕',
|
|
100
|
+
hasAdd: '➕',
|
|
101
|
+
};
|
|
102
|
+
// Merge provided icons with defaults
|
|
103
|
+
const icons = { ...defaultIcons, ...iconSrc };
|
|
91
104
|
const styles = (0, react_1.useMemo)(() => ({
|
|
92
105
|
...defaultStyles,
|
|
93
106
|
...tailwindStyle,
|
|
@@ -98,7 +111,9 @@ function CreatableSelect({ options = [], value, onChange, onClick, onValueChange
|
|
|
98
111
|
return getOptionLabel(option);
|
|
99
112
|
const anyOption = option;
|
|
100
113
|
const label = anyOption.label ?? anyOption.content ?? anyOption.value;
|
|
101
|
-
|
|
114
|
+
const result = String(label ?? '');
|
|
115
|
+
console.log('deriveLabel for option:', option, 'returning:', result);
|
|
116
|
+
return result;
|
|
102
117
|
}, [getOptionLabel]);
|
|
103
118
|
const deriveValue = (0, react_1.useCallback)((option) => {
|
|
104
119
|
if (getOptionValue)
|
|
@@ -106,6 +121,7 @@ function CreatableSelect({ options = [], value, onChange, onClick, onValueChange
|
|
|
106
121
|
const anyOption = option;
|
|
107
122
|
const base = anyOption.value ?? anyOption.label ?? anyOption.content;
|
|
108
123
|
const str = String(base ?? deriveLabel(option));
|
|
124
|
+
console.log('deriveValue for option:', option, 'returning:', str);
|
|
109
125
|
return str;
|
|
110
126
|
}, [getOptionValue, deriveLabel]);
|
|
111
127
|
const [isOpen, setIsOpen] = (0, react_1.useState)(false);
|
|
@@ -114,9 +130,31 @@ function CreatableSelect({ options = [], value, onChange, onClick, onValueChange
|
|
|
114
130
|
const [highlightedIndex, setHighlightedIndex] = (0, react_1.useState)(0);
|
|
115
131
|
const [internalLoading, setInternalLoading] = (0, react_1.useState)(false);
|
|
116
132
|
const [hasSearched, setHasSearched] = (0, react_1.useState)(false);
|
|
117
|
-
const [selectedValues, setSelectedValues] = (0, react_1.useState)(
|
|
133
|
+
const [selectedValues, setSelectedValues] = (0, react_1.useState)([]);
|
|
118
134
|
const containerRef = (0, react_1.useRef)(null);
|
|
119
135
|
const inputRef = (0, react_1.useRef)(null);
|
|
136
|
+
// Sync external value prop with internal selectedValues state
|
|
137
|
+
(0, react_1.useEffect)(() => {
|
|
138
|
+
console.log('useEffect triggered with value:', value, 'isMultiSelect:', isMultiSelect);
|
|
139
|
+
if (value === null || value === undefined) {
|
|
140
|
+
console.log('Setting selectedValues to empty array');
|
|
141
|
+
setSelectedValues([]);
|
|
142
|
+
}
|
|
143
|
+
else if (Array.isArray(value)) {
|
|
144
|
+
if (isMultiSelect) {
|
|
145
|
+
console.log('Setting selectedValues to array:', value);
|
|
146
|
+
setSelectedValues(value);
|
|
147
|
+
}
|
|
148
|
+
else {
|
|
149
|
+
console.log('Setting selectedValues to first item of array:', value.length > 0 ? [value[0]] : []);
|
|
150
|
+
setSelectedValues(value.length > 0 ? [value[0]] : []);
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
else {
|
|
154
|
+
console.log('Setting selectedValues to single item:', [value]);
|
|
155
|
+
setSelectedValues([value]);
|
|
156
|
+
}
|
|
157
|
+
}, [value, isMultiSelect]);
|
|
120
158
|
// Sync options into filtered list when not searching
|
|
121
159
|
(0, react_1.useEffect)(() => {
|
|
122
160
|
if (!hasSearched) {
|
|
@@ -295,7 +333,7 @@ function CreatableSelect({ options = [], value, onChange, onClick, onValueChange
|
|
|
295
333
|
selectedValues.length > 0 &&
|
|
296
334
|
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" },
|
|
297
335
|
react_1.default.createElement("span", { className: "truncate" }, deriveLabel(val)),
|
|
298
|
-
react_1.default.createElement("button", { onClick: (e) => clearValue(e, val), className: styles.clearButton }, renderIcon(
|
|
336
|
+
react_1.default.createElement("button", { onClick: (e) => clearValue(e, val), className: styles.clearButton }, renderIcon(icons.clear, styles.icon))))),
|
|
299
337
|
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() }))),
|
|
300
338
|
react_1.default.createElement("div", { className: "flex-shrink-0 flex items-center gap-1 ml-2" },
|
|
301
339
|
showLoading && renderIcon(iconSrc.loading, `animate-spin ${styles.icon}`),
|
|
@@ -65,7 +65,7 @@ export type CreatableSelectProps<T = SelectOption> = {
|
|
|
65
65
|
className?: string;
|
|
66
66
|
tailwindStyle?: TailwindStyleProps;
|
|
67
67
|
label?: string;
|
|
68
|
-
iconSrc
|
|
68
|
+
iconSrc?: IconSourceProps;
|
|
69
69
|
fetchOptions?: (inputValue: string) => Promise<T[]>;
|
|
70
70
|
onAddClick: (e: boolean) => void;
|
|
71
71
|
isMultiSelect?: boolean;
|