1
0
Fork 0
mirror of https://github.com/muerwre/vault-frontend.git synced 2025-04-25 12:56:41 +07:00
vault-frontend/src/containers/sidebars/SidebarWrapper/index.tsx
2022-01-19 12:30:04 +07:00

32 lines
704 B
TypeScript

import React, { FC, useEffect, useRef } from 'react';
import { clearAllBodyScrollLocks, disableBodyScroll } from 'body-scroll-lock';
import { useCloseOnEscape } from '~/hooks';
import styles from './styles.module.scss';
interface IProps {
onClose?: () => void;
}
const SidebarWrapper: FC<IProps> = ({ children, onClose }) => {
const ref = useRef<HTMLDivElement>(null);
useCloseOnEscape(onClose);
useEffect(() => {
if (!ref.current) return;
disableBodyScroll(ref.current, { reserveScrollBarGap: true });
return () => clearAllBodyScrollLocks();
}, []);
return (
<div className={styles.wrapper} ref={ref}>
{children}
</div>
);
};
export { SidebarWrapper };