ag-common 0.0.682 → 0.0.683
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.
|
@@ -4,4 +4,4 @@ export declare const ModalItem: import("@emotion/styled").StyledComponent<{
|
|
|
4
4
|
theme?: import("@emotion/react").Theme | undefined;
|
|
5
5
|
as?: React.ElementType<any, keyof React.JSX.IntrinsicElements> | undefined;
|
|
6
6
|
}, React.DetailedHTMLProps<React.HTMLAttributes<HTMLDivElement>, HTMLDivElement>, {}>;
|
|
7
|
-
export declare const Modal: ({ open, setOpen, children, position, topPosition, showCloseButton, closeOnMoveMouseOutside, className, closeOnClickOutside, portalId, style, }: IModal) => React.JSX.Element | null;
|
|
7
|
+
export declare const Modal: ({ open, setOpen, children, position, topPosition, showCloseButton, closeOnMoveMouseOutside, className, closeOnClickOutside, portalId: pidraw, style, }: IModal) => React.JSX.Element | null;
|
|
@@ -34,6 +34,7 @@ const react_dom_1 = require("react-dom");
|
|
|
34
34
|
const useOnClickOutside_1 = require("../../helpers/useOnClickOutside");
|
|
35
35
|
const styles_1 = require("../../styles");
|
|
36
36
|
const Close_1 = require("../Close");
|
|
37
|
+
const globalId = 'ag-modal-portal';
|
|
37
38
|
const FixedBackground = styled_1.default.div `
|
|
38
39
|
position: fixed;
|
|
39
40
|
top: 0;
|
|
@@ -84,8 +85,33 @@ exports.ModalItem = styled_1.default.div `
|
|
|
84
85
|
const CloseStyled = (0, styled_1.default)(Close_1.Close) `
|
|
85
86
|
z-index: 1;
|
|
86
87
|
`;
|
|
87
|
-
const Modal = ({ open, setOpen, children, position = 'left', topPosition = 'top', showCloseButton = true, closeOnMoveMouseOutside = false, className, closeOnClickOutside = true, portalId, style, }) => {
|
|
88
|
+
const Modal = ({ open, setOpen, children, position = 'left', topPosition = 'top', showCloseButton = true, closeOnMoveMouseOutside = false, className, closeOnClickOutside = true, portalId: pidraw, style, }) => {
|
|
89
|
+
let portalId = pidraw;
|
|
90
|
+
if (portalId === undefined) {
|
|
91
|
+
portalId = globalId;
|
|
92
|
+
}
|
|
88
93
|
const [elem, setElem] = (0, react_1.useState)();
|
|
94
|
+
(0, react_1.useEffect)(() => {
|
|
95
|
+
if (portalId === null ||
|
|
96
|
+
document.querySelectorAll(`#${portalId}`).length > 0) {
|
|
97
|
+
return;
|
|
98
|
+
}
|
|
99
|
+
const d = document.createElement('div');
|
|
100
|
+
d.id = portalId;
|
|
101
|
+
d.style.position = 'fixed';
|
|
102
|
+
d.style.zIndex = '10';
|
|
103
|
+
document.body.appendChild(d);
|
|
104
|
+
return () => {
|
|
105
|
+
var _a;
|
|
106
|
+
try {
|
|
107
|
+
(_a = document.querySelector(`#${portalId}`)) === null || _a === void 0 ? void 0 : _a.remove();
|
|
108
|
+
}
|
|
109
|
+
catch (e) {
|
|
110
|
+
//
|
|
111
|
+
}
|
|
112
|
+
};
|
|
113
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
114
|
+
}, []);
|
|
89
115
|
(0, react_1.useEffect)(() => {
|
|
90
116
|
const originalStyle = window.getComputedStyle(document.body).overflow || '';
|
|
91
117
|
if (open) {
|
|
@@ -9,8 +9,8 @@ export interface IModal {
|
|
|
9
9
|
closeOnMoveMouseOutside?: boolean;
|
|
10
10
|
className?: string;
|
|
11
11
|
closeOnClickOutside?: boolean;
|
|
12
|
-
/** if provided, will create inside this #id */
|
|
13
|
-
portalId?: string;
|
|
12
|
+
/** if provided, will create inside this #id. default "ag-modal-portal". if null, wont use global id */
|
|
13
|
+
portalId?: string | null;
|
|
14
14
|
/**applied to modal inside fixed */
|
|
15
15
|
style?: CSSProperties;
|
|
16
16
|
}
|
package/package.json
CHANGED