import React from 'react'; import Exit from '../assets/exit.svg'; type SidebarProps = { isOpen: boolean; toggleState: (arg0: boolean) => void; children: React.ReactNode; }; export default function Sidebar({ isOpen, toggleState, children, }: SidebarProps) { const sidebarRef = React.useRef(null); const handleClickOutside = (event: MouseEvent) => { if ( sidebarRef.current && !sidebarRef.current.contains(event.target as Node) ) { toggleState(false); } }; React.useEffect(() => { document.addEventListener('mousedown', handleClickOutside); return () => { document.removeEventListener('mousedown', handleClickOutside); }; }, []); return (
{children}
); }