x-ui-design 0.9.66 → 0.9.67

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, overlayPopupStyle, onVisibleChange, getPopupContainer }: PopoverProps) => React.JSX.Element;
4
+ declare const Popover: ({ prefixCls, content, children, trigger, placement, open, visible, title, style, overlayClassName, overlayStyle, listenPopoverPositions, onVisibleChange, getPopupContainer }: PopoverProps) => React.JSX.Element;
5
5
  export default Popover;
@@ -8,9 +8,9 @@ type TPopupPosition = {
8
8
  placement?: Placement;
9
9
  popupContainer?: HTMLElement | null;
10
10
  useTargetWidth?: boolean;
11
- overlayPopupStyle?: CSSProperties;
11
+ listenPopoverPositions?: CSSProperties;
12
12
  };
13
- export declare const usePopupPosition: ({ open, setOpen, popupRef, targetRef, placement, popupContainer, useTargetWidth, overlayPopupStyle }: TPopupPosition) => {
13
+ export declare const usePopupPosition: ({ open, setOpen, popupRef, targetRef, placement, popupContainer, useTargetWidth, listenPopoverPositions }: TPopupPosition) => {
14
14
  _placement: Placement;
15
15
  popupStyle: CSSProperties;
16
16
  };
@@ -8,10 +8,9 @@ export type PopoverProps = DefaultProps & {
8
8
  open?: boolean;
9
9
  overlayStyle?: CSSProperties;
10
10
  overlayClassName?: string;
11
- overlayPopupStyle?: CSSProperties;
11
+ listenPopoverPositions?: CSSProperties;
12
12
  title?: string | ReactNode;
13
13
  visible?: boolean;
14
- listenPopoverPositions?: CSSProperties;
15
14
  placementPositionOffset?: number;
16
15
  onVisibleChange?: ((open: boolean) => void) | undefined;
17
16
  getPopupContainer?: ((node: HTMLElement) => HTMLElement) | undefined;
package/dist/index.esm.js CHANGED
@@ -2628,7 +2628,7 @@ const usePopupPosition = ({
2628
2628
  placement,
2629
2629
  popupContainer,
2630
2630
  useTargetWidth,
2631
- overlayPopupStyle = {}
2631
+ listenPopoverPositions
2632
2632
  }) => {
2633
2633
  const [_placement, _setPlacement] = useState(placement ?? "bottomLeft");
2634
2634
  const [popupPosition, setPopupPosition] = useState({});
@@ -2721,69 +2721,65 @@ const usePopupPosition = ({
2721
2721
  });
2722
2722
  }
2723
2723
  });
