forked from forthfate/openorbit
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmodal.tsx
More file actions
48 lines (47 loc) · 1.3 KB
/
Copy pathmodal.tsx
File metadata and controls
48 lines (47 loc) · 1.3 KB
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
import { X } from "lucide-react";
import { useEffect, type ReactNode } from "react";
import { locales, resolveLocale } from "../../locales";
export function Modal({
open,
title,
onClose,
children,
className = "",
}: {
open: boolean;
title: string;
onClose: () => void;
children: ReactNode;
className?: string;
}) {
useEffect(() => {
if (!open) return;
const closeOnEscape = (event: KeyboardEvent) => {
if (event.key === "Escape") onClose();
};
document.addEventListener("keydown", closeOnEscape);
return () => document.removeEventListener("keydown", closeOnEscape);
}, [open, onClose]);
if (!open) return null;
const locale = resolveLocale(localStorage.getItem("orbit.locale")),
close = locales[locale].ui.closeDialog;
return (
<div className="modal-backdrop" role="presentation" onMouseDown={onClose}>
<section
className={`modal ${className}`}
role="dialog"
aria-modal="true"
aria-label={title}
onMouseDown={(event) => event.stopPropagation()}
>
<header className="modal-header">
<h2>{title}</h2>
<button className="modal-close" aria-label={close} onClick={onClose}>
<X size={18} />
</button>
</header>
{children}
</section>
</div>
);
}