/* @refresh reload */ import { type Component, createEffect, createSignal, JSX, Show } from "solid-js" import { Button } from "./button" interface MenuProps extends TitleProps { button?: JSX.Element buttonClassName?: string itemsClassName?: string } const MyMenu: Component = ({ title, button, children, id, className, buttonClassName, itemsClassName }) => { const [isOpen, setIsOpen] = createSignal(false) function closeMenu(): void { setIsOpen(false) } function toggleMenu(): void { setIsOpen(!isOpen()) } createEffect(() => { function click(e: MouseEvent): void { if (e.target instanceof HTMLElement) { if (e.target.closest(`#${id}`) === null) { closeMenu() } } } function keypress(e: KeyboardEvent): void { if (e.key === "Escape") { closeMenu() } } if (isOpen()) { document.addEventListener("click", click) document.addEventListener("keyup", keypress) } else { document.removeEventListener("click", click) document.removeEventListener("keyup", keypress) } }) return ( // TODO transition
{children}
) } export default MyMenu