x-ui-design 0.2.97 → 0.2.99
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.
- package/dist/index.esm.js +53 -11
- package/dist/index.esm.js.map +1 -1
- package/dist/index.js +53 -11
- package/dist/index.js.map +1 -1
- package/lib/components/Select/Select.tsx +62 -12
- package/package.json +1 -1
- package/src/app/page.tsx +22 -2
package/dist/index.js
CHANGED
|
@@ -3027,27 +3027,64 @@ const SelectComponent = /*#__PURE__*/React$1.forwardRef(({
|
|
|
3027
3027
|
document.removeEventListener('mousedown', handleClickOutside);
|
|
3028
3028
|
};
|
|
3029
3029
|
}, [handleClearInputValue, open, hasMode]);
|
|
3030
|
-
React$1.
|
|
3031
|
-
if (!selectRef.current
|
|
3032
|
-
return;
|
|
3033
|
-
}
|
|
3030
|
+
const updateDropdownPosition = React$1.useCallback(() => {
|
|
3031
|
+
if (!selectRef.current) return;
|
|
3034
3032
|
const selectBox = selectRef.current.getBoundingClientRect();
|
|
3035
3033
|
const dropdownHeight = listHeight;
|
|
3036
3034
|
const windowHeight = window.innerHeight;
|
|
3037
3035
|
const spaceBelow = windowHeight - selectBox.bottom;
|
|
3038
3036
|
const spaceAbove = selectBox.top;
|
|
3039
3037
|
let positionStyle = {
|
|
3040
|
-
top: `${selectBox.bottom}px
|
|
3041
|
-
|
|
3038
|
+
top: `${selectBox.bottom + window.scrollY}px`,
|
|
3039
|
+
left: `${selectBox.left + window.scrollX}px`,
|
|
3040
|
+
width: `${selectBox.width}px`,
|
|
3041
|
+
position: 'absolute'
|
|
3042
3042
|
};
|
|
3043
3043
|
if (spaceBelow < dropdownHeight && spaceAbove > dropdownHeight) {
|
|
3044
3044
|
positionStyle = {
|
|
3045
|
-
top: `${selectBox.top - dropdownHeight}px
|
|
3046
|
-
|
|
3045
|
+
top: `${selectBox.top + window.scrollY - dropdownHeight}px`,
|
|
3046
|
+
left: `${selectBox.left + window.scrollX}px`,
|
|
3047
|
+
width: `${selectBox.width}px`,
|
|
3048
|
+
position: 'absolute'
|
|
3047
3049
|
};
|
|
3048
3050
|
}
|
|
3049
3051
|
setDropdownPosition(positionStyle);
|
|
3050
|
-
}, [listHeight
|
|
3052
|
+
}, [listHeight]);
|
|
3053
|
+
React$1.useEffect(() => {
|
|
3054
|
+
if (!isOpen) return;
|
|
3055
|
+
updateDropdownPosition();
|
|
3056
|
+
// const container = getPopupContainer?.(selectRef.current!);
|
|
3057
|
+
const scrollableParents = getScrollParents(selectRef.current);
|
|
3058
|
+
const handleScroll = () => {
|
|
3059
|
+
updateDropdownPosition();
|
|
3060
|
+
};
|
|
3061
|
+
// Add scroll listeners to all scrollable parents
|
|
3062
|
+
scrollableParents.forEach(el => {
|
|
3063
|
+
el.addEventListener('scroll', handleScroll, {
|
|
3064
|
+
passive: true
|
|
3065
|
+
});
|
|
3066
|
+
});
|
|
3067
|
+
// Add resize listener
|
|
3068
|
+
window.addEventListener('resize', updateDropdownPosition);
|
|
3069
|
+
return () => {
|
|
3070
|
+
scrollableParents.forEach(el => {
|
|
3071
|
+
el.removeEventListener('scroll', handleScroll);
|
|
3072
|
+
});
|
|
3073
|
+
window.removeEventListener('resize', updateDropdownPosition);
|
|
3074
|
+
};
|
|
3075
|
+
}, [isOpen, getPopupContainer, updateDropdownPosition]);
|
|
3076
|
+
// Helper function to get all scrollable parents
|
|
3077
|
+
const getScrollParents = element => {
|
|
3078
|
+
const parents = [];
|
|
3079
|
+
let current = element.parentElement;
|
|
3080
|
+
while (current) {
|
|
3081
|
+
if (current.scrollHeight > current.clientHeight) {
|
|
3082
|
+
parents.push(current);
|
|
3083
|
+
}
|
|
3084
|
+
current = current.parentElement;
|
|
3085
|
+
}
|
|
3086
|
+
return parents;
|
|
3087
|
+
};
|
|
3051
3088
|
const handleSearch = e => {
|
|
3052
3089
|
setSearchQuery(e.target.value);
|
|
3053
3090
|
onSearch?.(e.target.value);
|
|
@@ -3066,7 +3103,7 @@ const SelectComponent = /*#__PURE__*/React$1.forwardRef(({
|
|
|
3066
3103
|
}
|
|
3067
3104
|
const updatedSelected = [...selected, newOptionValue];
|
|
3068
3105
|
onChange?.(updatedSelected);
|
|
3069
|
-
onSelect?.(
|
|
3106
|
+
onSelect?.(updatedSelected);
|
|
3070
3107
|
const input = selectRef.current?.querySelector('input');
|
|
3071
3108
|
if (input) {
|
|
3072
3109
|
input.value = '';
|
|
@@ -3082,6 +3119,7 @@ const SelectComponent = /*#__PURE__*/React$1.forwardRef(({
|
|
|
3082
3119
|
const newSelection = selected.includes(optionValue) ? selected.filter(item => item !== optionValue) : [...selected, optionValue];
|
|
3083
3120
|
setSelected(newSelection);
|
|
3084
3121
|
onChange?.(newSelection, option);
|
|
3122
|
+
onSelect?.(newSelection, option);
|
|
3085
3123
|
if (selected.includes(optionValue)) {
|
|
3086
3124
|
onDeselect?.(optionValue, option);
|
|
3087
3125
|
} else {
|
|
@@ -3099,12 +3137,14 @@ const SelectComponent = /*#__PURE__*/React$1.forwardRef(({
|
|
|
3099
3137
|
const value = hasMode ? [] : '';
|
|
3100
3138
|
setSelected(value);
|
|
3101
3139
|
onChange?.('');
|
|
3140
|
+
onSelect?.('');
|
|
3102
3141
|
onClear?.();
|
|
3103
3142
|
handleClearInputValue();
|
|
3104
3143
|
};
|
|
3105
3144
|
const handleRemoveTag = e => {
|
|
3106
3145
|
const updatedSelected = hasMode ? selected.filter(item => item !== e.target.value) : e.target.value;
|
|
3107
3146
|
onChange?.(updatedSelected);
|
|
3147
|
+
onSelect?.(updatedSelected);
|
|
3108
3148
|
setSelected(updatedSelected);
|
|
3109
3149
|
};
|
|
3110
3150
|
const handleOnKeyDown = e => {
|
|
@@ -3125,6 +3165,7 @@ const SelectComponent = /*#__PURE__*/React$1.forwardRef(({
|
|
|
3125
3165
|
if (e.key === 'Backspace' && (hasMode ? !searchQuery.trim().length : searchQuery.trim().length)) {
|
|
3126
3166
|
const updatedSelected = hasMode ? selected.filter(item => item !== selected[selected.length - 1]) : searchQuery.trim();
|
|
3127
3167
|
onChange?.(updatedSelected);
|
|
3168
|
+
onSelect?.(updatedSelected);
|
|
3128
3169
|
setSelected(updatedSelected);
|
|
3129
3170
|
}
|
|
3130
3171
|
clearTimeout(timeout);
|
|
@@ -3139,7 +3180,8 @@ const SelectComponent = /*#__PURE__*/React$1.forwardRef(({
|
|
|
3139
3180
|
}));
|
|
3140
3181
|
}, [showArrow, showSearch, isOpen, suffixIcon]);
|
|
3141
3182
|
const popupContainer = React$1.useMemo(() => {
|
|
3142
|
-
|
|
3183
|
+
if (typeof window === 'undefined') return null;
|
|
3184
|
+
return selectRef.current ? getPopupContainer?.(selectRef.current) : document.body;
|
|
3143
3185
|
}, [getPopupContainer]);
|
|
3144
3186
|
const extractedOptions = children ? (Array.isArray(children) ? children : [children]).filter(e => e).map(child => child.props) : options;
|
|
3145
3187
|
const filteredOptions = extractedOptions.filter(option => {
|