From 21f6262bd819d7185b225c292e289a7a29671973 Mon Sep 17 00:00:00 2001 From: Jaied Al Sabid <87969327+jaieds@users.noreply.github.com> Date: Thu, 31 Oct 2024 15:09:23 +0600 Subject: [PATCH] Removed duplicate files --- src/components/drawer/drawer.jsx | 156 ------------------------------- 1 file changed, 156 deletions(-) delete mode 100644 src/components/drawer/drawer.jsx diff --git a/src/components/drawer/drawer.jsx b/src/components/drawer/drawer.jsx deleted file mode 100644 index c52e3c9d..00000000 --- a/src/components/drawer/drawer.jsx +++ /dev/null @@ -1,156 +0,0 @@ -import { - cloneElement, - createContext, - isValidElement, - useCallback, - useContext, - useEffect, - useMemo, - useRef, - useState, -} from 'react'; -import { callAll, cn } from '@/utilities/functions'; - -const DrawerContext = createContext(); -export const useDrawerState = () => useContext(DrawerContext); - -const TRANSITION_DURATION = 0.2; - -// Drawer component. -const Drawer = ({ - open, - setOpen, - children, - trigger, - className, - exitOnClickOutside = false, - exitOnEsc = true, - design = 'simple', - position = 'right', - transitionDuration = TRANSITION_DURATION, - scrollLock = true, -}) => { - const isControlled = open !== undefined && setOpen !== undefined; - const [isOpen, setIsOpen] = useState(false); - const drawerRef = useRef(null); - const drawerContainerRef = useRef(null); - - const openState = useMemo( - () => (isControlled ? open : isOpen), - [open, isOpen] - ); - const setOpenState = useMemo( - () => (isControlled ? setOpen : setIsOpen), - [setIsOpen, setIsOpen] - ); - - const handleOpen = () => { - if (openState) { - return; - } - - setOpenState(true); - }; - - const handleClose = () => { - if (!openState) { - return; - } - - setOpenState(false); - }; - - const renderTrigger = useCallback(() => { - if (isValidElement(trigger)) { - return cloneElement(trigger, { - onClick: callAll(handleOpen, trigger.props.onClick), - }); - } - - if (typeof trigger === 'function') { - return trigger({ onClick: handleOpen }); - } - - return null; - }, [trigger, handleOpen, handleClose]); - - const handleKeyDown = (event) => { - switch (event.key) { - case 'Escape': - if (exitOnEsc) { - handleClose(); - } - break; - default: - break; - } - }; - - const handleClickOutside = (event) => { - if ( - exitOnClickOutside && - drawerRef.current && - !drawerRef.current.contains(event.target) - ) { - handleClose(); - } - }; - - useEffect(() => { - window.addEventListener('keydown', handleKeyDown); - document.addEventListener('mousedown', handleClickOutside); - - return () => { - window.removeEventListener('keydown', handleKeyDown); - document.removeEventListener('mousedown', handleClickOutside); - }; - }, [openState]); - - // Prevent scrolling when drawer is open. - useEffect(() => { - if (!scrollLock) { - return; - } - - if (openState) { - document.querySelector('html').style.overflow = 'hidden'; - } - - return () => { - document.querySelector('html').style.overflow = ''; - }; - }, [openState]); - - return ( - <> - {renderTrigger()} - -
- {children} -
-
- - ); -}; - -export default Object.assign(Drawer, { - displayName: 'Drawer', -});