hi-tm 0.3.7 → 0.3.9

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.
@@ -1,4 +1,3 @@
1
1
  import React from 'react';
2
- import type { CreatableSelectProps } from '../../types/DropDown/CreatableDropDown';
3
- export default function CreatableSelect({ options, value, onChange, onClick, // New prop for handling selection
4
- onCreateOption, placeholder, isLoading, isDisabled, isClearable, isCreatable, isMultiSelect, noOptionsMessage, noResultsFound, loadingMessage, createOptionMessage, className, tailwindStyle, iconSrc, fetchOptions, label, onAddClick, }: CreatableSelectProps): React.JSX.Element;
2
+ import type { SelectOption, CreatableSelectProps } from '../../types/DropDown/CreatableDropDown';
3
+ export default function CreatableSelect<T = SelectOption>({ options, value, onChange, onClick, onCreateOption, placeholder, isLoading, isDisabled, isCreatable, isMultiSelect, noOptionsMessage, noResultsFound, loadingMessage, createOptionMessage, className, tailwindStyle, iconSrc, fetchOptions, fetchRawOptions, mapCreateOption, toOption, onValueChange, label, onAddClick, }: CreatableSelectProps<T>): React.JSX.Element;
@@ -85,39 +85,56 @@ const renderNoResults = (noResults, className, searchIcon) => {
85
85
  return noResults;
86
86
  }
87
87
  };
