blob: 2ff7bea8fa1d98a5cffb7d1d515cb315295068d4 (
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
52
53
54
55
56
57
58
59
60
61
62
63
|
import { ReactNode, useRef } from "react";
import ReactDOM from "react-dom";
import { CSSTransition } from "react-transition-group";
import classNames from "classnames";
import { ThemeColor } from "../common";
import "./Dialog.css";
const optionalPortalElement = document.getElementById("portal");
if (optionalPortalElement == null) {
throw new Error("Portal element not found");
}
const portalElement = optionalPortalElement;
interface DialogProps {
open: boolean;
onClose: () => void;
color?: ThemeColor;
children?: ReactNode;
disableCloseOnClickOnOverlay?: boolean;
}
export default function Dialog({
open,
onClose,
color,
children,
disableCloseOnClickOnOverlay,
}: DialogProps) {
color = color ?? "primary";
const nodeRef = useRef(null);
return ReactDOM.createPortal(
<CSSTransition
nodeRef={nodeRef}
mountOnEnter
unmountOnExit
in={open}
timeout={300}
classNames="cru-dialog"
>
<div
ref={nodeRef}
className={classNames("cru-dialog-overlay", `cru-${color}`)}
>
<div
className="cru-dialog-background"
onClick={
disableCloseOnClickOnOverlay
? undefined
: () => {
onClose();
}
}
/>
<div className="cru-dialog-container">{children}</div>
</div>
</CSSTransition>,
portalElement,
);
}
|