hi-tm 0.8.8 → 0.9.0

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.
@@ -50,7 +50,8 @@ 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', // Style for the vertical line separator
53
+ separator: 'h-4 border-l mx-2',
54
+ selectedOptionIcon: 'w-4 h-4 mr-2 text-blue-500', // Added style for selected option icon
54
55
  };
55
56
  // Helper function to render different icon types
56
57
  const renderIcon = (icon, className = '') => {
@@ -133,7 +134,12 @@ function CreatableSelect({ options = [], value, onChange, onClick, onValueChange
133
134
  const inputRef = (0, react_1.useRef)(null);
134
135
  // Sync external value (ids or option objects) with internal selectedValues state
135
136
  (0, react_1.useEffect)(() => {
136
- if (value === undefined || value === null) {
137
+ // Uncontrolled mode: if value is undefined, do not override internal state
138
+ if (value === undefined) {
139
+ return;
140
+ }
141
+ // Explicit clear from parent
142
+ if (value === null) {
137
143
  setSelectedValues([]);
138
144
  return;
139
145
  }
@@ -344,7 +350,6 @@ function CreatableSelect({ options = [], value, onChange, onClick, onValueChange
344
350
  setHasSearched(false);
345
351
  }
346
352
  }, [isMultiSelect, selectedValues, deriveValue, emitSelection]);
347
- const showLoading = isLoading || internalLoading;
348
353
  const handleAddIconClick = (0, react_1.useCallback)((e) => {
349
354
  e.preventDefault();
350
355
  e.stopPropagation();
@@ -361,6 +366,11 @@ function CreatableSelect({ options = [], value, onChange, onClick, onValueChange
361
366
  }
362
367
  }
363
368
  }, [isDisabled, isOpen]);
369
+ const showLoading = isLoading || internalLoading;
370
+ // Helper function to check if an option is selected
371
+ const isOptionSelected = (0, react_1.useCallback)((option) => {
372
+ return selectedValues.some((val) => deriveValue(val) === deriveValue(option));
373
+ }, [selectedValues, deriveValue]);
364
374
  return (react_1.default.createElement("div", { ref: containerRef, className: `relative w-full ${className} ${styles.container}`, onKeyDown: handleKeyDown },
365
375
  label && react_1.default.createElement("label", { className: "block text-sm font-medium text-gray-700 mb-1" }, label),
366
376
  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 },
@@ -381,11 +391,9 @@ function CreatableSelect({ options = [], value, onChange, onClick, onValueChange
381
391
  renderIcon(iconSrc.loading, `animate-spin mr-2 ${styles.icon}`),
382
392
  loadingMessage)) : (react_1.default.createElement(react_1.default.Fragment, null,
383
393
  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) },
384
- selectedValues.some((val) => deriveValue(val) === deriveValue(option)) &&
385
- renderIcon(iconSrc.checkmark, 'w-4 h-4 mr-2 text-blue-500'),
386
- react_1.default.createElement("span", { className: selectedValues.some((val) => deriveValue(val) === deriveValue(option))
387
- ? styles.selectedOption
388
- : '' }, deriveLabel(option) || deriveValue(option))))))),
394
+ isOptionSelected(option) &&
395
+ renderIcon(icons.checkmark, styles.selectedOptionIcon || styles.icon),
396
+ react_1.default.createElement("span", { className: isOptionSelected(option) ? styles.selectedOption : '' }, deriveLabel(option) || deriveValue(option))))))),
389
397
  filteredOptions.length === 0 && !inputValue && (react_1.default.createElement("div", { className: styles.noOptions }, noOptionsMessage)),
390
398
  filteredOptions.length === 0 &&
391
399
  inputValue &&
@@ -29,6 +29,7 @@ export interface TailwindStyleProps extends React.CSSProperties {
29
29
  icon?: string;
30
30
  separator?: string;
31
31
  spinAnimation?: string;
32
+ selectedOptionIcon?: string;
32
33
  }
33
34
  export type BaseOption = {
34
35
  label?: string;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "hi-tm",
3
- "version": "0.8.8",
3
+ "version": "0.9.0",
4
4
  "styles": "dist/styles/globals.css",
5
5
  "main": "dist/index.js",
6
6
  "exports": {