hi-tm 0.6.0 → 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);
|
|
@@ -119,18 +135,23 @@ function CreatableSelect({ options = [], value, onChange, onClick, onValueChange
|
|
|
119
135
|
const inputRef = (0, react_1.useRef)(null);
|
|
120
136
|
// Sync external value prop with internal selectedValues state
|
|
121
137
|
(0, react_1.useEffect)(() => {
|
|
138
|
+
console.log('useEffect triggered with value:', value, 'isMultiSelect:', isMultiSelect);
|
|
122
139
|
if (value === null || value === undefined) {
|
|
140
|
+
console.log('Setting selectedValues to empty array');
|
|
123
141
|
setSelectedValues([]);
|
|
124
142
|
}
|
|
125
143
|
else if (Array.isArray(value)) {
|
|
126
144
|
if (isMultiSelect) {
|
|
145
|
+
console.log('Setting selectedValues to array:', value);
|
|
127
146
|
setSelectedValues(value);
|
|
128
147
|
}
|
|
129
148
|
else {
|
|
149
|
+
console.log('Setting selectedValues to first item of array:', value.length > 0 ? [value[0]] : []);
|
|
130
150
|
setSelectedValues(value.length > 0 ? [value[0]] : []);
|
|
131
151
|
}
|
|
132
152
|
}
|
|
133
153
|
else {
|
|
154
|
+
console.log('Setting selectedValues to single item:', [value]);
|
|
134
155
|
setSelectedValues([value]);
|
|
135
156
|
}
|
|
136
157
|
}, [value, isMultiSelect]);
|
|
@@ -312,7 +333,7 @@ function CreatableSelect({ options = [], value, onChange, onClick, onValueChange
|
|
|
312
333
|
selectedValues.length > 0 &&
|
|
313
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" },
|
|
314
335
|
react_1.default.createElement("span", { className: "truncate" }, deriveLabel(val)),
|
|
315
|
-
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))))),
|
|
316
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() }))),
|
|
317
338
|
react_1.default.createElement("div", { className: "flex-shrink-0 flex items-center gap-1 ml-2" },
|
|
318
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;
|