import { createEffect, createSignal, onMount, Show } from 'solid-js' import { getLogger } from '../../utils/logger' import './Modal.scss' import { hideModal, useModalStore } from '../../stores/ui' const log = getLogger('modal') interface ModalProps { name: string children: any } export const Modal = (props: ModalProps) => { const { getModal } = useModalStore() const wrapClick = (ev: Event) => { if ((ev.target as HTMLElement).classList.contains('modalwrap')) hideModal() } onMount(() => { window.addEventListener('keydown', (e: KeyboardEvent) => { if (e.key === 'Escape') hideModal() }) }) const [visible, setVisible] = createSignal(false) createEffect(() => { setVisible(getModal() === props.name) log.debug(`${props.name} is ${getModal() === props.name ? 'visible' : 'hidden'}`) }) return (
{props.children}
) }