import React, { useEffect } from 'react'; import trapFocus from '../utils/trapFocus'; import Typography from '../Typography/Typography'; export interface DrawerProps { ariaLabel?: string; callback: Function; children: React.ReactNode; id?: string; onBottom?: boolean; onRight?: boolean; openCallback?: Function; title?: string; showBack?: boolean; showClose?: boolean; showMask?: boolean; } const Drawer = ({ ariaLabel, callback, children, id = 'myDrawer', onBottom = false, onRight = false, openCallback = () => {}, title, showBack = false, showClose = true, showMask = true, }: DrawerProps) => { useEffect(() => { if (openCallback !== null) openCallback(); document.addEventListener('keydown', (e) => { trapFocus(e, `#${id}--drawer`, true); }); }, [id, openCallback]); return ( <> {title && title !== '' && ( {showBack !== false && ( callback()} > )} {showClose !== false && ( callback()} aria-label="Close" > )} )} {children} {showMask !== false && ( callback()} /> )} > ); }; export default Drawer;