x-ui-design 0.8.12 → 0.8.13
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/types/popover.d.ts +1 -0
- package/dist/index.esm.js +10 -8
- package/dist/index.esm.js.map +1 -1
- package/dist/index.js +10 -8
- package/dist/index.js.map +1 -1
- package/lib/components/Popover/Popover.tsx +20 -16
- package/lib/types/popover.ts +1 -0
- package/package.json +1 -1
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import React, { useRef, useState } from "react";
|
|
1
|
+
import React, { useRef, useState, useEffect } from "react";
|
|
2
2
|
import { usePosition } from "../../hooks/usePosition";
|
|
3
3
|
import { clsx } from '../../helpers';
|
|
4
4
|
import { PopoverProps } from "../../types/popover";
|
|
@@ -14,6 +14,7 @@ const Popover = ({
|
|
|
14
14
|
trigger = "click",
|
|
15
15
|
placement = "bottom",
|
|
16
16
|
open,
|
|
17
|
+
visible,
|
|
17
18
|
title,
|
|
18
19
|
overlayClassName = '',
|
|
19
20
|
overlayStyle = {},
|
|
@@ -25,9 +26,8 @@ const Popover = ({
|
|
|
25
26
|
|
|
26
27
|
const [innerOpen, setInnerOpen] = useState(false);
|
|
27
28
|
|
|
28
|
-
const
|
|
29
|
-
|
|
30
|
-
const [_hover, setHover] = useState<boolean>(isOpen);
|
|
29
|
+
const [hover, setHover] = useState(false);
|
|
30
|
+
const isOpen = visible !== undefined ? visible : open !== undefined ? open : innerOpen;
|
|
31
31
|
|
|
32
32
|
const { dropdownPosition, shouldShowAbove } = usePosition({
|
|
33
33
|
isOpen,
|
|
@@ -39,12 +39,12 @@ const Popover = ({
|
|
|
39
39
|
});
|
|
40
40
|
|
|
41
41
|
const toggle = () => {
|
|
42
|
-
|
|
42
|
+
const newState = !isOpen;
|
|
43
|
+
onVisibleChange ? onVisibleChange(newState) : setInnerOpen(newState);
|
|
43
44
|
};
|
|
44
45
|
|
|
45
46
|
const show = () => {
|
|
46
47
|
setHover(true);
|
|
47
|
-
|
|
48
48
|
if (trigger === "hover") {
|
|
49
49
|
onVisibleChange ? onVisibleChange(true) : setInnerOpen(true);
|
|
50
50
|
}
|
|
@@ -52,7 +52,6 @@ const Popover = ({
|
|
|
52
52
|
|
|
53
53
|
const hide = () => {
|
|
54
54
|
setHover(false);
|
|
55
|
-
|
|
56
55
|
if (trigger === "hover") {
|
|
57
56
|
onVisibleChange ? onVisibleChange(false) : setInnerOpen(false);
|
|
58
57
|
}
|
|
@@ -66,33 +65,38 @@ const Popover = ({
|
|
|
66
65
|
return (
|
|
67
66
|
<div className={`${prefixCls}-wrapper`}>
|
|
68
67
|
<div ref={triggerRef}>
|
|
69
|
-
<div className={`${prefixCls}-wrapper-content`} {...childProps}>
|
|
68
|
+
<div className={`${prefixCls}-wrapper-content`} {...childProps}>
|
|
69
|
+
{children}
|
|
70
|
+
</div>
|
|
70
71
|
|
|
71
72
|
{isOpen && (
|
|
72
73
|
<ConditionalWrapper
|
|
73
|
-
condition={getPopupContainer
|
|
74
|
-
wrapper={(element) =>
|
|
75
|
-
|
|
74
|
+
condition={!!getPopupContainer}
|
|
75
|
+
wrapper={(element) =>
|
|
76
|
+
getPopupContainer
|
|
77
|
+
? createPortal(element, getPopupContainer(popupRef.current as HTMLElement))
|
|
78
|
+
: <>{element}</>
|
|
79
|
+
}
|
|
80
|
+
>
|
|
76
81
|
<div
|
|
77
82
|
ref={popupRef}
|
|
78
|
-
className={clsx(prefixCls, `${prefixCls}-${placement}`,
|
|
83
|
+
className={clsx(prefixCls, `${prefixCls}-${placement}`, overlayClassName)}
|
|
79
84
|
style={{
|
|
80
|
-
zIndex:
|
|
85
|
+
zIndex: hover ? 1000 : 1,
|
|
81
86
|
...overlayStyle,
|
|
82
87
|
position: "absolute",
|
|
83
88
|
...dropdownPosition
|
|
84
89
|
}}
|
|
85
90
|
>
|
|
86
|
-
{title
|
|
91
|
+
{title && <div className={`${prefixCls}-title`}>{title}</div>}
|
|
87
92
|
<div className={`${prefixCls}-inner`}>{content}</div>
|
|
88
93
|
<div className={`${prefixCls}-arrow ${shouldShowAbove ? 'bottom' : ''}`} />
|
|
89
94
|
</div>
|
|
90
95
|
</ConditionalWrapper>
|
|
91
96
|
)}
|
|
92
97
|
</div>
|
|
93
|
-
|
|
94
98
|
</div>
|
|
95
99
|
);
|
|
96
100
|
};
|
|
97
101
|
|
|
98
|
-
export default Popover;
|
|
102
|
+
export default Popover;
|
package/lib/types/popover.ts
CHANGED
|
@@ -10,6 +10,7 @@ export interface PopoverProps {
|
|
|
10
10
|
overlayStyle?: CSSProperties;
|
|
11
11
|
overlayClassName?: string;
|
|
12
12
|
title?: string | ReactNode;
|
|
13
|
+
visible?: boolean;
|
|
13
14
|
onVisibleChange?: ((open: boolean) => void) | undefined;
|
|
14
15
|
getPopupContainer?: ((node: HTMLElement) => HTMLElement) | undefined
|
|
15
16
|
}
|