x-ui-design 0.9.14 → 0.9.16

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 CHANGED
@@ -2653,49 +2653,34 @@ const usePopupPosition = ({
2653
2653
  top: (relativePosition.top || 0) + (targetRef.current?.offsetTop || 0) - (scrollableParents?.offsetTop || 0) + OFFSET,
2654
2654
  left: relativePosition.left + (targetRef.current?.offsetLeft || 0) - (targetRef.current?.clientWidth || 0) / 2
2655
2655
  };
2656
- if (e?.target === scrollableParents && inBody) {
2657
- setOpen(false);
2658
- setPopupPosition({});
2659
- return;
2660
- }
2661
- if (popupRef.current) {
2656
+ if (!inBody && popupRef.current) {
2662
2657
  const popupRect = popupRef.current.getBoundingClientRect();
2663
2658
  const availableSpace = {
2664
2659
  top: container.top - (popupRect.height + OFFSET),
2665
- bottom: (inBody ? window.innerHeight : scrollableParents?.clientHeight || 0) - (container.bottom + popupRect.height + OFFSET),
2660
+ bottom: (scrollableParents?.clientHeight || 0) - (container.bottom + popupRect.height + OFFSET),
2666
2661
  left: container.left - (popupRect.width + OFFSET),
2667
- right: (inBody ? window.innerWidth : scrollableParents?.clientWidth || 0) - (container.right + popupRect.width + OFFSET)
2662
+ right: (scrollableParents?.clientWidth || 0) - (container.right + popupRect.width + OFFSET)
2668
2663
  };
2669
2664
  let newPlacement = _placement;
2670
2665
  if (availableSpace.bottom < 0 && availableSpace.top > 0) {
2671
- console.info(0);
2672
2666
  newPlacement = newPlacement.replace('bottom', 'top');
2673
2667
  }
2674
2668
  if (availableSpace.top < 0 && availableSpace.bottom > 0) {
2675
- console.info(1);
2676
2669
  newPlacement = newPlacement.replace('top', 'bottom');
2677
2670
  }
2678
- if (availableSpace.left < 0 && (availableSpace.right > 0 || availableSpace.right < popupRect.width)) {
2679
- console.info(2);
2671
+ if (availableSpace.left < 0 && availableSpace.right > 0) {
2680
2672
  newPlacement = newPlacement.replace('Right', 'Left');
2681
2673
  }
2682
- if (availableSpace.right < 0 && (availableSpace.left > 0 || availableSpace.left < popupRect.width)) {
2683
- console.info(3);
2674
+ if (availableSpace.right < 0 && availableSpace.left > 0) {
2684
2675
  newPlacement = newPlacement.replace('Left', 'Right');
2685
2676
  }
2686
- if (availableSpace.right < 0 && availableSpace.left < 0) {
2687
- console.info(4);
2688
- if (newPlacement.includes('Right')) {
2689
- console.info(5);
2690
- positions.left = popupRef.current.clientWidth - positions.left + container.left;
2691
- }
2692
- if (newPlacement.includes('Left')) {
2693
- console.info(6);
2694
- positions.left = positions.left - popupRef.current.clientWidth + container.width;
2695
- }
2696
- }
2697
2677
  _setPlacement(newPlacement);
2698
2678
  }
2679
+ if (e?.target === scrollableParents && inBody) {
2680
+ setOpen(false);
2681
+ setPopupPosition({});
2682
+ return;
2683
+ }
2699
2684
  const _calculation = () => {
2700
2685
  switch (_placement) {
2701
2686
  case "bottom":
@@ -2763,7 +2748,6 @@ const usePopupPosition = ({
2763
2748
  document.body.addEventListener("resize", calculatePosition, options);
2764
2749
  return () => {
2765
2750
  controller.abort();
2766
- setPopupPosition({});
2767
2751
  // setPositionRelative('unset');
2768
2752
  };
2769
2753
  }, [open, targetRef, popupContainer, inBody, calculatePosition]);