hi-tm 0.9.1 → 0.9.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.
@@ -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 gap-2', // Added gap-2 for spacing
44
+ option: 'py-2 px-3 cursor-pointer flex items-center gap-2',
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',
@@ -51,7 +51,7 @@ const defaultStyles = {
51
51
  clearButton: 'p-1 rounded-full hover:bg-gray-100',
52
52
  icon: 'w-4 h-4 text-gray-400',
53
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
+ selectedOptionIcon: 'w-4 h-4 mr-2 text-blue-500 flex-shrink-0',
55
55
  };
56
56
  // Helper function to render different icon types
57
57
  const renderIcon = (icon, className = '') => {
@@ -89,7 +89,7 @@ const renderNoResults = (noResults, className, searchIcon) => {
89
89
  if (typeof noResults === 'string') {
90
90
  return react_1.default.createElement("div", { className: className }, noResults);
91
91
  }
92
- else if (typeof noResults === 'object' && noResults && 'text' in noResults) {
92
+ if (typeof noResults === 'object' && noResults && 'text' in noResults) {
93
93
  const withText = noResults;
94
94
  return (react_1.default.createElement("div", { className: className },
95
95
  withText.icon
@@ -97,9 +97,7 @@ const renderNoResults = (noResults, className, searchIcon) => {
97
97
  : renderIcon(searchIcon, 'w-6 h-6 mb-1'),
98
98
  react_1.default.createElement("span", null, withText.text)));
99
99
  }
100
- else {
101
- return noResults;
102
- }
100
+ return noResults;
103
101
  };
104
102
  function CreatableSelect({ options = [], value, onChange, onClick, onValueChange, onCreateOption, placeholder = 'جست‌وجو', isLoading = false, isDisabled = false, isCreatable = true, isMultiSelect = false, noOptionsMessage = 'مقدار پیشفرضی وجود ندارد', noResultsFound, loadingMessage = 'در حال بارگذاری...', createOptionMessage = 'ایجاد ', className = '', tailwindStyle = {}, iconSrc = {}, fetchOptions, label, onAddClick, getOptionLabel, getOptionValue, }) {
105
103
  // Default icons
@@ -115,26 +113,21 @@ function CreatableSelect({ options = [], value, onChange, onClick, onValueChange
115
113
  };
116
114
  // Merge provided icons with defaults
117
115
  const icons = { ...defaultIcons, ...iconSrc };
118
- const styles = (0, react_1.useMemo)(() => ({
119
- ...defaultStyles,
120
- ...tailwindStyle,
121
- }), [tailwindStyle]);
116
+ const styles = (0, react_1.useMemo)(() => ({ ...defaultStyles, ...tailwindStyle }), [tailwindStyle]);
122
117
  // Derivers for label/value to support arbitrary option shapes
123
118
  const deriveLabel = (0, react_1.useCallback)((option) => {
124
119
  if (getOptionLabel)
125
120
  return getOptionLabel(option);
126
121
  const anyOption = option;
127
122
  const label = anyOption.label ?? anyOption.content ?? anyOption.value;
128
- const result = String(label ?? '');
129
- return result;
123
+ return String(label ?? '');
130
124
  }, [getOptionLabel]);
131
125
  const deriveValue = (0, react_1.useCallback)((option) => {
132
126
  if (getOptionValue)
133
127
  return getOptionValue(option);
134
128
  const anyOption = option;
135
129
  const base = anyOption.value ?? anyOption.label ?? anyOption.content;
136
- const str = String(base ?? deriveLabel(option));
137
- return str;
130
+ return String(base ?? deriveLabel(option));
138
131
  }, [getOptionValue, deriveLabel]);
139
132
  const [isOpen, setIsOpen] = (0, react_1.useState)(false);
140
133
  const [inputValue, setInputValue] = (0, react_1.useState)('');
@@ -145,13 +138,10 @@ function CreatableSelect({ options = [], value, onChange, onClick, onValueChange
145
138
  const [selectedValues, setSelectedValues] = (0, react_1.useState)([]);
146
139
  const containerRef = (0, react_1.useRef)(null);
147
140
  const inputRef = (0, react_1.useRef)(null);
148
- // Sync external value (ids or option objects) with internal selectedValues state
141
+ // Sync external value with internal state
149
142
  (0, react_1.useEffect)(() => {
150
- // Uncontrolled mode: if value is undefined, do not override internal state
151
- if (value === undefined) {
143
+ if (value === undefined)
152
144
  return;
153
- }
154
- // Explicit clear from parent
155
145
  if (value === null) {
156
146
  setSelectedValues([]);
157
147
  return;
@@ -232,6 +222,7 @@ function CreatableSelect({ options = [], value, onChange, onClick, onValueChange
232
222
  setFilteredOptions(newOptions ?? []);
233
223
  }
234
224
  catch {
225
+ // Error handling
235
226
  }
236
227
  finally {
237
228
  setInternalLoading(false);
@@ -293,7 +284,6 @@ function CreatableSelect({ options = [], value, onChange, onClick, onValueChange
293
284
  }
294
285
  }, [isDisabled, isOpen, filteredOptions, highlightedIndex, isCreatable, inputValue, deriveLabel]);
295
286
  const emitSelection = (0, react_1.useCallback)((next) => {
296
- // Backward-compatible callback
297
287
  if (onClick) {
298
288
  onClick(isMultiSelect ? next ?? [] : next ? next[0] : null);
299
289
  }
@@ -319,6 +309,7 @@ function CreatableSelect({ options = [], value, onChange, onClick, onValueChange
319
309
  setHasSearched(false);
320
310
  }
321
311
  catch {
312
+ // Error handling
322
313
  }
323
314
  finally {
324
315
  setInternalLoading(false);
@@ -349,10 +340,8 @@ function CreatableSelect({ options = [], value, onChange, onClick, onValueChange
349
340
  }
350
341
  setSelectedValues(next);
351
342
  emitSelection(next);
352
- // In multi-select mode, keep the input open and clear input for next search
353
343
  setInputValue('');
354
344
  setHasSearched(false);
355
- // Don't close dropdown in multi-select mode
356
345
  }
357
346
  else {
358
347
  const next = [option];
@@ -389,16 +378,15 @@ function CreatableSelect({ options = [], value, onChange, onClick, onValueChange
389
378
  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 },
390
379
  react_1.default.createElement("div", { className: "flex-grow flex items-center overflow-x-auto no-scrollbar" },
391
380
  react_1.default.createElement("div", { className: "flex items-center gap-2 flex-nowrap" },
392
- selectedValues.length > 0 &&
393
- 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" },
394
- react_1.default.createElement("span", { className: "truncate" }, deriveLabel(val)),
395
- react_1.default.createElement("button", { type: "button", onClick: (e) => clearValue(e, val), className: styles.clearButton }, renderIcon(icons.clear, styles.icon))))),
381
+ 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" },
382
+ react_1.default.createElement("span", { className: "truncate" }, deriveLabel(val)),
383
+ react_1.default.createElement("button", { type: "button", onClick: (e) => clearValue(e, val), className: styles.clearButton }, renderIcon(icons.clear, styles.icon))))),
396
384
  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() }))),
397
385
  react_1.default.createElement("div", { className: "flex-shrink-0 flex items-center gap-1 ml-2" },
398
386
  iconSrc.hasAdd && (react_1.default.createElement("button", { type: "button", onClick: handleAddIconClick, className: styles.clearButton }, renderIcon(iconSrc.hasAdd, styles.icon))),
399
387
  styles.separator && react_1.default.createElement("div", { className: styles.separator }),
400
388
  react_1.default.createElement("button", { type: "button", onClick: toggleDropdown }, isOpen
401
- ? renderIcon(iconSrc.dropdownOpen, `${styles.icon} ${styles.spinAnimation || ''}`)
389
+ ? renderIcon(iconSrc.dropdownOpen, styles.icon)
402
390
  : renderIcon(iconSrc.dropdownClosed, styles.icon)))),
403
391
  isOpen && (react_1.default.createElement("div", { className: styles.dropdown }, showLoading ? (react_1.default.createElement("div", { className: styles.loadingState },
404
392
  renderIcon(iconSrc.loading, `animate-spin mr-2 ${styles.icon}`),
@@ -410,10 +398,7 @@ function CreatableSelect({ options = [], value, onChange, onClick, onValueChange
410
398
  react_1.default.createElement("span", { className: isSelected ? styles.selectedOption : '' }, deriveLabel(option) || deriveValue(option))));
411
399
  }))),
412
400
  filteredOptions.length === 0 && !inputValue && (react_1.default.createElement("div", { className: styles.noOptions }, noOptionsMessage)),
413
- filteredOptions.length === 0 &&
414
- inputValue &&
415
- hasSearched &&
416
- renderNoResults(noResultsFound, styles.noResults ?? '', iconSrc.create),
401
+ filteredOptions.length === 0 && inputValue && hasSearched && (react_1.default.createElement("div", { className: styles.noResults }, renderIcon(iconSrc.create, 'w-6 h-6 mb-1'))),
417
402
  isCreatable &&
418
403
  inputValue &&
419
404
  !options?.some((o) => deriveLabel(o) === inputValue) && (react_1.default.createElement("div", { className: styles.createOption, onClick: handleCreateOption },
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "hi-tm",
3
- "version": "0.9.1",
3
+ "version": "0.9.2",
4
4
  "styles": "dist/styles/globals.css",
5
5
  "main": "dist/index.js",
6
6
  "exports": {