import React, { useEffect, useRef } from "react"; import "./menu-styles.scss"; import { MenuOption, MenuProps } from "@app/models/components"; import Option from "../option/Option"; const Menu: React.FC = ({ id = "", children, options = [], open, onClose, }) => { const menuRef = useRef(null); useEffect(() => { const handleClickOutside = (event: MouseEvent) => { if (menuRef.current && !menuRef.current.contains(event.target as Node)) { onClose?.(); } }; if (open) { document.addEventListener("click", handleClickOutside); } return () => { document.removeEventListener("click", handleClickOutside); }; }, [open, onClose]); const handleMenuOptionClick = (option: MenuOption) => () => { option.onClick(); onClose?.(); }; return ( <> {options?.length > 0 && (
{children} {open && (
    {options.map((option, index) => (
)}
)} ); }; export default Menu;