import { FC, useEffect, useRef } from 'react' import s from './Sidebar.module.css' import cn from 'classnames' import { disableBodyScroll, enableBodyScroll, clearAllBodyScrollLocks, } from 'body-scroll-lock' interface SidebarProps { children: any onClose: () => void } const Sidebar: FC = ({ children, onClose }) => { const sidebarRef = useRef() as React.MutableRefObject const contentRef = useRef() as React.MutableRefObject const onKeyDownSidebar = (event: React.KeyboardEvent) => { if (event.code === 'Escape') { onClose() } } useEffect(() => { if (sidebarRef.current) { sidebarRef.current.focus() } const contentElement = contentRef.current if (contentElement) { disableBodyScroll(contentElement, { reserveScrollBarGap: true }) } return () => { if (contentElement) enableBodyScroll(contentElement) clearAllBodyScrollLocks() } }, []) return (
{children}
) } export default Sidebar