blob: 923c636b14fbe74c0416bd300bd0a84a525bcd99 (
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
47
48
49
50
51
|
import { ReactNode } from "react";
import ReactDOM from "react-dom";
import { CSSTransition } from "react-transition-group";
import "./Dialog.css";
const optionalPortalElement = document.getElementById("portal");
if (optionalPortalElement == null) {
throw new Error("Portal element not found");
}
const portalElement = optionalPortalElement;
interface DialogProps {
onClose: () => void;
open: boolean;
children?: ReactNode;
disableCloseOnClickOnOverlay?: boolean;
}
export default function Dialog(props: DialogProps) {
const { open, onClose, children, disableCloseOnClickOnOverlay } = props;
return ReactDOM.createPortal(
<CSSTransition
mountOnEnter
unmountOnExit
in={open}
timeout={300}
classNames="cru-dialog"
>
<div
className="cru-dialog-overlay"
onPointerDown={
disableCloseOnClickOnOverlay
? undefined
: () => {
onClose();
}
}
>
<div
className="cru-dialog-container"
onPointerDown={(e) => e.stopPropagation()}
>
{children}
</div>
</div>
</CSSTransition>,
portalElement,
);
}
|