x-ui-design 0.9.21 → 0.9.22
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 +14 -15
- package/dist/index.esm.js.map +1 -1
- package/dist/index.js +14 -15
- package/dist/index.js.map +1 -1
- package/lib/components/Dropdown/Dropdown.tsx +1 -1
- package/lib/hooks/usePopupPosition.ts +13 -16
- package/package.json +1 -1
- package/src/app/page.tsx +11 -1
package/dist/index.esm.js
CHANGED
|
@@ -2618,7 +2618,7 @@ const ConditionalWrapper = ({
|
|
|
2618
2618
|
children
|
|
2619
2619
|
}) => condition ? wrapper(children) : children;
|
|
2620
2620
|
|
|
2621
|
-
const OFFSET =
|
|
2621
|
+
const OFFSET = 11;
|
|
2622
2622
|
const usePopupPosition = ({
|
|
2623
2623
|
open,
|
|
2624
2624
|
setOpen,
|
|
@@ -2630,6 +2630,7 @@ const usePopupPosition = ({
|
|
|
2630
2630
|
const [_placement, _setPlacement] = useState(placement ?? "bottomLeft");
|
|
2631
2631
|
const [popupPosition, setPopupPosition] = useState({});
|
|
2632
2632
|
const inBody = useMemo(() => popupContainer?.tagName === 'BODY', [popupContainer]);
|
|
2633
|
+
const popupRect = useMemo(() => popupRef.current?.getBoundingClientRect(), [popupRef.current]);
|
|
2633
2634
|
const calculatePosition = useCallback(e => {
|
|
2634
2635
|
const container = targetRef.current?.getBoundingClientRect();
|
|
2635
2636
|
if (!container) {
|
|
@@ -2658,8 +2659,7 @@ const usePopupPosition = ({
|
|
|
2658
2659
|
setPopupPosition({});
|
|
2659
2660
|
return;
|
|
2660
2661
|
}
|
|
2661
|
-
if (
|
|
2662
|
-
const popupRect = popupRef.current?.getBoundingClientRect();
|
|
2662
|
+
if (popupRect) {
|
|
2663
2663
|
const availableSpace = {
|
|
2664
2664
|
top: container.top - (popupRect.height + OFFSET),
|
|
2665
2665
|
bottom: (inBody ? window.innerHeight : scrollableParents?.clientHeight || 0) - (container.bottom + popupRect.height + OFFSET),
|
|
@@ -2694,7 +2694,7 @@ const usePopupPosition = ({
|
|
|
2694
2694
|
case "bottom":
|
|
2695
2695
|
setPopupPosition({
|
|
2696
2696
|
top: positions.top + container.height,
|
|
2697
|
-
left: positions.left + (container.width || 0) / 2 - (
|
|
2697
|
+
left: positions.left + (container.width || 0) / 2 - (popupRect?.width || 0) / 2
|
|
2698
2698
|
});
|
|
2699
2699
|
break;
|
|
2700
2700
|
case "bottomLeft":
|
|
@@ -2706,31 +2706,31 @@ const usePopupPosition = ({
|
|
|
2706
2706
|
case "bottomRight":
|
|
2707
2707
|
setPopupPosition({
|
|
2708
2708
|
top: positions.top + container.height,
|
|
2709
|
-
left: positions.left + (container.width || 0) - (
|
|
2709
|
+
left: positions.left + (container.width || 0) - (popupRect?.width || 0)
|
|
2710
2710
|
});
|
|
2711
2711
|
break;
|
|
2712
2712
|
case "top":
|
|
2713
2713
|
setPopupPosition({
|
|
2714
|
-
top: positions.top - (
|
|
2715
|
-
left: positions.left + (container.width || 0) / 2 - (
|
|
2714
|
+
top: positions.top - (popupRect?.height || 0) - OFFSET * 2,
|
|
2715
|
+
left: positions.left + (container.width || 0) / 2 - (popupRect?.width || 0) / 2
|
|
2716
2716
|
});
|
|
2717
2717
|
break;
|
|
2718
2718
|
case "topLeft":
|
|
2719
2719
|
setPopupPosition({
|
|
2720
|
-
top: positions.top - (
|
|
2720
|
+
top: positions.top - (popupRect?.height || 0) - OFFSET * 2,
|
|
2721
2721
|
left: positions.left
|
|
2722
2722
|
});
|
|
2723
2723
|
break;
|
|
2724
2724
|
case "topRight":
|
|
2725
2725
|
setPopupPosition({
|
|
2726
|
-
top: positions.top - (
|
|
2727
|
-
left: positions.left + (container.width || 0) - (
|
|
2726
|
+
top: positions.top - (popupRect?.height || 0) - OFFSET * 2,
|
|
2727
|
+
left: positions.left + (container.width || 0) - (popupRect?.width || 0)
|
|
2728
2728
|
});
|
|
2729
2729
|
break;
|
|
2730
2730
|
}
|
|
2731
2731
|
};
|
|
2732
2732
|
_calculation();
|
|
2733
|
-
}, [targetRef, popupContainer,
|
|
2733
|
+
}, [targetRef, popupContainer, popupRect, inBody, _placement, setOpen]);
|
|
2734
2734
|
useEffect(() => {
|
|
2735
2735
|
if (!open) {
|
|
2736
2736
|
return;
|
|
@@ -2744,7 +2744,6 @@ const usePopupPosition = ({
|
|
|
2744
2744
|
scrollableParents
|
|
2745
2745
|
} = getElementParentDetails(targetRef.current, true);
|
|
2746
2746
|
scrollableParents?.addEventListener("scroll", calculatePosition, options);
|
|
2747
|
-
// setPositionRelative('relative');
|
|
2748
2747
|
calculatePosition();
|
|
2749
2748
|
document.body.addEventListener("scroll", calculatePosition, options);
|
|
2750
2749
|
document.body.addEventListener("resize", calculatePosition, options);
|
|
@@ -2752,13 +2751,13 @@ const usePopupPosition = ({
|
|
|
2752
2751
|
controller.abort();
|
|
2753
2752
|
setPopupPosition({});
|
|
2754
2753
|
};
|
|
2755
|
-
}, [open, calculatePosition]);
|
|
2754
|
+
}, [open, targetRef, calculatePosition]);
|
|
2756
2755
|
return {
|
|
2757
2756
|
_placement,
|
|
2758
2757
|
popupStyle: {
|
|
2759
2758
|
zIndex: 10000,
|
|
2760
2759
|
position: "absolute",
|
|
2761
|
-
opacity: Object.keys(popupPosition).length ? 1 : 0,
|
|
2760
|
+
opacity: Object.keys(popupPosition).length && popupRect?.width ? 1 : 0,
|
|
2762
2761
|
...popupPosition
|
|
2763
2762
|
}
|
|
2764
2763
|
};
|
|
@@ -5571,7 +5570,7 @@ function MenuInner({
|
|
|
5571
5570
|
className: `${prefixCls}-menu`,
|
|
5572
5571
|
ref: menuRef,
|
|
5573
5572
|
role: "menu"
|
|
5574
|
-
}, items
|
|
5573
|
+
}, items?.map(it => /*#__PURE__*/React.createElement("li", {
|
|
5575
5574
|
key: it.key,
|
|
5576
5575
|
role: "menuitem",
|
|
5577
5576
|
tabIndex: it.disabled ? -1 : 0,
|