88
- function CreatableSelect({ options = [], value, onChange, onClick, // New prop for handling selection
89
- onCreateOption, placeholder = 'Select...', isLoading = false, isDisabled = false, isClearable = true, isCreatable = true, isMultiSelect = false, noOptionsMessage = 'No options available', noResultsFound, loadingMessage = 'Loading...', createOptionMessage = 'Create option', className = '', tailwindStyle = {}, iconSrc, fetchOptions, label, onAddClick, }) {
88
+ // Generic component so consumers can pass any T and receive T back
89
+ function CreatableSelect({ options = [], value, onChange, onClick, onCreateOption, placeholder = 'Select...', isLoading = false, isDisabled = false,
90
+ // isClearable is currently unused; keep behavior but omit local param to avoid lint error
91
+ isCreatable = true, isMultiSelect = false, noOptionsMessage = 'No options available', noResultsFound, loadingMessage = 'Loading...', createOptionMessage = 'Create option', className = '', tailwindStyle = {}, iconSrc, fetchOptions, fetchRawOptions, mapCreateOption, toOption, onValueChange, label, onAddClick, }) {
90
92
  const styles = {
91
93
  ...defaultStyles,
92
94
  ...tailwindStyle,
93
95
  };
96
+ // Ensure we always have a mapper from T -> SelectOption
97
+ const toSelectOption = (0, react_1.useMemo)(() => {
98
+ if (toOption)
99
+ return toOption;
100
+ // Best-effort default: if item already looks like SelectOption use it; otherwise toString
101
+ return (item) => {
102
+ if (item && typeof item === 'object' && 'value' in item && 'label' in item) {
103
+ return item;
104
+ }
105
+ const text = String(item ?? '');
106
+ return { label: text, value: text, content: text };
107
+ };
108
+ }, [toOption]);
94
109
  const [isOpen, setIsOpen] = (0, react_1.useState)(false);
95
110
  const [inputValue, setInputValue] = (0, react_1.useState)('');
96
- const [filteredOptions, setFilteredOptions] = (0, react_1.useState)(options ?? []);
111
+ const [filteredOptions, setFilteredOptions] = (0, react_1.useState)((options ?? []).map(toSelectOption));
97
112
  const [highlightedIndex, setHighlightedIndex] = (0, react_1.useState)(0);
98
113
  const [internalLoading, setInternalLoading] = (0, react_1.useState)(false);
99
114
  const [hasSearched, setHasSearched] = (0, react_1.useState)(false);
100
- const [selectedValues, setSelectedValues] = (0, react_1.useState)(Array.isArray(value) && isMultiSelect
101
- ? value
102
- : value
103
- ? [value]
104
- : []);
115
+ // Store selected values in raw T form, but display via mapper
116
+ const initialSelected = (0, react_1.useMemo)(() => {
117
+ if (!value)
118
+ return [];
119
+ return Array.isArray(value) ? value : [value];
120
+ }, [value]);
121
+ const [selectedRawValues, setSelectedRawValues] = (0, react_1.useState)(initialSelected);
122
+ const selectedValues = (0, react_1.useMemo)(() => selectedRawValues.map(toSelectOption), [selectedRawValues, toSelectOption]);
105
123
  const containerRef = (0, react_1.useRef)(null);
106
124
  const inputRef = (0, react_1.useRef)(null);
125
+ // Keep filtered options in sync with external changes when not actively searching
107
126
  (0, react_1.useEffect)(() => {
108
- console.log('Options prop changed:', options); // Debugging log
109
- // Only update filteredOptions when options change if we're not in the middle of a search
110
127
  if (!hasSearched) {
111
- setFilteredOptions(options ?? []);
128
+ setFilteredOptions((options ?? []).map(toSelectOption));
112
129
  }
113
- }, [options, hasSearched]);
130
+ }, [options, hasSearched, toSelectOption]);
131
+ // Reset search list when input cleared
114
132
  (0, react_1.useEffect)(() => {
115
133
  if (inputValue === '') {
116
- console.log('Input value is empty, resetting filtered options'); // Debugging log
117
- setFilteredOptions(options ?? []);
134
+ setFilteredOptions((options ?? []).map(toSelectOption));
118
135
  setHasSearched(false);
119
136
  }
120
- }, [options, inputValue]);
137
+ }, [options, inputValue, toSelectOption]);
121
138
  (0, react_1.useEffect)(() => {
122
139
  const handler = (e) => {
123
140
  if (containerRef.current && !containerRef.current.contains(e.target)) {
@@ -129,20 +146,34 @@ onCreateOption, placeholder = 'Select...', isLoading = false, isDisabled = false
129
146
  document.removeEventListener('click', handler);
130
147
  };
131
148
  }, []);
132
- const handleInputChange = async (e) => {
133
- const value = e.target.value;
134
- setInputValue(value);
135
- setIsOpen(true);
136
- // Pass the input event to onChange
137
- if (onChange) {
138
- onChange(e);
149
+ // Debounce input to limit fetch/filter work
150
+ const [debouncedQuery, setDebouncedQuery] = (0, react_1.useState)('');
151
+ (0, react_1.useEffect)(() => {
152
+ const id = setTimeout(() => setDebouncedQuery(inputValue), 200);
153
+ return () => clearTimeout(id);
154
+ }, [inputValue]);
155
+ const runSearch = (0, react_1.useCallback)(async (query) => {
156
+ if (fetchRawOptions && query.trim() !== '') {
157
+ setInternalLoading(true);
158
+ setHasSearched(true);
159
+ try {
160
+ const rawItems = await fetchRawOptions(query);
161
+ setFilteredOptions((rawItems ?? []).map(toSelectOption));
162
+ }
163
+ catch (error) {
164
+ console.error('Error fetching raw options:', error);
165
+ }
166
+ finally {
167
+ setInternalLoading(false);
168
+ }
169
+ return;
139
170
  }
140
- if (fetchOptions && value.trim() !== '') {
171
+ if (fetchOptions && query.trim() !== '') {
141
172
  setInternalLoading(true);
142
173
  setHasSearched(true);
143
174
  try {
144
- const newOptions = await fetchOptions(value);
145
- setFilteredOptions(newOptions);
175
+ const newOptions = await fetchOptions(query);
176
+ setFilteredOptions(newOptions ?? []);
146
177
  }
147
178
  catch (error) {
148
179
  console.error('Error fetching options:', error);
@@ -150,83 +181,100 @@ onCreateOption, placeholder = 'Select...', isLoading = false, isDisabled = false
150
181
  finally {
151
182
  setInternalLoading(false);
152
183
  }
184
+ return;
153
185
  }
154
- else if (value.trim() === '') {
155
- setFilteredOptions(options ?? []);
186
+ if (query.trim() === '') {
187
+ setFilteredOptions((options ?? []).map(toSelectOption));
156
188
  setHasSearched(false);
189
+ return;
157
190
  }
158
- else {
159
- // Filter options to only show items that match the search text
160
- const searchText = String(value).trim();
161
- const filtered = (options ?? []).filter((option) => {
162
- // Check for label, content, or value properties
163
- const optionLabel = String(option.label || option.content || '');
164
- return optionLabel.toLowerCase().includes(searchText.toLowerCase());
165
- });
166
- console.log('Search text:', searchText);
167
- console.log('Filtered options:', filtered);
168
- setFilteredOptions(filtered);
169
- setHasSearched(true);
191
+ const searchText = String(query).trim().toLowerCase();
192
+ const baseOptions = (options ?? []).map(toSelectOption);
193
+ const filtered = baseOptions.filter((option) => {
194
+ const optionLabel = String(option.label || option.content || option.value || '');
195
+ return optionLabel.toLowerCase().includes(searchText);
196
+ });
197
+ setFilteredOptions(filtered);
198
+ setHasSearched(true);
199
+ }, [fetchRawOptions, fetchOptions, options, toSelectOption]);
200
+ (0, react_1.useEffect)(() => {
201
+ runSearch(debouncedQuery);
202
+ }, [debouncedQuery, runSearch]);
203
+ const handleInputChange = (e) => {
204
+ const next = e.target.value;
205
+ setInputValue(next);
206
+ setIsOpen(true);
207
+ if (onChange)
208
+ onChange(e);
209
+ };
210
+ const notifySelection = (0, react_1.useCallback)((newRawValues) => {
211
+ // Legacy emit with mapped options
212
+ if (onClick) {
213
+ const mapped = newRawValues.map(toSelectOption);
214
+ onClick(isMultiSelect ? mapped : mapped[0] || null);
170
215
  }
216
+ // New typed emit with T
217
+ if (onValueChange) {
218
+ onValueChange(isMultiSelect ? newRawValues : newRawValues[0] ?? null);
219
+ }
220
+ }, [isMultiSelect, onClick, onValueChange, toSelectOption]);
221
+ const clearValue = (e, option) => {
222
+ e.stopPropagation();
223
+ const newRawValues = selectedRawValues.filter((val) => toSelectOption(val).value !== option.value);
224
+ setSelectedRawValues(newRawValues);
225
+ notifySelection(newRawValues);
171
226
  };
172
- const handleKeyDown = (e) => {
173
- if (isDisabled)
174
- return;
175
- switch (e.key) {
176
- case 'Enter':
177
- e.preventDefault();
178
- if (isOpen) {
179
- if (filteredOptions.length > 0 && highlightedIndex < filteredOptions.length) {
180
- selectOption(filteredOptions[highlightedIndex]);
181
- }
182
- else if (isCreatable &&
183
- inputValue &&
184
- !filteredOptions.some((o) => o.label === inputValue)) {
185
- handleCreateOption();
186
- }
187
- setIsOpen(false);
188
- }
189
- else {
190
- setIsOpen(true);
191
- }
192
- break;
193
- case 'Escape':
194
- setIsOpen(false);
195
- break;
196
- case 'ArrowUp':
197
- e.preventDefault();
198
- if (isOpen) {
199
- setHighlightedIndex((prev) => (prev > 0 ? prev - 1 : filteredOptions.length - 1));
200
- }
201
- else {
202
- setIsOpen(true);
203
- }
204
- break;
205
- case 'ArrowDown':
206
- e.preventDefault();
207
- if (isOpen) {
208
- setHighlightedIndex((prev) => (prev < filteredOptions.length - 1 ? prev + 1 : 0));
209
- }
210
- else {
211
- setIsOpen(true);
212
- }
213
- break;
227
+ const selectOption = (option) => {
228
+ if (isMultiSelect) {
229
+ const newRawValues = [...selectedRawValues];
230
+ const already = newRawValues.some((val) => toSelectOption(val).value === option.value);
231
+ if (!already) {
232
+ // Try to find original raw item by value match; if not found, fallback to option payload
233
+ const raw = (options ?? []).find((item) => toSelectOption(item).value === option.value);
234
+ newRawValues.push(raw ?? option);
235
+ }
236
+ setSelectedRawValues(newRawValues);
237
+ notifySelection(newRawValues);
238
+ }
239
+ else {
240
+ // Try to map back to raw by value
241
+ const raw = (options ?? []).find((item) => toSelectOption(item).value === option.value);
242
+ const nextRaw = raw ?? option;
243
+ setSelectedRawValues([nextRaw]);
244
+ notifySelection([nextRaw]);
214
245
  }
246
+ setInputValue('');
247
+ setIsOpen(false);
248
+ setHasSearched(false);
215
249
  };
216
250
  const handleCreateOption = async () => {
217
- if (!inputValue.trim() || !isCreatable || !onCreateOption)
251
+ if (!inputValue.trim() || !isCreatable)
218
252
  return;
219
253
  setInternalLoading(true);
220
254
  try {
221
- await onCreateOption(inputValue);
222
- // Create value without toLowerCase
223
- const safeInputValue = String(inputValue);
224
- const newOption = {
225
- label: safeInputValue,
226
- content: safeInputValue, // Add content property for compatibility
227
- value: safeInputValue.replace(/\s+/g, '-'),
228
- };
229
- selectOption(newOption);
255
+ // Prefer typed creator
256
+ let createdRaw;
257
+ if (mapCreateOption) {
258
+ createdRaw = await Promise.resolve(mapCreateOption(inputValue));
259
+ }
260
+ if (!createdRaw) {
261
+ if (onCreateOption) {
262
+ await onCreateOption(inputValue);
263
+ }
264
+ // Fallback: fabricate SelectOption consistent with prior behavior
265
+ const text = String(inputValue);
266
+ const newOption = {
267
+ label: text,
268
+ content: text,
269
+ value: text.replace(/\s+/g, '-'),
270
+ };
271
+ selectOption(newOption);
272
+ }
273
+ else {
274
+ const nextValues = isMultiSelect ? [...selectedRawValues, createdRaw] : [createdRaw];
275
+ setSelectedRawValues(nextValues);
276
+ notifySelection(nextValues);
277
+ }
230
278
  setInputValue('');
231
279
  setHasSearched(false);
232
280
  }
@@ -245,47 +293,56 @@ onCreateOption, placeholder = 'Select...', isLoading = false, isDisabled = false
245
293
  }
246
294
  }
247
295
  };
248
- const clearValue = (e, option) => {
249
- e.stopPropagation();
250
- const newValues = selectedValues.filter((val) => val.value !== option.value);
251
- setSelectedValues(newValues);
252
- // Use onClick instead of onChange for selection updates
253
- if (onClick) {
254
- onClick(isMultiSelect ? newValues : newValues[0] || null);
255
- }
256
- };
257
- const selectOption = (option) => {
258
- if (isMultiSelect) {
259
- const newValues = [...selectedValues];
260
- if (!newValues.some((val) => val.value === option.value)) {
261
- newValues.push(option);
262
- }
263
- setSelectedValues(newValues);
264
- // Use onClick instead of onChange for selection updates
265
- if (onClick) {
266
- onClick(newValues);
267
- }
268
- }
269
- else {
270
- setSelectedValues([option]);
271
- // Use onClick instead of onChange for selection updates
272
- if (onClick) {
273
- onClick(option);
274
- }
275
- }
276
- setInputValue('');
277
- setIsOpen(false);
278
- setHasSearched(false);
279
- };
280
296
  const showLoading = isLoading || internalLoading;
281
297
  const handleAddIconClick = (e) => {
282
298
  e.stopPropagation();
283
- if (onAddClick) {
284
- // Pass the required argument to onAddClick
299
+ if (onAddClick)
285
300
  onAddClick(true);
286
- }
287
301
  };
288
- return (react_1.default.createElement("div", { ref: containerRef, className: `relative w-full ${className} ${styles.container}`, onKeyDown: handleKeyDown },
302
+ return (react_1.default.createElement("div", { ref: containerRef, className: `relative w-full ${className} ${styles.container}`, onKeyDown: (e) => {
303
+ if (isDisabled)
304
+ return;
305
+ switch (e.key) {
306
+ case 'Enter':
307
+ e.preventDefault();
308
+ if (isOpen) {
309
+ if (filteredOptions.length > 0 && highlightedIndex < filteredOptions.length) {
310
+ selectOption(filteredOptions[highlightedIndex]);
311
+ }
312
+ else if (isCreatable &&
313
+ inputValue &&
314
+ !filteredOptions.some((o) => o.label === inputValue)) {
315
+ handleCreateOption();
316
+ }
317
+ setIsOpen(false);
318
+ }
319
+ else {
320
+ setIsOpen(true);
321
+ }
322
+ break;
323
+ case 'Escape':
324
+ setIsOpen(false);
325
+ break;
326
+ case 'ArrowUp':
327
+ e.preventDefault();
328
+ if (isOpen) {
329
+ setHighlightedIndex((prev) => (prev > 0 ? prev - 1 : filteredOptions.length - 1));
330
+ }
331
+ else {
332
+ setIsOpen(true);
333
+ }
334
+ break;
335
+ case 'ArrowDown':
336
+ e.preventDefault();
337
+ if (isOpen) {
338
+ setHighlightedIndex((prev) => (prev < filteredOptions.length - 1 ? prev + 1 : 0));
339
+ }
340
+ else {
341
+ setIsOpen(true);
342
+ }
343
+ break;
344
+ }
345
+ } },
289
346
  label && react_1.default.createElement("label", { className: "block text-sm font-medium text-gray-700 mb-1" }, label),
290
347
  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: toggleDropdown },
291
348
  react_1.default.createElement("div", { className: "flex-grow flex items-center overflow-x-auto no-scrollbar" },
@@ -315,10 +372,12 @@ onCreateOption, placeholder = 'Select...', isLoading = false, isDisabled = false
315
372
  filteredOptions.length === 0 &&
316
373
  inputValue &&
317
374
  hasSearched &&
318
- renderNoResults(noResultsFound, styles?.noResults, iconSrc.create),
375
+ renderNoResults(noResultsFound, styles?.noResults ?? '', iconSrc.create),
319
376
  isCreatable &&
320
377
  inputValue &&
321
- !options?.some((o) => (o.label || o.content) === inputValue) && (react_1.default.createElement("div", { className: styles.createOption, onClick: handleCreateOption },
378
+ !(options ?? [])
379
+ .map(toSelectOption)
380
+ .some((o) => (o.label || o.content) === inputValue) && (react_1.default.createElement("div", { className: styles.createOption, onClick: handleCreateOption },
322
381
  renderIcon(iconSrc.create, styles.icon),
323
382
  react_1.default.createElement("span", null,
324
383
  createOptionMessage,
@@ -1,5 +1,4 @@
1
1
  "use strict";
2
- // InputMultiselect.tsx
3
2
  'use client';
4
3
  var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
5
4
  if (k2 === undefined) k2 = k;
@@ -44,58 +43,76 @@ const InputMultiselect = ({ label, required, textError, placeholder, onChangeHan
44
43
  margin: 'mt-[-6px]',
45
44
  width: 'w-full',
46
45
  }, }) => {
47
- const [items, setItems] = (0, react_1.useState)(value || []);
46
+ const [items, setItems] = (0, react_1.useState)([]);
48
47
  const [currentValue, setCurrentValue] = (0, react_1.useState)('');
49
48
  const [showError, setShowError] = (0, react_1.useState)(false);
49
+ const isErrorVisible = () => {
50
+ // Show error if there's a textError OR if there's unconfirmed input
51
+ return (textError && textError.trim() !== '') || showError;
52
+ };
53
+ const getErrorMessage = () => {
54
+ if (textError && textError.trim() !== '') {
55
+ return textError.trim();
56
+ }
57
+ if (showError && currentValue.trim() !== '') {
58
+ return 'برای ثبت بارکد کلید Enter را فشار دهید';
59
+ }
60
+ return '';
61
+ };
62
+ // Initialize items from value prop only once
50
63
  (0, react_1.useEffect)(() => {
51
- if (value && value.length > 0) {
64
+ if (value && value.length > 0 && items.length === 0) {
52
65
  setItems(value);
53
66
  }
54
- }, [value]);
67
+ }, [value, items.length]);
55
68
  const handleChange = (e) => {
56
69
  setCurrentValue(e.target.value);
57
- if (e.target.value.trim() !== '') {
70
+ // Hide error when user starts typing
71
+ if (showError) {
58
72
  setShowError(false);
59
73
  }
60
74
  };
61
75
  const handleKeyDown = (e) => {
62
76
  if (e.key === 'Enter' && currentValue.trim() !== '') {
63
77
  e.preventDefault();
64
- setItems((prevItems) => [...prevItems, currentValue.trim()]);
78
+ const newItems = [...items, currentValue.trim()];
79
+ setItems(newItems);
65
80
  setCurrentValue('');
66
- setShowError(false);
81
+ setShowError(false); // Reset error on Enter
82
+ // Call onChangeHandler directly here instead of in useEffect
83
+ onChangeHandler(newItems);
67
84
  }
68
85
  propHandleKeyDown?.(e);
69
86
  };
70
87
  const handleBlur = (e) => {
71
88
  if (currentValue.trim() !== '') {
72
- setShowError(true);
73
- }
74
- else {
75
- setShowError(false);
89
+ setShowError(true); // Show error if there's unconfirmed input
76
90
  }
77
91
  onBlurHandler?.(e);
78
92
  };
79
- const handleFocus = (e) => {
80
- setShowError(false);
81
- onFocusHandler?.(e);
82
- };
83
- (0, react_1.useEffect)(() => {
84
- onChangeHandler(items);
85
- }, [items, onChangeHandler]);
86
- const handleRemoveItem = (index) => {
87
- setItems((prevItems) => prevItems.filter((_, i) => i !== index));
88
- };
89
- return (react_1.default.createElement("div", { className: `${style.width} ${style.margin} relative` },
93
+ // Remove the problematic useEffect that was causing the loop
94
+ // useEffect((): void => {
95
+ // onChangeHandler(items);
96
+ // }, [items]);
97
+ const handleRemoveItem = (0, react_1.useCallback)((index) => {
98
+ setItems((prevItems) => {
99
+ const newItems = prevItems.filter((_, i) => i !== index);
100
+ // Call onChangeHandler directly here
101
+ onChangeHandler(newItems);
102
+ return newItems;
103
+ });
104
+ }, [onChangeHandler]);
105
+ return (react_1.default.createElement("div", { className: `${style.width} ${style.margin} relative ` },
90
106
  react_1.default.createElement("label", { htmlFor: label, className: "flex items-center gap-2 mx-3" },
91
107
  react_1.default.createElement("p", { className: "text-sm text-text-color-primary font-medium cursor-pointer" }, label),
92
108
  react_1.default.createElement("span", { className: `text-red-primary font-bold ${required ? 'block' : 'hidden'}` }, "*")),
93
- react_1.default.createElement("div", { className: `w-full h-10 flex gap-1 items-center justify-between bg-inherit outline-none border rounded-lg text-sm px-2 ${!textError ? 'border-gray-tertiary focus:border-gray-quaternary' : 'border-red-primary'}` },
109
+ react_1.default.createElement("div", { className: `w-full h-10 flex gap-1 items-center justify-between bg-inherit outline-none border rounded-lg text-sm px-2 ${isErrorVisible()
110
+ ? 'border-red-primary'
111
+ : 'border-gray-tertiary focus:border-gray-quaternary'}` },
94
112
  items.map((item, index) => (react_1.default.createElement("span", { key: index, className: "bg-gray-secondary text-text-color-primary px-2 py-1 rounded flex items-center justify-center gap-1" },
95
113
  item,
96
114
  react_1.default.createElement(image_1.default, { src: closeIconSRC, alt: "close", width: 22, height: 22, onClick: () => handleRemoveItem(index), className: "inline-block cursor-pointer" })))),
97
- react_1.default.createElement("input", { ref: inputRef, type: "text", value: currentValue, id: label, placeholder: items.length === 0 ? placeholder : '', onChange: handleChange, autoComplete: autoComplete ? 'on' : 'off', autoFocus: autoFocus, className: "outline-none bg-inherit flex-grow", required: required, onFocus: handleFocus, onKeyUp: onKeyUpHandler, onKeyDown: handleKeyDown, onBlur: handleBlur })),
98
- textError && react_1.default.createElement("p", { className: "text-sm mt-1 text-red-primary" }, textError),
99
- showError && !textError && (react_1.default.createElement("p", { className: "text-sm mt-1 text-red-primary" }, "\u0628\u0631\u0627\u06CC \u062B\u0628\u062A \u0628\u0627\u0631\u06A9\u062F \u06A9\u0644\u06CC\u062F Enter \u0631\u0627 \u0641\u0634\u0627\u0631 \u062F\u0647\u06CC\u062F"))));
115
+ react_1.default.createElement("input", { ref: inputRef, type: "text", value: currentValue, id: label, placeholder: items.length === 0 ? placeholder : '', onChange: handleChange, autoComplete: autoComplete ? 'on' : 'off', autoFocus: autoFocus, className: "outline-none bg-inherit flex-grow", required: required, onFocus: onFocusHandler, onKeyUp: onKeyUpHandler, onKeyDown: handleKeyDown, onBlur: handleBlur })),
116
+ isErrorVisible() && react_1.default.createElement("p", { className: "text-sm mt-1 text-red-primary" }, getErrorMessage())));
100
117
  };
101
118
  exports.default = InputMultiselect;
@@ -39,11 +39,18 @@ export type NoResultsType = ReactNode | string | {
39
39
  icon?: IconType;
40
40
  text: string;
41
41
  };
42
- export type CreatableSelectProps = {
43
- options: SelectOption[] | null;
44
- value: SelectOption | SelectOption[] | null;
42
+ export type ToOptionMapper<T> = (item: T) => SelectOption;
43
+ export type CreateOptionMapper<T> = (inputValue: string) => Promise<T> | T;
44
+ export type CreatableSelectProps<T = SelectOption> = {
45
+ options: T[] | null;
46
+ value: T | T[] | null;
45
47
  onChange?: (e: React.ChangeEvent<HTMLInputElement>) => void;
46
48
  onClick?: (value: SelectOption | SelectOption[] | null) => void;
49
+ onValueChange?: (value: T | T[] | null) => void;
50
+ toOption?: ToOptionMapper<T>;
51
+ fetchRawOptions?: (inputValue: string) => Promise<T[]>;
52
+ fetchOptions?: (inputValue: string) => Promise<SelectOption[]>;
53
+ mapCreateOption?: CreateOptionMapper<T>;
47
54
  onCreateOption?: (inputValue: string) => Promise<void> | void;
48
55
  placeholder?: string;
49
56
  isLoading?: boolean;
@@ -58,7 +65,6 @@ export type CreatableSelectProps = {
58
65
  tailwindStyle?: TailwindStyleProps;
59
66
  label?: string;
60
67
  iconSrc: IconSourceProps;
61
- fetchOptions?: (inputValue: string) => Promise<SelectOption[]>;
62
68
  onAddClick: (e: boolean) => void;
63
69
  isMultiSelect?: boolean;
64
70
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "hi-tm",
3
- "version": "0.3.7",
3
+ "version": "0.3.9",
4
4
  "styles": "dist/styles/globals.css",
5
5
  "main": "dist/index.js",
6
6
  "exports": {