x-ui-design 0.9.16 → 0.9.18
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 +30 -8
- package/dist/index.esm.js.map +1 -1
- package/dist/index.js +30 -8
- package/dist/index.js.map +1 -1
- package/lib/hooks/usePopupPosition.ts +36 -9
- package/package.json +2 -3
- package/src/app/page.tsx +12 -10
package/dist/index.esm.js
CHANGED
|
@@ -2640,6 +2640,15 @@ const usePopupPosition = ({
|
|
|
2640
2640
|
relativePosition
|
|
2641
2641
|
} = getElementParentDetails(targetRef.current, true);
|
|
2642
2642
|
const _containsElement = scrollableParents?.contains(popupContainer) && popupContainer !== scrollableParents;
|
|
2643
|
+
console.info({
|
|
2644
|
+
container,
|
|
2645
|
+
scrollableParents,
|
|
2646
|
+
relativePosition,
|
|
2647
|
+
positions: !popupContainer,
|
|
2648
|
+
_containsElement,
|
|
2649
|
+
inBody,
|
|
2650
|
+
popupRef
|
|
2651
|
+
});
|
|
2643
2652
|
const positions = !popupContainer ? {
|
|
2644
2653
|
top: (targetRef.current?.offsetTop || 0) + OFFSET,
|
|
2645
2654
|
left: targetRef.current?.offsetLeft || 0
|
|
@@ -2653,14 +2662,23 @@ const usePopupPosition = ({
|
|
|
2653
2662
|
top: (relativePosition.top || 0) + (targetRef.current?.offsetTop || 0) - (scrollableParents?.offsetTop || 0) + OFFSET,
|
|
2654
2663
|
left: relativePosition.left + (targetRef.current?.offsetLeft || 0) - (targetRef.current?.clientWidth || 0) / 2
|
|
2655
2664
|
};
|
|
2656
|
-
if (
|
|
2665
|
+
if (e?.target === scrollableParents && inBody) {
|
|
2666
|
+
setOpen(false);
|
|
2667
|
+
setPopupPosition({});
|
|
2668
|
+
return;
|
|
2669
|
+
}
|
|
2670
|
+
if (popupRef.current) {
|
|
2657
2671
|
const popupRect = popupRef.current.getBoundingClientRect();
|
|
2658
2672
|
const availableSpace = {
|
|
2659
2673
|
top: container.top - (popupRect.height + OFFSET),
|
|
2660
|
-
bottom: (scrollableParents?.clientHeight || 0) - (container.bottom + popupRect.height + OFFSET),
|
|
2674
|
+
bottom: (inBody ? window.innerHeight : scrollableParents?.clientHeight || 0) - (container.bottom + popupRect.height + OFFSET),
|
|
2661
2675
|
left: container.left - (popupRect.width + OFFSET),
|
|
2662
|
-
right: (scrollableParents?.clientWidth || 0) - (container.right + popupRect.width + OFFSET)
|
|
2676
|
+
right: (inBody ? window.innerWidth : scrollableParents?.clientWidth || 0) - (container.right + popupRect.width + OFFSET)
|
|
2663
2677
|
};
|
|
2678
|
+
console.info({
|
|
2679
|
+
popupRect,
|
|
2680
|
+
availableSpace
|
|
2681
|
+
});
|
|
2664
2682
|
let newPlacement = _placement;
|
|
2665
2683
|
if (availableSpace.bottom < 0 && availableSpace.top > 0) {
|
|
2666
2684
|
newPlacement = newPlacement.replace('bottom', 'top');
|
|
@@ -2674,13 +2692,16 @@ const usePopupPosition = ({
|
|
|
2674
2692
|
if (availableSpace.right < 0 && availableSpace.left > 0) {
|
|
2675
2693
|
newPlacement = newPlacement.replace('Left', 'Right');
|
|
2676
2694
|
}
|
|
2695
|
+
if (availableSpace.right < 0 && availableSpace.left < 0) {
|
|
2696
|
+
if (newPlacement.includes('Right')) {
|
|
2697
|
+
positions.left = popupRef.current.clientWidth - positions.left + container.left;
|
|
2698
|
+
}
|
|
2699
|
+
if (newPlacement.includes('Left')) {
|
|
2700
|
+
positions.left = positions.left - popupRef.current.clientWidth + container.width;
|
|
2701
|
+
}
|
|
2702
|
+
}
|
|
2677
2703
|
_setPlacement(newPlacement);
|
|
2678
2704
|
}
|
|
2679
|
-
if (e?.target === scrollableParents && inBody) {
|
|
2680
|
-
setOpen(false);
|
|
2681
|
-
setPopupPosition({});
|
|
2682
|
-
return;
|
|
2683
|
-
}
|
|
2684
2705
|
const _calculation = () => {
|
|
2685
2706
|
switch (_placement) {
|
|
2686
2707
|
case "bottom":
|
|
@@ -2748,6 +2769,7 @@ const usePopupPosition = ({
|
|
|
2748
2769
|
document.body.addEventListener("resize", calculatePosition, options);
|
|
2749
2770
|
return () => {
|
|
2750
2771
|
controller.abort();
|
|
2772
|
+
setPopupPosition({});
|
|
2751
2773
|
// setPositionRelative('unset');
|
|
2752
2774
|
};
|
|
2753
2775
|
}, [open, targetRef, popupContainer, inBody, calculatePosition]);
|