1import { ComponentProps, onCleanup, onMount, Show } from "solid-js";
2
3export interface ModalProps extends Pick<ComponentProps<"svg">, "children"> {
4 open?: boolean;
5 onClose?: () => void;
6}
7
8export const Modal = (props: ModalProps) => {
9 return (
10 <Show when={props.open}>
11 <dialog
12 ref={(node) => {
13 onMount(() => {
14 document.body.style.overflow = "hidden";
15 node.showModal();
16 (document.activeElement as any).blur();
17 });
18 onCleanup(() => node.close());
19 }}
20 onClick={(ev) => {
21 if (ev.target === ev.currentTarget) {
22 if (props.onClose) props.onClose();
23 }
24 }}
25 onClose={() => {
26 document.body.style.overflow = "auto";
27 if (props.onClose) props.onClose();
28 }}
29 class="h-full max-h-none w-full max-w-none bg-transparent backdrop:bg-transparent"
30 >
31 {props.children}
32 </dialog>
33 </Show>
34 );
35};