hi-tm 0.9.7 → 0.9.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,3 +1,3 @@
|
|
|
1
1
|
import React from "react";
|
|
2
2
|
import type { SelectOption, CreatableSelectProps } from "../../types/DropDown/CreatableDropDown";
|
|
3
|
-
export default function CreatableSelect<T = SelectOption>({ options, value, onChange, onClick, onValueChange, onCreateOption, placeholder, isLoading, isDisabled, isCreatable, isMultiSelect, noOptionsMessage, noResultsFound, loadingMessage, createOptionMessage, className, tailwindStyle, iconSrc, fetchOptions, label, onAddClick, getOptionLabel, getOptionValue, }: CreatableSelectProps<T>): React.JSX.Element;
|
|
3
|
+
export default function CreatableSelect<T = SelectOption>({ options, value, onChange, onClick, onValueChange, onCreateOption, placeholder, isLoading, isDisabled, isCreatable, isMultiSelect, noOptionsMessage, noResultsFound, loadingMessage, createOptionMessage, className, tailwindStyle, iconSrc, fetchOptions, label, onAddClick, getOptionLabel, getOptionValue, onFocusShowAllData, }: CreatableSelectProps<T>): React.JSX.Element;
|
|
@@ -89,7 +89,7 @@ const renderNoResults = (noResults, className, searchIcon) => {
|
|
|
89
89
|
return noResults;
|
|
90
90
|
}
|
|
91
91
|
};
|
|
92
|
-
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, }) {
|
|
92
|
+
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, onFocusShowAllData, }) {
|
|
93
93
|
// Default icons
|
|
94
94
|
const defaultIcons = {
|
|
95
95
|
dropdownOpen: "▼",
|
|
@@ -131,7 +131,6 @@ function CreatableSelect({ options = [], value, onChange, onClick, onValueChange
|
|
|
131
131
|
const [internalLoading, setInternalLoading] = (0, react_1.useState)(false);
|
|
132
132
|
const [hasSearched, setHasSearched] = (0, react_1.useState)(false);
|
|
133
133
|
const [selectedValues, setSelectedValues] = (0, react_1.useState)([]);
|
|
134
|
-
const [showAllOptions, setShowAllOptions] = (0, react_1.useState)(false);
|
|
135
134
|
const containerRef = (0, react_1.useRef)(null);
|
|
136
135
|
const inputRef = (0, react_1.useRef)(null);
|
|
137
136
|
// Sync external value (ids or option objects) with internal selectedValues state
|
|
@@ -208,41 +207,10 @@ function CreatableSelect({ options = [], value, onChange, onClick, onValueChange
|
|
|
208
207
|
document.removeEventListener("click", handler);
|
|
209
208
|
};
|
|
210
209
|
}, []);
|
|
211
|
-
// const handleInputChange = useCallback(
|
|
212
|
-
// async (e: ChangeEvent<HTMLInputElement>) => {
|
|
213
|
-
// const next = e.target.value;
|
|
214
|
-
// setInputValue(next);
|
|
215
|
-
// setIsOpen(true);
|
|
216
|
-
// if (onChange) onChange(e);
|
|
217
|
-
// if (fetchOptions && next.trim() !== "") {
|
|
218
|
-
// setInternalLoading(true);
|
|
219
|
-
// setHasSearched(true);
|
|
220
|
-
// try {
|
|
221
|
-
// const newOptions = await fetchOptions(next);
|
|
222
|
-
// setFilteredOptions(newOptions ?? []);
|
|
223
|
-
// } catch {
|
|
224
|
-
// } finally {
|
|
225
|
-
// setInternalLoading(false);
|
|
226
|
-
// }
|
|
227
|
-
// } else if (next.trim() === "") {
|
|
228
|
-
// setFilteredOptions(options ?? []);
|
|
229
|
-
// setHasSearched(false);
|
|
230
|
-
// } else {
|
|
231
|
-
// const searchText = String(next).trim().toLowerCase();
|
|
232
|
-
// const filtered = (options ?? []).filter((option) =>
|
|
233
|
-
// deriveLabel(option).toLowerCase().includes(searchText)
|
|
234
|
-
// );
|
|
235
|
-
// setFilteredOptions(filtered);
|
|
236
|
-
// setHasSearched(true);
|
|
237
|
-
// }
|
|
238
|
-
// },
|
|
239
|
-
// [onChange, fetchOptions, options, deriveLabel]
|
|
240
|
-
// );
|
|
241
210
|
const handleInputChange = (0, react_1.useCallback)(async (e) => {
|
|
242
211
|
const next = e.target.value;
|
|
243
212
|
setInputValue(next);
|
|
244
213
|
setIsOpen(true);
|
|
245
|
-
setShowAllOptions(false); // ریست کردن حالت نمایش همه
|
|
246
214
|
if (onChange)
|
|
247
215
|
onChange(e);
|
|
248
216
|
if (fetchOptions && next.trim() !== "") {
|
|
@@ -403,41 +371,15 @@ function CreatableSelect({ options = [], value, onChange, onClick, onValueChange
|
|
|
403
371
|
onAddClick(true);
|
|
404
372
|
}
|
|
405
373
|
}, [onAddClick]);
|
|
406
|
-
|
|
407
|
-
// (e: React.MouseEvent) => {
|
|
408
|
-
// e.preventDefault();
|
|
409
|
-
// if (!isDisabled) {
|
|
410
|
-
// setIsOpen((prev) => !prev);
|
|
411
|
-
// if (!isOpen && inputRef.current) {
|
|
412
|
-
// inputRef.current.focus({ preventScroll: true });
|
|
413
|
-
// }
|
|
414
|
-
// }
|
|
415
|
-
// },
|
|
416
|
-
// [isDisabled, isOpen]
|
|
417
|
-
// );
|
|
418
|
-
const handleTriggerClick = (0, react_1.useCallback)(async (e) => {
|
|
374
|
+
const handleTriggerClick = (0, react_1.useCallback)((e) => {
|
|
419
375
|
e.preventDefault();
|
|
420
376
|
if (!isDisabled) {
|
|
421
377
|
setIsOpen((prev) => !prev);
|
|
422
378
|
if (!isOpen && inputRef.current) {
|
|
423
379
|
inputRef.current.focus({ preventScroll: true });
|
|
424
380
|
}
|
|
425
|
-
// اگر اینپوت خالی است و روی آن کلیک شد، لیست کامل را نمایش دهید
|
|
426
|
-
if (inputValue.trim() === "" && fetchOptions) {
|
|
427
|
-
setInternalLoading(true);
|
|
428
|
-
try {
|
|
429
|
-
const allOptions = await fetchOptions("");
|
|
430
|
-
setFilteredOptions(allOptions ?? []);
|
|
431
|
-
setShowAllOptions(true);
|
|
432
|
-
}
|
|
433
|
-
catch {
|
|
434
|
-
}
|
|
435
|
-
finally {
|
|
436
|
-
setInternalLoading(false);
|
|
437
|
-
}
|
|
438
|
-
}
|
|
439
381
|
}
|
|
440
|
-
}, [isDisabled, isOpen
|
|
382
|
+
}, [isDisabled, isOpen]);
|
|
441
383
|
return (react_1.default.createElement("div", { ref: containerRef, className: `relative w-full ${className} ${styles.container}`, onKeyDown: handleKeyDown },
|
|
442
384
|
label && (react_1.default.createElement("label", { className: "block text-sm font-medium text-gray-700 mb-1" }, label)),
|
|
443
385
|
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 },
|
|
@@ -447,7 +389,9 @@ function CreatableSelect({ options = [], value, onChange, onClick, onValueChange
|
|
|
447
389
|
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" },
|
|
448
390
|
react_1.default.createElement("span", { className: "truncate" }, deriveLabel(val)),
|
|
449
391
|
react_1.default.createElement("button", { type: "button", onClick: (e) => clearValue(e, val), className: styles.clearButton }, renderIcon(icons.clear, styles.icon))))),
|
|
450
|
-
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()
|
|
392
|
+
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(), onFocus: () => {
|
|
393
|
+
console.log("focus");
|
|
394
|
+
} }))),
|
|
451
395
|
react_1.default.createElement("div", { className: "flex-shrink-0 flex items-center gap-1 ml-2" },
|
|
452
396
|
iconSrc.hasAdd && (react_1.default.createElement("button", { type: "button", onClick: handleAddIconClick, className: styles.clearButton }, renderIcon(iconSrc.hasAdd, styles.icon))),
|
|
453
397
|
styles.separator && react_1.default.createElement("div", { className: styles.separator }),
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ReactNode } from
|
|
1
|
+
import { ReactNode } from "react";
|
|
2
2
|
export type IconType = ReactNode | string | {
|
|
3
3
|
src: string;
|
|
4
4
|
alt?: string;
|
|
@@ -71,4 +71,5 @@ export type CreatableSelectProps<T = SelectOption> = {
|
|
|
71
71
|
isMultiSelect?: boolean;
|
|
72
72
|
getOptionLabel?: OptionLabelGetter<T>;
|
|
73
73
|
getOptionValue?: OptionValueGetter<T>;
|
|
74
|
+
onFocusShowAllData?: boolean;
|
|
74
75
|
};
|