x-ui-design 0.9.22 → 0.9.24
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 -11
- package/dist/index.esm.js.map +1 -1
- package/dist/index.js +14 -11
- package/dist/index.js.map +1 -1
- package/lib/hooks/usePopupPosition.ts +16 -11
- package/package.json +1 -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 = 12;
|
|
2622
2622
|
const usePopupPosition = ({
|
|
2623
2623
|
open,
|
|
2624
2624
|
setOpen,
|
|
@@ -2630,7 +2630,6 @@ 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]);
|
|
2634
2633
|
const calculatePosition = useCallback(e => {
|
|
2635
2634
|
const container = targetRef.current?.getBoundingClientRect();
|
|
2636
2635
|
if (!container) {
|
|
@@ -2659,6 +2658,7 @@ const usePopupPosition = ({
|
|
|
2659
2658
|
setPopupPosition({});
|
|
2660
2659
|
return;
|
|
2661
2660
|
}
|
|
2661
|
+
const popupRect = popupRef.current?.getBoundingClientRect();
|
|
2662
2662
|
if (popupRect) {
|
|
2663
2663
|
const availableSpace = {
|
|
2664
2664
|
top: container.top - (popupRect.height + OFFSET),
|
|
@@ -2690,11 +2690,14 @@ const usePopupPosition = ({
|
|
|
2690
2690
|
_setPlacement(newPlacement);
|
|
2691
2691
|
}
|
|
2692
2692
|
const _calculation = () => {
|
|
2693
|
+
if (!popupRect?.width) {
|
|
2694
|
+
return;
|
|
2695
|
+
}
|
|
2693
2696
|
switch (_placement) {
|
|
2694
2697
|
case "bottom":
|
|
2695
2698
|
setPopupPosition({
|
|
2696
2699
|
top: positions.top + container.height,
|
|
2697
|
-
left: positions.left + (container.width || 0) / 2 - (
|
|
2700
|
+
left: positions.left + (container.width || 0) / 2 - (popupRef.current?.offsetWidth || 0) / 2
|
|
2698
2701
|
});
|
|
2699
2702
|
break;
|
|
2700
2703
|
case "bottomLeft":
|
|
@@ -2706,31 +2709,31 @@ const usePopupPosition = ({
|
|
|
2706
2709
|
case "bottomRight":
|
|
2707
2710
|
setPopupPosition({
|
|
2708
2711
|
top: positions.top + container.height,
|
|
2709
|
-
left: positions.left + (container.width || 0) - (
|
|
2712
|
+
left: positions.left + (container.width || 0) - (popupRef.current?.offsetWidth || 0)
|
|
2710
2713
|
});
|
|
2711
2714
|
break;
|
|
2712
2715
|
case "top":
|
|
2713
2716
|
setPopupPosition({
|
|
2714
|
-
top: positions.top - (
|
|
2715
|
-
left: positions.left + (container.width || 0) / 2 - (
|
|
2717
|
+
top: positions.top - (popupRef.current?.clientHeight || 0) - OFFSET * 2,
|
|
2718
|
+
left: positions.left + (container.width || 0) / 2 - (popupRef.current?.offsetWidth || 0) / 2
|
|
2716
2719
|
});
|
|
2717
2720
|
break;
|
|
2718
2721
|
case "topLeft":
|
|
2719
2722
|
setPopupPosition({
|
|
2720
|
-
top: positions.top - (
|
|
2723
|
+
top: positions.top - (popupRef.current?.clientHeight || 0) - OFFSET * 2,
|
|
2721
2724
|
left: positions.left
|
|
2722
2725
|
});
|
|
2723
2726
|
break;
|
|
2724
2727
|
case "topRight":
|
|
2725
2728
|
setPopupPosition({
|
|
2726
|
-
top: positions.top - (
|
|
2727
|
-
left: positions.left + (container.width || 0) - (
|
|
2729
|
+
top: positions.top - (popupRef.current?.clientHeight || 0) - OFFSET * 2,
|
|
2730
|
+
left: positions.left + (container.width || 0) - (popupRef.current?.offsetWidth || 0)
|
|
2728
2731
|
});
|
|
2729
2732
|
break;
|
|
2730
2733
|
}
|
|
2731
2734
|
};
|
|
2732
2735
|
_calculation();
|
|
2733
|
-
}, [targetRef, popupContainer,
|
|
2736
|
+
}, [targetRef, popupContainer, popupRef, inBody, _placement, setOpen]);
|
|
2734
2737
|
useEffect(() => {
|
|
2735
2738
|
if (!open) {
|
|
2736
2739
|
return;
|
|
@@ -2757,7 +2760,7 @@ const usePopupPosition = ({
|
|
|
2757
2760
|
popupStyle: {
|
|
2758
2761
|
zIndex: 10000,
|
|
2759
2762
|
position: "absolute",
|
|
2760
|
-
opacity: Object.keys(popupPosition).length
|
|
2763
|
+
opacity: Object.keys(popupPosition).length ? 1 : 0,
|
|
2761
2764
|
...popupPosition
|
|
2762
2765
|
}
|
|
2763
2766
|
};
|