x-ui-design 0.9.20 → 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 +13 -24
- package/dist/index.esm.js.map +1 -1
- package/dist/index.js +13 -24
- package/dist/index.js.map +1 -1
- package/lib/components/Dropdown/Dropdown.tsx +1 -1
- package/lib/hooks/usePopupPosition.ts +12 -37
- 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) {
|
|
@@ -2640,10 +2641,6 @@ const usePopupPosition = ({
|
|
|
2640
2641
|
relativePosition
|
|
2641
2642
|
} = getElementParentDetails(targetRef.current, true);
|
|
2642
2643
|
const _containsElement = scrollableParents?.contains(popupContainer) && popupContainer !== scrollableParents;
|
|
2643
|
-
const popupRect = popupRef.current?.getBoundingClientRect();
|
|
2644
|
-
if (!popupRect?.width) {
|
|
2645
|
-
return;
|
|
2646
|
-
}
|
|
2647
2644
|
const positions = !popupContainer ? {
|
|
2648
2645
|
top: (targetRef.current?.offsetTop || 0) + OFFSET,
|
|
2649
2646
|
left: targetRef.current?.offsetLeft || 0
|
|
@@ -2697,7 +2694,7 @@ const usePopupPosition = ({
|
|
|
2697
2694
|
case "bottom":
|
|
2698
2695
|
setPopupPosition({
|
|
2699
2696
|
top: positions.top + container.height,
|
|
2700
|
-
left: positions.left + (container.width || 0) / 2 - (
|
|
2697
|
+
left: positions.left + (container.width || 0) / 2 - (popupRect?.width || 0) / 2
|
|
2701
2698
|
});
|
|
2702
2699
|
break;
|
|
2703
2700
|
case "bottomLeft":
|
|
@@ -2709,41 +2706,35 @@ const usePopupPosition = ({
|
|
|
2709
2706
|
case "bottomRight":
|
|
2710
2707
|
setPopupPosition({
|
|
2711
2708
|
top: positions.top + container.height,
|
|
2712
|
-
left: positions.left + (container.width || 0) - (
|
|
2709
|
+
left: positions.left + (container.width || 0) - (popupRect?.width || 0)
|
|
2713
2710
|
});
|
|
2714
2711
|
break;
|
|
2715
2712
|
case "top":
|
|
2716
2713
|
setPopupPosition({
|
|
2717
|
-
top: positions.top - (
|
|
2718
|
-
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
|
|
2719
2716
|
});
|
|
2720
2717
|
break;
|
|
2721
2718
|
case "topLeft":
|
|
2722
2719
|
setPopupPosition({
|
|
2723
|
-
top: positions.top - (
|
|
2720
|
+
top: positions.top - (popupRect?.height || 0) - OFFSET * 2,
|
|
2724
2721
|
left: positions.left
|
|
2725
2722
|
});
|
|
2726
2723
|
break;
|
|
2727
2724
|
case "topRight":
|
|
2728
2725
|
setPopupPosition({
|
|
2729
|
-
top: positions.top - (
|
|
2730
|
-
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)
|
|
2731
2728
|
});
|
|
2732
2729
|
break;
|
|
2733
2730
|
}
|
|
2734
2731
|
};
|
|
2735
2732
|
_calculation();
|
|
2736
|
-
}, [targetRef, popupContainer,
|
|
2733
|
+
}, [targetRef, popupContainer, popupRect, inBody, _placement, setOpen]);
|
|
2737
2734
|
useEffect(() => {
|
|
2738
2735
|
if (!open) {
|
|
2739
2736
|
return;
|
|
2740
2737
|
}
|
|
2741
|
-
// const setPositionRelative = (position: string) => {
|
|
2742
|
-
// (scrollableParents as HTMLDivElement).style.position = position;
|
|
2743
|
-
// if (popupContainer) {
|
|
2744
|
-
// (popupContainer as HTMLDivElement).style.position = position;
|
|
2745
|
-
// }
|
|
2746
|
-
// }
|
|
2747
2738
|
const controller = new AbortController();
|
|
2748
2739
|
const options = {
|
|
2749
2740
|
passive: true,
|
|
@@ -2753,22 +2744,20 @@ const usePopupPosition = ({
|
|
|
2753
2744
|
scrollableParents
|
|
2754
2745
|
} = getElementParentDetails(targetRef.current, true);
|
|
2755
2746
|
scrollableParents?.addEventListener("scroll", calculatePosition, options);
|
|
2756
|
-
// setPositionRelative('relative');
|
|
2757
2747
|
calculatePosition();
|
|
2758
2748
|
document.body.addEventListener("scroll", calculatePosition, options);
|
|
2759
2749
|
document.body.addEventListener("resize", calculatePosition, options);
|
|
2760
2750
|
return () => {
|
|
2761
2751
|
controller.abort();
|
|
2762
2752
|
setPopupPosition({});
|
|
2763
|
-
// setPositionRelative('unset');
|
|
2764
2753
|
};
|
|
2765
|
-
}, [open, targetRef,
|
|
2754
|
+
}, [open, targetRef, calculatePosition]);
|
|
2766
2755
|
return {
|
|
2767
2756
|
_placement,
|
|
2768
2757
|
popupStyle: {
|
|
2769
2758
|
zIndex: 10000,
|
|
2770
2759
|
position: "absolute",
|
|
2771
|
-
opacity: Object.keys(popupPosition).length ? 1 : 0,
|
|
2760
|
+
opacity: Object.keys(popupPosition).length && popupRect?.width ? 1 : 0,
|
|
2772
2761
|
...popupPosition
|
|
2773
2762
|
}
|
|
2774
2763
|
};
|
|
@@ -5581,7 +5570,7 @@ function MenuInner({
|
|
|
5581
5570
|
className: `${prefixCls}-menu`,
|
|
5582
5571
|
ref: menuRef,
|
|
5583
5572
|
role: "menu"
|
|
5584
|
-
}, items
|
|
5573
|
+
}, items?.map(it => /*#__PURE__*/React.createElement("li", {
|
|
5585
5574
|
key: it.key,
|
|
5586
5575
|
role: "menuitem",
|
|
5587
5576
|
tabIndex: it.disabled ? -1 : 0,
|