From c48e53850af7964b395e134940555b205a3a5a94 Mon Sep 17 00:00:00 2001 From: tanish35 Date: Tue, 15 Oct 2024 14:58:03 +0530 Subject: [PATCH] Fix sidebar --- frontend/src/components/MainNavbar.tsx | 88 ++++++++++++++++++++------ 1 file changed, 68 insertions(+), 20 deletions(-) diff --git a/frontend/src/components/MainNavbar.tsx b/frontend/src/components/MainNavbar.tsx index 528c284..ce548fa 100644 --- a/frontend/src/components/MainNavbar.tsx +++ b/frontend/src/components/MainNavbar.tsx @@ -1,7 +1,6 @@ -import React, { useEffect, useState } from "react"; -import { Outlet, useNavigate } from "react-router-dom"; -import { useLocation } from "react-router-dom"; -import { Link } from "react-router-dom"; +import React, { useEffect, useState, useRef } from "react"; +import { Outlet, useNavigate, Link } from "react-router-dom"; +import { gsap } from "gsap"; interface NavbarProps { btnName: string; @@ -11,13 +10,33 @@ interface NavbarProps { const Navbar: React.FC = ({ btnName, navigateUrl, display }) => { const navigate = useNavigate(); - const location = useLocation(); const [isSidebarOpen, setIsSidebarOpen] = useState(false); + const sidebarRef = useRef(null); // Ref for the sidebar + + useEffect(() => { + if (isSidebarOpen) { + gsap.fromTo( + sidebarRef.current, + { x: -250, opacity: 0 }, // Start position and opacity + { x: 0, opacity: 1, duration: 0.3 } // End position and opacity + ); + } + }, [isSidebarOpen]); useEffect(() => { if (location.pathname === "/") navigate("/homepage"); }, [location, navigate]); + // Close sidebar function with GSAP animation + const closeSidebar = () => { + gsap.to(sidebarRef.current, { + x: -250, + opacity: 0, + duration: 0.3, + onComplete: () => setIsSidebarOpen(false), // Set sidebar state after animation + }); + }; + return ( <>