2724
- if (Object.keys(overlayPopupStyle).length) {
2725
- setPopupPosition(overlayPopupStyle);
2726
- } else {
2727
- promisePopupPlacment.then(({
2728
- container,
2729
- positions,
2730
- newPlacement
2731
- }) => {
2732
- const _calculation = () => {
2733
- switch (newPlacement) {
2734
- case "bottom":
2735
- setPopupPosition({
2736
- top: positions.top + container.height,
2737
- left: positions.left + (container.width || 0) / 2 - (popupRef.current?.offsetWidth || 0) / 2
2738
- });
2739
- break;
2740
- case "bottomLeft":
2741
- setPopupPosition({
2742
- top: positions.top + container.height,
2743
- left: positions.left
2744
- });
2745
- break;
2746
- case "bottomRight":
2747
- setPopupPosition({
2748
- top: positions.top + container.height,
2749
- left: positions.left + (container.width || 0) - (popupRef.current?.offsetWidth || 0)
2750
- });
2751
- break;
2752
- case "top":
2753
- setPopupPosition({
2754
- top: positions.top - (popupRef.current?.clientHeight || 0) - OFFSET * 2,
2755
- left: positions.left + (container.width || 0) / 2 - (popupRef.current?.offsetWidth || 0) / 2
2756
- });
2757
- break;
2758
- case "topLeft":
2759
- setPopupPosition({
2760
- top: positions.top - (popupRef.current?.clientHeight || 0) - OFFSET * 2,
2761
- left: positions.left
2762
- });
2763
- break;
2764
- case "topRight":
2765
- setPopupPosition({
2766
- top: positions.top - (popupRef.current?.clientHeight || 0) - OFFSET * 2,
2767
- left: positions.left + (container.width || 0) - (popupRef.current?.offsetWidth || 0)
2768
- });
2769
- break;
2770
- case "left":
2771
- setPopupPosition({
2772
- top: positions.top - OFFSET,
2773
- left: positions.left - (popupRef.current?.offsetWidth || 0) - OFFSET
2774
- });
2775
- break;
2776
- case "right":
2777
- setPopupPosition({
2778
- top: positions.top - OFFSET,
2779
- left: positions.left + container.width + OFFSET
2780
- });
2781
- break;
2782
- }
2783
- };
2784
- _calculation();
2785
- });
2786
- }
2724
+ promisePopupPlacment.then(({
2725
+ container,
2726
+ positions,
2727
+ newPlacement
2728
+ }) => {
2729
+ const _calculation = () => {
2730
+ switch (newPlacement) {
2731
+ case "bottom":
2732
+ setPopupPosition({
2733
+ top: positions.top + container.height,
2734
+ left: positions.left + (container.width || 0) / 2 - (popupRef.current?.offsetWidth || 0) / 2
2735
+ });
2736
+ break;
2737
+ case "bottomLeft":
2738
+ setPopupPosition({
2739
+ top: positions.top + container.height,
2740
+ left: positions.left
2741
+ });
2742
+ break;
2743
+ case "bottomRight":
2744
+ setPopupPosition({
2745
+ top: positions.top + container.height,
2746
+ left: positions.left + (container.width || 0) - (popupRef.current?.offsetWidth || 0)
2747
+ });
2748
+ break;
2749
+ case "top":
2750
+ setPopupPosition({
2751
+ top: positions.top - (popupRef.current?.clientHeight || 0) - OFFSET * 2,
2752
+ left: positions.left + (container.width || 0) / 2 - (popupRef.current?.offsetWidth || 0) / 2
2753
+ });
2754
+ break;
2755
+ case "topLeft":
2756
+ setPopupPosition({
2757
+ top: positions.top - (popupRef.current?.clientHeight || 0) - OFFSET * 2,
2758
+ left: positions.left
2759
+ });
2760
+ break;
2761
+ case "topRight":
2762
+ setPopupPosition({
2763
+ top: positions.top - (popupRef.current?.clientHeight || 0) - OFFSET * 2,
2764
+ left: positions.left + (container.width || 0) - (popupRef.current?.offsetWidth || 0)
2765
+ });
2766
+ break;
2767
+ case "left":
2768
+ setPopupPosition({
2769
+ top: positions.top - OFFSET,
2770
+ left: positions.left - (popupRef.current?.offsetWidth || 0) - OFFSET
2771
+ });
2772
+ break;
2773
+ case "right":
2774
+ setPopupPosition({
2775
+ top: positions.top - OFFSET,
2776
+ left: positions.left + container.width + OFFSET
2777
+ });
2778
+ break;
2779
+ }
2780
+ };
2781
+ _calculation();
2782
+ });
2787
2783
  }, [targetRef, popupContainer, popupRef, useTargetWidth, inBody, _placement, setOpen]);
2788
2784
  useEffect(() => {
2789
2785
  if (!open) {
@@ -2805,7 +2801,7 @@ const usePopupPosition = ({
2805
2801
  controller.abort();
2806
2802
  setPopupPosition({});
2807
2803
  };
2808
- }, [open, targetRef, calculatePosition]);
2804
+ }, [open, targetRef, listenPopoverPositions, calculatePosition]);
2809
2805
  return {
2810
2806
  _placement,
2811
2807
  popupStyle: {
@@ -5675,7 +5671,7 @@ const Popover = ({
5675
5671
  style = {},
5676
5672
  overlayClassName = '',
5677
5673
  overlayStyle = {},
5678
- overlayPopupStyle = {},
5674
+ listenPopoverPositions,
5679
5675
  onVisibleChange,
5680
5676
  getPopupContainer
5681
5677
  }) => {
@@ -5692,7 +5688,7 @@ const Popover = ({
5692
5688
  placement,
5693
5689
  open: isOpen,
5694
5690
  setOpen: setInnerOpen,
5695
- overlayPopupStyle,
5691
+ listenPopoverPositions,
5696
5692
  popupContainer: getPopupContainer?.(targetRef.current)
5697
5693
  });
5698
5694
  useEffect(() => {