hi-tm 0.6.8 → 0.6.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,4 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
import type { SelectOption, CreatableSelectProps } from '../../types/DropDown/CreatableDropDown';
|
|
3
|
-
|
|
3
|
+
declare const _default: React.MemoExoticComponent<(<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)>;
|
|
4
|
+
export default _default;
|
|
@@ -33,7 +33,6 @@ var __importStar = (this && this.__importStar) || (function () {
|
|
|
33
33
|
};
|
|
34
34
|
})();
|
|
35
35
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
-
exports.default = CreatableSelect;
|
|
37
36
|
const react_1 = __importStar(require("react"));
|
|
38
37
|
// Default Tailwind styles
|
|
39
38
|
const defaultStyles = {
|
|
@@ -87,7 +86,7 @@ const renderNoResults = (noResults, className, searchIcon) => {
|
|
|
87
86
|
return noResults;
|
|
88
87
|
}
|
|
89
88
|
};
|
|
90
|
-
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, }) {
|
|
89
|
+
exports.default = react_1.default.memo(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, }) {
|
|
91
90
|
// Default icons
|
|
92
91
|
const defaultIcons = {
|
|
93
92
|
dropdownOpen: '▼',
|
|
@@ -136,25 +135,9 @@ function CreatableSelect({ options = [], value, onChange, onClick, onValueChange
|
|
|
136
135
|
const containerRef = (0, react_1.useRef)(null);
|
|
137
136
|
const inputRef = (0, react_1.useRef)(null);
|
|
138
137
|
const scrollContainerRef = (0, react_1.useRef)(null);
|
|
139
|
-
const scrollPositionRef = (0, react_1.useRef)(0);
|
|
140
|
-
// Save scroll position before re-renders
|
|
141
|
-
const saveScrollPosition = (0, react_1.useCallback)(() => {
|
|
142
|
-
if (scrollContainerRef.current) {
|
|
143
|
-
scrollPositionRef.current = scrollContainerRef.current.scrollLeft;
|
|
144
|
-
}
|
|
145
|
-
}, []);
|
|
146
|
-
// Restore scroll position after re-renders
|
|
147
|
-
const restoreScrollPosition = (0, react_1.useCallback)(() => {
|
|
148
|
-
if (scrollContainerRef.current && scrollPositionRef.current > 0) {
|
|
149
|
-
// Only restore if the position has actually changed
|
|
150
|
-
if (scrollContainerRef.current.scrollLeft !== scrollPositionRef.current) {
|
|
151
|
-
scrollContainerRef.current.scrollLeft = scrollPositionRef.current;
|
|
152
|
-
}
|
|
153
|
-
}
|
|
154
|
-
}, []);
|
|
155
138
|
// Prevent scroll jumping by maintaining position during keyboard navigation
|
|
156
139
|
const handleKeyboardNavigation = (0, react_1.useCallback)((direction) => {
|
|
157
|
-
|
|
140
|
+
// Don't save scroll position - just update the highlighted index
|
|
158
141
|
if (direction === 'up') {
|
|
159
142
|
highlightedIndexRef.current = Math.max(0, highlightedIndexRef.current - 1);
|
|
160
143
|
}
|
|
@@ -163,11 +146,7 @@ function CreatableSelect({ options = [], value, onChange, onClick, onValueChange
|
|
|
163
146
|
}
|
|
164
147
|
// Force re-render of dropdown options only
|
|
165
148
|
setForceUpdate((prev) => prev + 1);
|
|
166
|
-
|
|
167
|
-
requestAnimationFrame(() => {
|
|
168
|
-
restoreScrollPosition();
|
|
169
|
-
});
|
|
170
|
-
}, [filteredOptions.length, saveScrollPosition, restoreScrollPosition]);
|
|
149
|
+
}, [filteredOptions.length]);
|
|
171
150
|
// Sync external value prop with internal selectedValues state
|
|
172
151
|
(0, react_1.useEffect)(() => {
|
|
173
152
|
// Don't sync if user is actively interacting with the component
|
|
@@ -216,13 +195,6 @@ function CreatableSelect({ options = [], value, onChange, onClick, onValueChange
|
|
|
216
195
|
setFilteredOptions(options ?? []);
|
|
217
196
|
}
|
|
218
197
|
}, [options, hasSearched]);
|
|
219
|
-
// Restore scroll position after filteredOptions changes
|
|
220
|
-
(0, react_1.useEffect)(() => {
|
|
221
|
-
// Use requestAnimationFrame to ensure DOM has updated
|
|
222
|
-
requestAnimationFrame(() => {
|
|
223
|
-
restoreScrollPosition();
|
|
224
|
-
});
|
|
225
|
-
}, [filteredOptions, restoreScrollPosition]);
|
|
226
198
|
// Reset filtered list when input cleared
|
|
227
199
|
(0, react_1.useEffect)(() => {
|
|
228
200
|
if (inputValue === '') {
|
|
@@ -401,8 +373,14 @@ function CreatableSelect({ options = [], value, onChange, onClick, onValueChange
|
|
|
401
373
|
onAddClick(true);
|
|
402
374
|
}
|
|
403
375
|
}, [onAddClick]);
|
|
404
|
-
const scrollContainer = (0, react_1.useMemo)(() => (react_1.default.createElement("div", { ref: scrollContainerRef, className: "flex-grow flex items-center overflow-x-auto creatable-dropdown-scroll", key: "scroll-container-stable"
|
|
405
|
-
|
|
376
|
+
const scrollContainer = (0, react_1.useMemo)(() => (react_1.default.createElement("div", { ref: scrollContainerRef, className: "flex-grow flex items-center overflow-x-auto creatable-dropdown-scroll", key: "scroll-container-stable", style: {
|
|
377
|
+
scrollBehavior: 'auto',
|
|
378
|
+
scrollbarWidth: 'none',
|
|
379
|
+
msOverflowStyle: 'none',
|
|
380
|
+
minWidth: 0, // Prevent flex item from growing beyond container
|
|
381
|
+
flexShrink: 1, // Allow shrinking
|
|
382
|
+
} },
|
|
383
|
+
react_1.default.createElement("div", { className: "flex items-center gap-2 flex-nowrap min-w-0" },
|
|
406
384
|
selectedValues.length > 0 &&
|
|
407
385
|
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" },
|
|
408
386
|
react_1.default.createElement("span", { className: "truncate" }, deriveLabel(val)),
|
|
@@ -455,4 +433,26 @@ function CreatableSelect({ options = [], value, onChange, onClick, onValueChange
|
|
|
455
433
|
createOptionMessage,
|
|
456
434
|
": ",
|
|
457
435
|
inputValue)))))))));
|
|
458
|
-
}
|
|
436
|
+
}, (prevProps, nextProps) => {
|
|
437
|
+
// Custom comparison function for React.memo
|
|
438
|
+
// Only re-render if the props that affect the component's output have changed.
|
|
439
|
+
// This prevents unnecessary re-renders when options, value, or other props are shallowly equal.
|
|
440
|
+
return (prevProps.options === nextProps.options &&
|
|
441
|
+
prevProps.value === nextProps.value &&
|
|
442
|
+
prevProps.isLoading === nextProps.isLoading &&
|
|
443
|
+
prevProps.isDisabled === nextProps.isDisabled &&
|
|
444
|
+
prevProps.isCreatable === nextProps.isCreatable &&
|
|
445
|
+
prevProps.isMultiSelect === nextProps.isMultiSelect &&
|
|
446
|
+
prevProps.noOptionsMessage === nextProps.noOptionsMessage &&
|
|
447
|
+
prevProps.noResultsFound === nextProps.noResultsFound &&
|
|
448
|
+
prevProps.loadingMessage === nextProps.loadingMessage &&
|
|
449
|
+
prevProps.createOptionMessage === nextProps.createOptionMessage &&
|
|
450
|
+
prevProps.className === nextProps.className &&
|
|
451
|
+
prevProps.tailwindStyle === nextProps.tailwindStyle &&
|
|
452
|
+
prevProps.iconSrc === nextProps.iconSrc &&
|
|
453
|
+
prevProps.fetchOptions === nextProps.fetchOptions &&
|
|
454
|
+
prevProps.label === nextProps.label &&
|
|
455
|
+
prevProps.onAddClick === nextProps.onAddClick &&
|
|
456
|
+
prevProps.getOptionLabel === nextProps.getOptionLabel &&
|
|
457
|
+
prevProps.getOptionValue === nextProps.getOptionValue);
|
|
458
|
+
});
|
package/dist/styles/globals.css
CHANGED
|
@@ -90,9 +90,12 @@ li.activeSidebar-subset::after {
|
|
|
90
90
|
|
|
91
91
|
/* Custom scroll behavior for CreatableDropDown */
|
|
92
92
|
.creatable-dropdown-scroll {
|
|
93
|
-
scroll-behavior:
|
|
93
|
+
scroll-behavior: auto !important;
|
|
94
94
|
scrollbar-width: none;
|
|
95
95
|
-ms-overflow-style: none;
|
|
96
|
+
will-change: auto;
|
|
97
|
+
transform: translateZ(0);
|
|
98
|
+
backface-visibility: hidden;
|
|
96
99
|
}
|
|
97
100
|
|
|
98
101
|
.creatable-dropdown-scroll::-webkit-scrollbar {
|
|
@@ -100,7 +103,12 @@ li.activeSidebar-subset::after {
|
|
|
100
103
|
}
|
|
101
104
|
|
|
102
105
|
.creatable-dropdown-scroll:focus-within {
|
|
103
|
-
scroll-behavior: auto;
|
|
106
|
+
scroll-behavior: auto !important;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
/* Prevent scroll container from being affected by re-renders */
|
|
110
|
+
.creatable-dropdown-scroll * {
|
|
111
|
+
will-change: auto;
|
|
104
112
|
}
|
|
105
113
|
.danger {
|
|
106
114
|
background-color: #ffffff;
|