x-ui-design 0.9.66 → 0.9.68
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/esm/types/components/Popover/Popover.d.ts +1 -1
- package/dist/esm/types/hooks/usePopupPosition.d.ts +1 -2
- package/dist/esm/types/types/popover.d.ts +0 -2
- package/dist/index.esm.js +61 -69
- package/dist/index.esm.js.map +1 -1
- package/dist/index.js +61 -69
- package/dist/index.js.map +1 -1
- package/lib/components/Popover/Popover.tsx +0 -2
- package/lib/hooks/usePopupPosition.ts +60 -67
- package/lib/types/popover.ts +0 -2
- package/package.json +1 -1
- package/src/app/page.tsx +8 -193
|
@@ -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,
|
|
4
|
+
declare const Popover: ({ prefixCls, content, children, trigger, placement, open, visible, title, style, overlayClassName, overlayStyle, onVisibleChange, getPopupContainer }: PopoverProps) => React.JSX.Element;
|
|
5
5
|
export default Popover;
|
|
@@ -8,9 +8,8 @@ type TPopupPosition = {
|
|
|
8
8
|
placement?: Placement;
|
|
9
9
|
popupContainer?: HTMLElement | null;
|
|
10
10
|
useTargetWidth?: boolean;
|
|
11
|
-
overlayPopupStyle?: CSSProperties;
|
|
12
11
|
};
|
|
13
|
-
export declare const usePopupPosition: ({ open, setOpen, popupRef, targetRef, placement, popupContainer, useTargetWidth,
|
|
12
|
+
export declare const usePopupPosition: ({ open, setOpen, popupRef, targetRef, placement, popupContainer, useTargetWidth, }: TPopupPosition) => {
|
|
14
13
|
_placement: Placement;
|
|
15
14
|
popupStyle: CSSProperties;
|
|
16
15
|
};
|
|
@@ -8,10 +8,8 @@ export type PopoverProps = DefaultProps & {
|
|
|
8
8
|
open?: boolean;
|
|
9
9
|
overlayStyle?: CSSProperties;
|
|
10
10
|
overlayClassName?: string;
|
|
11
|
-
overlayPopupStyle?: CSSProperties;
|
|
12
11
|
title?: string | ReactNode;
|
|
13
12
|
visible?: boolean;
|
|
14
|
-
listenPopoverPositions?: CSSProperties;
|
|
15
13
|
placementPositionOffset?: number;
|
|
16
14
|
onVisibleChange?: ((open: boolean) => void) | undefined;
|
|
17
15
|
getPopupContainer?: ((node: HTMLElement) => HTMLElement) | undefined;
|
package/dist/index.esm.js
CHANGED
|
@@ -2627,8 +2627,7 @@ const usePopupPosition = ({
|
|
|
2627
2627
|
targetRef,
|
|
2628
2628
|
placement,
|
|
2629
2629
|
popupContainer,
|
|
2630
|
-
useTargetWidth
|
|
2631
|
-
overlayPopupStyle = {}
|
|
2630
|
+
useTargetWidth
|
|
2632
2631
|
}) => {
|
|
2633
2632
|
const [_placement, _setPlacement] = useState(placement ?? "bottomLeft");
|
|
2634
2633
|
const [popupPosition, setPopupPosition] = useState({});
|
|
@@ -2664,7 +2663,7 @@ const usePopupPosition = ({
|
|
|
2664
2663
|
}
|
|
2665
2664
|
const popupRect = popupRef.current?.getBoundingClientRect();
|
|
2666
2665
|
if (popupRect) {
|
|
2667
|
-
if (popupRect?.width < OFFSET) {
|
|
2666
|
+
if (popupRect?.width < OFFSET || !targetRef.current) {
|
|
2668
2667
|
setOpen(false);
|
|
2669
2668
|
setPopupPosition({});
|
|
2670
2669
|
const timeout = setTimeout(() => {
|
|
@@ -2721,69 +2720,65 @@ const usePopupPosition = ({
|
|
|
2721
2720
|
});
|
|
2722
2721
|
}
|
|
2723
2722
|
});
|
|
2724
|
-
|
|
2725
|
-
|
|
2726
|
-
|
|
2727
|
-
|
|
2728
|
-
|
|
2729
|
-
|
|
2730
|
-
newPlacement
|
|
2731
|
-
|
|
2732
|
-
|
|
2733
|
-
|
|
2734
|
-
|
|
2735
|
-
|
|
2736
|
-
|
|
2737
|
-
|
|
2738
|
-
|
|
2739
|
-
|
|
2740
|
-
|
|
2741
|
-
|
|
2742
|
-
|
|
2743
|
-
|
|
2744
|
-
|
|
2745
|
-
|
|
2746
|
-
|
|
2747
|
-
|
|
2748
|
-
|
|
2749
|
-
|
|
2750
|
-
|
|
2751
|
-
|
|
2752
|
-
|
|
2753
|
-
|
|
2754
|
-
|
|
2755
|
-
|
|
2756
|
-
|
|
2757
|
-
|
|
2758
|
-
|
|
2759
|
-
|
|
2760
|
-
|
|
2761
|
-
|
|
2762
|
-
|
|
2763
|
-
|
|
2764
|
-
|
|
2765
|
-
|
|
2766
|
-
|
|
2767
|
-
|
|
2768
|
-
|
|
2769
|
-
|
|
2770
|
-
|
|
2771
|
-
|
|
2772
|
-
|
|
2773
|
-
|
|
2774
|
-
|
|
2775
|
-
|
|
2776
|
-
|
|
2777
|
-
|
|
2778
|
-
|
|
2779
|
-
|
|
2780
|
-
|
|
2781
|
-
|
|
2782
|
-
|
|
2783
|
-
};
|
|
2784
|
-
_calculation();
|
|
2785
|
-
});
|
|
2786
|
-
}
|
|
2723
|
+
promisePopupPlacment.then(({
|
|
2724
|
+
container,
|
|
2725
|
+
positions,
|
|
2726
|
+
newPlacement
|
|
2727
|
+
}) => {
|
|
2728
|
+
const _calculation = () => {
|
|
2729
|
+
switch (newPlacement) {
|
|
2730
|
+
case "bottom":
|
|
2731
|
+
setPopupPosition({
|
|
2732
|
+
top: positions.top + container.height,
|
|
2733
|
+
left: positions.left + (container.width || 0) / 2 - (popupRef.current?.offsetWidth || 0) / 2
|
|
2734
|
+
});
|
|
2735
|
+
break;
|
|
2736
|
+
case "bottomLeft":
|
|
2737
|
+
setPopupPosition({
|
|
2738
|
+
top: positions.top + container.height,
|
|
2739
|
+
left: positions.left
|
|
2740
|
+
});
|
|
2741
|
+
break;
|
|
2742
|
+
case "bottomRight":
|
|
2743
|
+
setPopupPosition({
|
|
2744
|
+
top: positions.top + container.height,
|
|
2745
|
+
left: positions.left + (container.width || 0) - (popupRef.current?.offsetWidth || 0)
|
|
2746
|
+
});
|
|
2747
|
+
break;
|
|
2748
|
+
case "top":
|
|
2749
|
+
setPopupPosition({
|
|
2750
|
+
top: positions.top - (popupRef.current?.clientHeight || 0) - OFFSET * 2,
|
|
2751
|
+
left: positions.left + (container.width || 0) / 2 - (popupRef.current?.offsetWidth || 0) / 2
|
|
2752
|
+
});
|
|
2753
|
+
break;
|
|
2754
|
+
case "topLeft":
|
|
2755
|
+
setPopupPosition({
|
|
2756
|
+
top: positions.top - (popupRef.current?.clientHeight || 0) - OFFSET * 2,
|
|
2757
|
+
left: positions.left
|
|
2758
|
+
});
|
|
2759
|
+
break;
|
|
2760
|
+
case "topRight":
|
|
2761
|
+
setPopupPosition({
|
|
2762
|
+
top: positions.top - (popupRef.current?.clientHeight || 0) - OFFSET * 2,
|
|
2763
|
+
left: positions.left + (container.width || 0) - (popupRef.current?.offsetWidth || 0)
|
|
2764
|
+
});
|
|
2765
|
+
break;
|
|
2766
|
+
case "left":
|
|
2767
|
+
setPopupPosition({
|
|
2768
|
+
top: positions.top - OFFSET,
|
|
2769
|
+
left: positions.left - (popupRef.current?.offsetWidth || 0) - OFFSET
|
|
2770
|
+
});
|
|
2771
|
+
break;
|
|
2772
|
+
case "right":
|
|
2773
|
+
setPopupPosition({
|
|
2774
|
+
top: positions.top - OFFSET,
|
|
2775
|
+
left: positions.left + container.width + OFFSET
|
|
2776
|
+
});
|
|
2777
|
+
break;
|
|
2778
|
+
}
|
|
2779
|
+
};
|
|
2780
|
+
_calculation();
|
|
2781
|
+
});
|
|
2787
2782
|
}, [targetRef, popupContainer, popupRef, useTargetWidth, inBody, _placement, setOpen]);
|
|
2788
2783
|
useEffect(() => {
|
|
2789
2784
|
if (!open) {
|
|
@@ -2811,7 +2806,6 @@ const usePopupPosition = ({
|
|
|
2811
2806
|
popupStyle: {
|
|
2812
2807
|
zIndex: 10000,
|
|
2813
2808
|
position: "absolute",
|
|
2814
|
-
// transition: '1s ease',
|
|
2815
2809
|
opacity: Object.keys(popupPosition).length ? 1 : 0,
|
|
2816
2810
|
...popupPosition
|
|
2817
2811
|
}
|
|
@@ -5675,7 +5669,6 @@ const Popover = ({
|
|
|
5675
5669
|
style = {},
|
|
5676
5670
|
overlayClassName = '',
|
|
5677
5671
|
overlayStyle = {},
|
|
5678
|
-
overlayPopupStyle = {},
|
|
5679
5672
|
onVisibleChange,
|
|
5680
5673
|
getPopupContainer
|
|
5681
5674
|
}) => {
|
|
@@ -5692,7 +5685,6 @@ const Popover = ({
|
|
|
5692
5685
|
placement,
|
|
5693
5686
|
open: isOpen,
|
|
5694
5687
|
setOpen: setInnerOpen,
|
|
5695
|
-
overlayPopupStyle,
|
|
5696
5688
|
popupContainer: getPopupContainer?.(targetRef.current)
|
|
5697
5689
|
});
|
|
5698
5690
|
useEffect(() => {
|