x-ui-design 0.8.37 → 0.8.38

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.
@@ -1,5 +1,5 @@
1
1
  import React from "react";
2
2
  import { PopoverProps } from "../../types/popover";
3
3
  import './style.css';
4
- declare const Popover: ({ prefixCls, content, children, trigger, placement, open, visible, title, style, overlayClassName, overlayStyle, onVisibleChange, getPopupContainer, stopDropdownPosition }: PopoverProps) => React.JSX.Element;
4
+ declare const Popover: ({ prefixCls, content, children, trigger, placement, open, visible, title, style, overlayClassName, overlayStyle, onVisibleChange, getPopupContainer, controlDropdownPosition }: PopoverProps) => React.JSX.Element;
5
5
  export default Popover;
@@ -7,8 +7,9 @@ type TPosition = {
7
7
  getPopupContainer?: HTMLElement;
8
8
  placement?: Placement;
9
9
  offset?: number;
10
+ controlDropdownPosition?: CSSProperties;
10
11
  };
11
- export declare const usePosition: ({ isOpen, offset, popupRef, placement, triggerRef, getPopupContainer }: TPosition) => {
12
+ export declare const usePosition: ({ isOpen, offset, popupRef, placement, triggerRef, getPopupContainer, controlDropdownPosition }: TPosition) => {
12
13
  showPlacement: string;
13
14
  dropdownPosition: CSSProperties;
14
15
  };
@@ -10,7 +10,7 @@ export type PopoverProps = DefaultProps & {
10
10
  overlayClassName?: string;
11
11
  title?: string | ReactNode;
12
12
  visible?: boolean;
13
- stopDropdownPosition?: boolean;
13
+ controlDropdownPosition?: CSSProperties;
14
14
  onVisibleChange?: ((open: boolean) => void) | undefined;
15
15
  getPopupContainer?: ((node: HTMLElement) => HTMLElement) | undefined;
16
16
  };
package/dist/index.esm.js CHANGED
@@ -2609,75 +2609,75 @@ const usePosition = ({
2609
2609
  popupRef,
2610
2610
  placement,
2611
2611
  triggerRef,
2612
- getPopupContainer
2612
+ getPopupContainer,
2613
+ controlDropdownPosition
2613
2614
  }) => {
2614
2615
  const [showPlacement, setShowPlacement] = useState('');
2615
2616
  const [_dropdownPosition, setDropdownPosition] = useState({});
2616
2617
  const dropdownPosition = useCallback(() => {
2617
- console.log({
2618
- getPopupContainer,
2619
- popupRef: popupRef.current,
2620
- triggerRef: triggerRef.current
2621
- });
2622
2618
  if (!triggerRef.current) {
2623
2619
  return {};
2624
2620
  }
2625
- const inputRect = triggerRef.current?.getBoundingClientRect();
2626
- const dropdownHeight = popupRef.current?.offsetHeight || popupRef.current?.offsetHeight || 0;
2627
- const containerRect = (getPopupContainer || getScrollParent(triggerRef.current, true) || document.body).getBoundingClientRect();
2628
- const spaceAbove = inputRect.top - containerRect.top;
2629
- const spaceBelow = containerRect.bottom - inputRect.bottom;
2630
- const _shouldShowAbove = spaceBelow < dropdownHeight && spaceAbove > dropdownHeight;
2631
- const hasRight = placement?.includes('Right');
2632
- if (getPopupContainer) {
2633
- const {
2634
- minLeft,
2635
- maxLeft,
2636
- leftPosition
2637
- } = clampWithinContainer(hasRight ? (inputRect.left || 0) + (triggerRef.current?.offsetWidth || 0) - (popupRef.current?.offsetWidth || 0) : (inputRect.left || 0) + document.documentElement.scrollLeft, popupRef.current?.offsetWidth || 0, containerRect);
2638
- const _center = minLeft + maxLeft < (popupRef.current?.offsetWidth || 0) ? 'center' : '';
2639
- setShowPlacement(_shouldShowAbove ? `bottom ${_center}` : `${_center}`);
2640
- const _top = (inputRect.top || 0) + document.documentElement.scrollTop;
2641
- if (_shouldShowAbove) {
2642
- setDropdownPosition({
2643
- top: _top - (popupRef.current?.offsetHeight || 0) + 4 - (offset !== 4 ? offset * 2 : 0),
2644
- left: leftPosition
2645
- });
2621
+ if (controlDropdownPosition) {
2622
+ setDropdownPosition(controlDropdownPosition);
2623
+ } else {
2624
+ const inputRect = triggerRef.current?.getBoundingClientRect();
2625
+ const dropdownHeight = popupRef.current?.offsetHeight || popupRef.current?.offsetHeight || 0;
2626
+ const containerRect = (getPopupContainer || getScrollParent(triggerRef.current, true) || document.body).getBoundingClientRect();
2627
+ const spaceAbove = inputRect.top - containerRect.top;
2628
+ const spaceBelow = containerRect.bottom - inputRect.bottom;
2629
+ const _shouldShowAbove = spaceBelow < dropdownHeight && spaceAbove > dropdownHeight;
2630
+ const hasRight = placement?.includes('Right');
2631
+ if (getPopupContainer) {
2632
+ const {
2633
+ minLeft,
2634
+ maxLeft,
2635
+ leftPosition
2636
+ } = clampWithinContainer(hasRight ? (inputRect.left || 0) + (triggerRef.current?.offsetWidth || 0) - (popupRef.current?.offsetWidth || 0) : (inputRect.left || 0) + document.documentElement.scrollLeft, popupRef.current?.offsetWidth || 0, containerRect);
2637
+ const _center = minLeft + maxLeft < (popupRef.current?.offsetWidth || 0) ? 'center' : '';
2638
+ setShowPlacement(_shouldShowAbove ? `bottom ${_center}` : `${_center}`);
2639
+ const _top = (inputRect.top || 0) + document.documentElement.scrollTop;
2640
+ if (_shouldShowAbove) {
2641
+ setDropdownPosition({
2642
+ top: _top - (popupRef.current?.offsetHeight || 0) + 4 - (offset !== 4 ? offset * 2 : 0),
2643
+ left: leftPosition
2644
+ });
2645
+ } else {
2646
+ setDropdownPosition({
2647
+ top: _top + (triggerRef.current?.offsetHeight || 0) + offset,
2648
+ left: leftPosition
2649
+ });
2650
+ }
2646
2651
  } else {
2647
2652
  setDropdownPosition({
2648
- top: _top + (triggerRef.current?.offsetHeight || 0) + offset,
2649
- left: leftPosition
2653
+ top: (_shouldShowAbove ? triggerRef.current.offsetTop - (popupRef.current?.offsetHeight || dropdownHeight) - offset * 2 : triggerRef.current.offsetTop + triggerRef.current?.offsetHeight) + offset,
2654
+ ...(hasRight ? {
2655
+ left: (() => {
2656
+ const {
2657
+ minLeft,
2658
+ maxLeft,
2659
+ leftPosition
2660
+ } = clampWithinContainer(triggerRef.current.offsetLeft + (triggerRef.current?.offsetWidth || 0) - (popupRef.current?.offsetWidth || dropdownHeight), popupRef.current?.offsetWidth || dropdownHeight, containerRect);
2661
+ const _center = minLeft + maxLeft < (popupRef.current?.offsetWidth || 0) ? 'center' : '';
2662
+ setShowPlacement(_shouldShowAbove ? `bottom ${_center}` : `${_center}`);
2663
+ return leftPosition;
2664
+ })()
2665
+ } : {
2666
+ left: (() => {
2667
+ const {
2668
+ minLeft,
2669
+ maxLeft,
2670
+ leftPosition
2671
+ } = clampWithinContainer(triggerRef.current.offsetLeft, popupRef.current?.offsetWidth || dropdownHeight, containerRect);
2672
+ const _center = minLeft + maxLeft < (popupRef.current?.offsetWidth || 0) ? 'center' : '';
2673
+ setShowPlacement(_shouldShowAbove ? `bottom ${_center}` : `${_center}`);
2674
+ return leftPosition;
2675
+ })()
2676
+ })
2650
2677
  });
2651
2678
  }
2652
- } else {
2653
- setDropdownPosition({
2654
- top: (_shouldShowAbove ? triggerRef.current.offsetTop - (popupRef.current?.offsetHeight || dropdownHeight) - offset * 2 : triggerRef.current.offsetTop + triggerRef.current?.offsetHeight) + offset,
2655
- ...(hasRight ? {
2656
- left: (() => {
2657
- const {
2658
- minLeft,
2659
- maxLeft,
2660
- leftPosition
2661
- } = clampWithinContainer(triggerRef.current.offsetLeft + (triggerRef.current?.offsetWidth || 0) - (popupRef.current?.offsetWidth || dropdownHeight), popupRef.current?.offsetWidth || dropdownHeight, containerRect);
2662
- const _center = minLeft + maxLeft < (popupRef.current?.offsetWidth || 0) ? 'center' : '';
2663
- setShowPlacement(_shouldShowAbove ? `bottom ${_center}` : `${_center}`);
2664
- return leftPosition;
2665
- })()
2666
- } : {
2667
- left: (() => {
2668
- const {
2669
- minLeft,
2670
- maxLeft,
2671
- leftPosition
2672
- } = clampWithinContainer(triggerRef.current.offsetLeft, popupRef.current?.offsetWidth || dropdownHeight, containerRect);
2673
- const _center = minLeft + maxLeft < (popupRef.current?.offsetWidth || 0) ? 'center' : '';
2674
- setShowPlacement(_shouldShowAbove ? `bottom ${_center}` : `${_center}`);
2675
- return leftPosition;
2676
- })()
2677
- })
2678
- });
2679
2679
  }
2680
- }, [offset, popupRef, placement, triggerRef, getPopupContainer]);
2680
+ }, [offset, popupRef, placement, triggerRef, getPopupContainer, controlDropdownPosition]);
2681
2681
  useEffect(() => {
2682
2682
  if (!isOpen) return;
2683
2683
  const _dropdownPosition = () => dropdownPosition();
@@ -5551,7 +5551,7 @@ const Popover = ({
5551
5551
  overlayStyle = {},
5552
5552
  onVisibleChange,
5553
5553
  getPopupContainer,
5554
- stopDropdownPosition = false
5554
+ controlDropdownPosition
5555
5555
  }) => {
5556
5556
  const triggerRef = useRef(null);
5557
5557
  const popupRef = useRef(null);
@@ -5566,6 +5566,7 @@ const Popover = ({
5566
5566
  popupRef,
5567
5567
  placement,
5568
5568
  triggerRef,
5569
+ controlDropdownPosition,
5569
5570
  getPopupContainer: getPopupContainer?.(triggerRef.current)
5570
5571
  });
5571
5572
  useEffect(() => {
@@ -5633,7 +5634,7 @@ const Popover = ({
5633
5634
  zIndex: 1000,
5634
5635
  position: "absolute",
5635
5636
  ...overlayStyle,
5636
- ...(!stopDropdownPosition ? dropdownPosition : {})
5637
+ ...dropdownPosition
5637
5638
  }
5638
5639
  }), title && /*#__PURE__*/React.createElement("div", {
5639
5640
  className: `${prefixCls}-title`