From 850b21ba988f09cb49cb01384c14d7604984a12c Mon Sep 17 00:00:00 2001 From: Mahyar Khanbolooki Date: Sun, 13 Jul 2025 02:42:02 +0330 Subject: [PATCH] improve: side menu animation --- src/components/menu/SideMenu.tsx | 43 ++++++++++++++++++++++++++++---- 1 file changed, 38 insertions(+), 5 deletions(-) diff --git a/src/components/menu/SideMenu.tsx b/src/components/menu/SideMenu.tsx index bcd7978..da67898 100644 --- a/src/components/menu/SideMenu.tsx +++ b/src/components/menu/SideMenu.tsx @@ -1,6 +1,7 @@ 'use client'; -import React, { useMemo } from 'react' +import React, { useMemo, useRef } from 'react' +import { motion, PanInfo, Variants } from 'framer-motion'; import MenuItemType from './SideMenuItem' import SideMenuItem from './SideMenuItem'; import NotificationBellIcon from '../icons/NotificationBellIcon'; @@ -73,11 +74,43 @@ type Props = { function SideMenu({ menuState, toggleMenuState, nightModeState, togglenightModeState }: Props) { const menuStateMemo = useMemo(() => menuState, [menuState]); + const closeRef: React.Ref | undefined = useRef(null); + + const variants: Variants = { + hidden: { + x: '100%', + }, + visible: { + x: 0, + transition: { + duration: 0.1, + ease: 'easeInOut', + }, + }, + }; + + const onDrag = (_event: MouseEvent | TouchEvent | PointerEvent, info: PanInfo) => { + if (info.offset.x > 100) { + if (closeRef.current) { + closeRef.current.click(); + } + } + } return ( -
- -
+ + { e.stopPropagation(); }} className={`fixed top-0 bottom-0 -right-full data-[isvisible=true]:right-0 transition-all duration-100 ease-in-out not-xl:!rounded-s-none overflow-clip bg-white w-[200px] h-dvh flex flex-col z-40`}> @@ -99,7 +132,7 @@ function SideMenu({ menuState, toggleMenuState, nightModeState, togglenightModeS }> -
+
)