x-ui-design 0.8.38 → 0.8.40
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/esm/types/hooks/usePosition.d.ts +1 -2
- package/dist/index.esm.js +58 -60
- package/dist/index.esm.js.map +1 -1
- package/dist/index.js +58 -60
- package/dist/index.js.map +1 -1
- package/lib/components/Popover/Popover.tsx +6 -3
- package/lib/hooks/usePosition.ts +69 -76
- package/package.json +1 -1
- package/src/app/page.tsx +4 -1
|
@@ -7,9 +7,8 @@ type TPosition = {
|
|
|
7
7
|
getPopupContainer?: HTMLElement;
|
|
8
8
|
placement?: Placement;
|
|
9
9
|
offset?: number;
|
|
10
|
-
controlDropdownPosition?: CSSProperties;
|
|
11
10
|
};
|
|
12
|
-
export declare const usePosition: ({ isOpen, offset, popupRef, placement, triggerRef, getPopupContainer,
|
|
11
|
+
export declare const usePosition: ({ isOpen, offset, popupRef, placement, triggerRef, getPopupContainer, }: TPosition) => {
|
|
13
12
|
showPlacement: string;
|
|
14
13
|
dropdownPosition: CSSProperties;
|
|
15
14
|
};
|
package/dist/index.esm.js
CHANGED
|
@@ -2609,8 +2609,7 @@ const usePosition = ({
|
|
|
2609
2609
|
popupRef,
|
|
2610
2610
|
placement,
|
|
2611
2611
|
triggerRef,
|
|
2612
|
-
getPopupContainer
|
|
2613
|
-
controlDropdownPosition
|
|
2612
|
+
getPopupContainer
|
|
2614
2613
|
}) => {
|
|
2615
2614
|
const [showPlacement, setShowPlacement] = useState('');
|
|
2616
2615
|
const [_dropdownPosition, setDropdownPosition] = useState({});
|
|
@@ -2618,66 +2617,62 @@ const usePosition = ({
|
|
|
2618
2617
|
if (!triggerRef.current) {
|
|
2619
2618
|
return {};
|
|
2620
2619
|
}
|
|
2621
|
-
|
|
2622
|
-
|
|
2623
|
-
|
|
2624
|
-
|
|
2625
|
-
|
|
2626
|
-
|
|
2627
|
-
|
|
2628
|
-
|
|
2629
|
-
const
|
|
2630
|
-
|
|
2631
|
-
|
|
2632
|
-
|
|
2633
|
-
|
|
2634
|
-
|
|
2635
|
-
|
|
2636
|
-
|
|
2637
|
-
|
|
2638
|
-
|
|
2639
|
-
|
|
2640
|
-
|
|
2641
|
-
|
|
2642
|
-
top: _top - (popupRef.current?.offsetHeight || 0) + 4 - (offset !== 4 ? offset * 2 : 0),
|
|
2643
|
-
left: leftPosition
|
|
2644
|
-
});
|
|
2645
|
-
} else {
|
|
2646
|
-
setDropdownPosition({
|
|
2647
|
-
top: _top + (triggerRef.current?.offsetHeight || 0) + offset,
|
|
2648
|
-
left: leftPosition
|
|
2649
|
-
});
|
|
2650
|
-
}
|
|
2620
|
+
const inputRect = triggerRef.current?.getBoundingClientRect();
|
|
2621
|
+
const dropdownHeight = popupRef.current?.offsetHeight || popupRef.current?.offsetHeight || 0;
|
|
2622
|
+
const containerRect = (getPopupContainer || getScrollParent(triggerRef.current, true) || document.body).getBoundingClientRect();
|
|
2623
|
+
const spaceAbove = inputRect.top - containerRect.top;
|
|
2624
|
+
const spaceBelow = containerRect.bottom - inputRect.bottom;
|
|
2625
|
+
const _shouldShowAbove = spaceBelow < dropdownHeight && spaceAbove > dropdownHeight;
|
|
2626
|
+
const hasRight = placement?.includes('Right');
|
|
2627
|
+
if (getPopupContainer) {
|
|
2628
|
+
const {
|
|
2629
|
+
minLeft,
|
|
2630
|
+
maxLeft,
|
|
2631
|
+
leftPosition
|
|
2632
|
+
} = clampWithinContainer(hasRight ? (inputRect.left || 0) + (triggerRef.current?.offsetWidth || 0) - (popupRef.current?.offsetWidth || 0) : (inputRect.left || 0) + document.documentElement.scrollLeft, popupRef.current?.offsetWidth || 0, containerRect);
|
|
2633
|
+
const _center = minLeft + maxLeft < (popupRef.current?.offsetWidth || 0) ? 'center' : '';
|
|
2634
|
+
setShowPlacement(_shouldShowAbove ? `bottom ${_center}` : `${_center}`);
|
|
2635
|
+
const _top = (inputRect.top || 0) + document.documentElement.scrollTop;
|
|
2636
|
+
if (_shouldShowAbove) {
|
|
2637
|
+
setDropdownPosition({
|
|
2638
|
+
top: _top - (popupRef.current?.offsetHeight || 0) + 4 - (offset !== 4 ? offset * 2 : 0),
|
|
2639
|
+
left: leftPosition
|
|
2640
|
+
});
|
|
2651
2641
|
} else {
|
|
2652
2642
|
setDropdownPosition({
|
|
2653
|
-
top:
|
|
2654
|
-
|
|
2655
|
-
left: (() => {
|
|
2656
|
-
const {
|
|
2657
|
-
minLeft,
|
|
2658
|
-
maxLeft,
|
|
2659
|
-
leftPosition
|
|
2660
|
-
} = clampWithinContainer(triggerRef.current.offsetLeft + (triggerRef.current?.offsetWidth || 0) - (popupRef.current?.offsetWidth || dropdownHeight), popupRef.current?.offsetWidth || dropdownHeight, containerRect);
|
|
2661
|
-
const _center = minLeft + maxLeft < (popupRef.current?.offsetWidth || 0) ? 'center' : '';
|
|
2662
|
-
setShowPlacement(_shouldShowAbove ? `bottom ${_center}` : `${_center}`);
|
|
2663
|
-
return leftPosition;
|
|
2664
|
-
})()
|
|
2665
|
-
} : {
|
|
2666
|
-
left: (() => {
|
|
2667
|
-
const {
|
|
2668
|
-
minLeft,
|
|
2669
|
-
maxLeft,
|
|
2670
|
-
leftPosition
|
|
2671
|
-
} = clampWithinContainer(triggerRef.current.offsetLeft, popupRef.current?.offsetWidth || dropdownHeight, containerRect);
|
|
2672
|
-
const _center = minLeft + maxLeft < (popupRef.current?.offsetWidth || 0) ? 'center' : '';
|
|
2673
|
-
setShowPlacement(_shouldShowAbove ? `bottom ${_center}` : `${_center}`);
|
|
2674
|
-
return leftPosition;
|
|
2675
|
-
})()
|
|
2676
|
-
})
|
|
2643
|
+
top: _top + (triggerRef.current?.offsetHeight || 0) + offset,
|
|
2644
|
+
left: leftPosition
|
|
2677
2645
|
});
|
|
2678
2646
|
}
|
|
2647
|
+
} else {
|
|
2648
|
+
setDropdownPosition({
|
|
2649
|
+
top: (_shouldShowAbove ? triggerRef.current.offsetTop - (popupRef.current?.offsetHeight || dropdownHeight) - offset * 2 : triggerRef.current.offsetTop + triggerRef.current?.offsetHeight) + offset,
|
|
2650
|
+
...(hasRight ? {
|
|
2651
|
+
left: (() => {
|
|
2652
|
+
const {
|
|
2653
|
+
minLeft,
|
|
2654
|
+
maxLeft,
|
|
2655
|
+
leftPosition
|
|
2656
|
+
} = clampWithinContainer(triggerRef.current.offsetLeft + (triggerRef.current?.offsetWidth || 0) - (popupRef.current?.offsetWidth || dropdownHeight), popupRef.current?.offsetWidth || dropdownHeight, containerRect);
|
|
2657
|
+
const _center = minLeft + maxLeft < (popupRef.current?.offsetWidth || 0) ? 'center' : '';
|
|
2658
|
+
setShowPlacement(_shouldShowAbove ? `bottom ${_center}` : `${_center}`);
|
|
2659
|
+
return leftPosition;
|
|
2660
|
+
})()
|
|
2661
|
+
} : {
|
|
2662
|
+
left: (() => {
|
|
2663
|
+
const {
|
|
2664
|
+
minLeft,
|
|
2665
|
+
maxLeft,
|
|
2666
|
+
leftPosition
|
|
2667
|
+
} = clampWithinContainer(triggerRef.current.offsetLeft, popupRef.current?.offsetWidth || dropdownHeight, containerRect);
|
|
2668
|
+
const _center = minLeft + maxLeft < (popupRef.current?.offsetWidth || 0) ? 'center' : '';
|
|
2669
|
+
setShowPlacement(_shouldShowAbove ? `bottom ${_center}` : `${_center}`);
|
|
2670
|
+
return leftPosition;
|
|
2671
|
+
})()
|
|
2672
|
+
})
|
|
2673
|
+
});
|
|
2679
2674
|
}
|
|
2680
|
-
}, [offset, popupRef, placement, triggerRef, getPopupContainer
|
|
2675
|
+
}, [offset, popupRef, placement, triggerRef, getPopupContainer]);
|
|
2681
2676
|
useEffect(() => {
|
|
2682
2677
|
if (!isOpen) return;
|
|
2683
2678
|
const _dropdownPosition = () => dropdownPosition();
|
|
@@ -5566,7 +5561,6 @@ const Popover = ({
|
|
|
5566
5561
|
popupRef,
|
|
5567
5562
|
placement,
|
|
5568
5563
|
triggerRef,
|
|
5569
|
-
controlDropdownPosition,
|
|
5570
5564
|
getPopupContainer: getPopupContainer?.(triggerRef.current)
|
|
5571
5565
|
});
|
|
5572
5566
|
useEffect(() => {
|
|
@@ -5615,7 +5609,10 @@ const Popover = ({
|
|
|
5615
5609
|
return /*#__PURE__*/cloneElement(child, {
|
|
5616
5610
|
key: index,
|
|
5617
5611
|
...{
|
|
5618
|
-
style
|
|
5612
|
+
style: {
|
|
5613
|
+
...style,
|
|
5614
|
+
...(controlDropdownPosition || {})
|
|
5615
|
+
},
|
|
5619
5616
|
...childProps,
|
|
5620
5617
|
ref: triggerRef,
|
|
5621
5618
|
className: `${prefixCls}-wrapper-content`
|
|
@@ -5634,7 +5631,8 @@ const Popover = ({
|
|
|
5634
5631
|
zIndex: 1000,
|
|
5635
5632
|
position: "absolute",
|
|
5636
5633
|
...overlayStyle,
|
|
5637
|
-
...dropdownPosition
|
|
5634
|
+
...dropdownPosition,
|
|
5635
|
+
...(controlDropdownPosition || {})
|
|
5638
5636
|
}
|
|
5639
5637
|
}), title && /*#__PURE__*/React.createElement("div", {
|
|
5640
5638
|
className: `${prefixCls}-title`
|