blob: c755950d510fa150766d49d792f7598bb2019f3f (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
|
import * as React from "react";
import ReactDOM from "react-dom";
import { CSSTransition } from "react-transition-group";
import "./Dialog.css";
export interface DialogProps {
onClose: () => void;
open: boolean;
children?: React.ReactNode;
disableCloseOnClickOnOverlay?: boolean;
}
export default function Dialog(props: DialogProps): React.ReactElement | null {
const { open, onClose, children, disableCloseOnClickOnOverlay } = props;
return ReactDOM.createPortal(
<CSSTransition
mountOnEnter
unmountOnExit
in={open}
timeout={300}
classNames="cru-dialog"
>
<div
className="cru-dialog-overlay"
onClick={
disableCloseOnClickOnOverlay
? undefined
: () => {
onClose();
}
}
>
<div
className="cru-dialog-container"
onClick={(e) => e.stopPropagation()}
>
{children}
</div>
</div>
</CSSTransition>,
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
document.getElementById("portal")!
);
}
|