hi-tm 0.6.1 → 0.6.2
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.
|
@@ -112,7 +112,6 @@ function CreatableSelect({ options = [], value, onChange, onClick, onValueChange
|
|
|
112
112
|
const anyOption = option;
|
|
113
113
|
const label = anyOption.label ?? anyOption.content ?? anyOption.value;
|
|
114
114
|
const result = String(label ?? '');
|
|
115
|
-
console.log('deriveLabel for option:', option, 'returning:', result);
|
|
116
115
|
return result;
|
|
117
116
|
}, [getOptionLabel]);
|
|
118
117
|
const deriveValue = (0, react_1.useCallback)((option) => {
|
|
@@ -121,7 +120,6 @@ function CreatableSelect({ options = [], value, onChange, onClick, onValueChange
|
|
|
121
120
|
const anyOption = option;
|
|
122
121
|
const base = anyOption.value ?? anyOption.label ?? anyOption.content;
|
|
123
122
|
const str = String(base ?? deriveLabel(option));
|
|
124
|
-
console.log('deriveValue for option:', option, 'returning:', str);
|
|
125
123
|
return str;
|
|
126
124
|
}, [getOptionValue, deriveLabel]);
|
|
127
125
|
const [isOpen, setIsOpen] = (0, react_1.useState)(false);
|
|
@@ -135,26 +133,35 @@ function CreatableSelect({ options = [], value, onChange, onClick, onValueChange
|
|
|
135
133
|
const inputRef = (0, react_1.useRef)(null);
|
|
136
134
|
// Sync external value prop with internal selectedValues state
|
|
137
135
|
(0, react_1.useEffect)(() => {
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
136
|
+
// Only sync if the external value is different from current selectedValues
|
|
137
|
+
const currentValues = selectedValues;
|
|
138
|
+
const externalValue = value;
|
|
139
|
+
if (externalValue === null || externalValue === undefined) {
|
|
140
|
+
if (currentValues.length > 0) {
|
|
141
|
+
setSelectedValues([]);
|
|
142
|
+
}
|
|
142
143
|
}
|
|
143
|
-
else if (Array.isArray(
|
|
144
|
+
else if (Array.isArray(externalValue)) {
|
|
144
145
|
if (isMultiSelect) {
|
|
145
|
-
|
|
146
|
-
|
|
146
|
+
const externalArray = externalValue;
|
|
147
|
+
if (JSON.stringify(externalArray) !== JSON.stringify(currentValues)) {
|
|
148
|
+
setSelectedValues(externalArray);
|
|
149
|
+
}
|
|
147
150
|
}
|
|
148
151
|
else {
|
|
149
|
-
|
|
150
|
-
|
|
152
|
+
const firstItem = externalValue.length > 0 ? [externalValue[0]] : [];
|
|
153
|
+
if (JSON.stringify(firstItem) !== JSON.stringify(currentValues)) {
|
|
154
|
+
setSelectedValues(firstItem);
|
|
155
|
+
}
|
|
151
156
|
}
|
|
152
157
|
}
|
|
153
158
|
else {
|
|
154
|
-
|
|
155
|
-
|
|
159
|
+
const singleItem = [externalValue];
|
|
160
|
+
if (JSON.stringify(singleItem) !== JSON.stringify(currentValues)) {
|
|
161
|
+
setSelectedValues(singleItem);
|
|
162
|
+
}
|
|
156
163
|
}
|
|
157
|
-
}, [value, isMultiSelect]);
|
|
164
|
+
}, [value, isMultiSelect, selectedValues]);
|
|
158
165
|
// Sync options into filtered list when not searching
|
|
159
166
|
(0, react_1.useEffect)(() => {
|
|
160
167
|
if (!hasSearched) {
|
|
@@ -308,15 +315,19 @@ function CreatableSelect({ options = [], value, onChange, onClick, onValueChange
|
|
|
308
315
|
}
|
|
309
316
|
setSelectedValues(next);
|
|
310
317
|
emitSelection(next);
|
|
318
|
+
// In multi-select mode, keep the input open and clear input for next search
|
|
319
|
+
setInputValue('');
|
|
320
|
+
setHasSearched(false);
|
|
321
|
+
// Don't close dropdown in multi-select mode
|
|
311
322
|
}
|
|
312
323
|
else {
|
|
313
324
|
const next = [option];
|
|
314
325
|
setSelectedValues(next);
|
|
315
326
|
emitSelection(next);
|
|
327
|
+
setInputValue('');
|
|
328
|
+
setIsOpen(false);
|
|
329
|
+
setHasSearched(false);
|
|
316
330
|
}
|
|
317
|
-
setInputValue('');
|
|
318
|
-
setIsOpen(false);
|
|
319
|
-
setHasSearched(false);
|
|
320
331
|
}, [isMultiSelect, selectedValues, deriveValue, emitSelection]);
|
|
321
332
|
const showLoading = isLoading || internalLoading;
|
|
322
333
|
const handleAddIconClick = (0, react_1.useCallback)((e) => {
|
|
@@ -336,18 +347,18 @@ function CreatableSelect({ options = [], value, onChange, onClick, onValueChange
|
|
|
336
347
|
react_1.default.createElement("button", { onClick: (e) => clearValue(e, val), className: styles.clearButton }, renderIcon(icons.clear, styles.icon))))),
|
|
337
348
|
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() }))),
|
|
338
349
|
react_1.default.createElement("div", { className: "flex-shrink-0 flex items-center gap-1 ml-2" },
|
|
339
|
-
showLoading && renderIcon(
|
|
340
|
-
|
|
350
|
+
showLoading && renderIcon(icons.loading, `animate-spin ${styles.icon}`),
|
|
351
|
+
icons.hasAdd && onAddClick !== undefined && (react_1.default.createElement("button", { onClick: handleAddIconClick, className: styles.clearButton }, renderIcon(icons.hasAdd, styles.icon))),
|
|
341
352
|
styles.separator && react_1.default.createElement("div", { className: styles.separator }),
|
|
342
353
|
isOpen
|
|
343
|
-
? renderIcon(
|
|
344
|
-
: renderIcon(
|
|
354
|
+
? renderIcon(icons.dropdownOpen, `${styles.icon} ${styles.spinAnimation || ''}`)
|
|
355
|
+
: renderIcon(icons.dropdownClosed, styles.icon))),
|
|
345
356
|
isOpen && (react_1.default.createElement("div", { className: styles.dropdown }, showLoading ? (react_1.default.createElement("div", { className: styles.loadingState },
|
|
346
|
-
renderIcon(
|
|
357
|
+
renderIcon(icons.loading, `animate-spin mr-2 ${styles.icon}`),
|
|
347
358
|
loadingMessage)) : (react_1.default.createElement(react_1.default.Fragment, null,
|
|
348
359
|
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 ? styles.highlightedOption : 'hover:bg-gray-50'}`, onClick: () => selectOption(option), onMouseEnter: () => setHighlightedIndex(index) },
|
|
349
360
|
selectedValues.some((val) => deriveValue(val) === deriveValue(option)) &&
|
|
350
|
-
renderIcon(
|
|
361
|
+
renderIcon(icons.checkmark, 'w-4 h-4 mr-2 text-blue-500'),
|
|
351
362
|
react_1.default.createElement("span", { className: selectedValues.some((val) => deriveValue(val) === deriveValue(option))
|
|
352
363
|
? styles.selectedOption
|
|
353
364
|
: '' }, deriveLabel(option) || deriveValue(option))))))),
|
|
@@ -355,11 +366,11 @@ function CreatableSelect({ options = [], value, onChange, onClick, onValueChange
|
|
|
355
366
|
filteredOptions.length === 0 &&
|
|
356
367
|
inputValue &&
|
|
357
368
|
hasSearched &&
|
|
358
|
-
renderNoResults(noResultsFound, styles.noResults ?? '',
|
|
369
|
+
renderNoResults(noResultsFound, styles.noResults ?? '', icons.create),
|
|
359
370
|
isCreatable &&
|
|
360
371
|
inputValue &&
|
|
361
372
|
!options?.some((o) => deriveLabel(o) === inputValue) && (react_1.default.createElement("div", { className: styles.createOption, onClick: handleCreateOption },
|
|
362
|
-
renderIcon(
|
|
373
|
+
renderIcon(icons.create, styles.icon),
|
|
363
374
|
react_1.default.createElement("span", null,
|
|
364
375
|
createOptionMessage,
|
|
365
376
|
": ",
|
|
@@ -67,7 +67,7 @@ export type CreatableSelectProps<T = SelectOption> = {
|
|
|
67
67
|
label?: string;
|
|
68
68
|
iconSrc?: IconSourceProps;
|
|
69
69
|
fetchOptions?: (inputValue: string) => Promise<T[]>;
|
|
70
|
-
onAddClick
|
|
70
|
+
onAddClick?: (e: boolean) => void;
|
|
71
71
|
isMultiSelect?: boolean;
|
|
72
72
|
getOptionLabel?: OptionLabelGetter<T>;
|
|
73
73
|
getOptionValue?: OptionValueGetter<T>;
|