From e2d9c4757d51107a9f270ee50f24cf14f77d8e43 Mon Sep 17 00:00:00 2001 From: amandeeep02 Date: Fri, 5 Jul 2024 00:15:02 +0530 Subject: [PATCH] Removed the extra portion of the navbar and aligned it --- src/components/Navbar.jsx | 146 ++++++++++++++++++++++++-------------- 1 file changed, 94 insertions(+), 52 deletions(-) diff --git a/src/components/Navbar.jsx b/src/components/Navbar.jsx index 3989c2a..68ad8ed 100644 --- a/src/components/Navbar.jsx +++ b/src/components/Navbar.jsx @@ -1,68 +1,110 @@ import React, { useState, useRef, useEffect } from "react"; import { NavLink, useLocation } from "react-router-dom"; -import ThemeToggle from './ThemeToggle'; -import './Navbar.css'; +import ThemeToggle from "./ThemeToggle"; +import "./Navbar.css"; const Navbar = () => { - const location = useLocation(); - const [isMenuOpen, setMenuOpen] = useState(false); - const menuRef = useRef(null); + const location = useLocation(); + const [isMenuOpen, setMenuOpen] = useState(false); + const menuRef = useRef(null); - const isActive = (path) => location.pathname === path ? 'text-[#00bfff] underline' : ''; + const isActive = (path) => + location.pathname === path ? "text-[#00bfff] underline" : ""; - const handleLinkClick = () => { + const handleLinkClick = () => { + setMenuOpen(false); + }; + + useEffect(() => { + const handleClickOutside = (event) => { + if (menuRef.current && !menuRef.current.contains(event.target)) { setMenuOpen(false); + } }; - useEffect(() => { - const handleClickOutside = (event) => { - if (menuRef.current && !menuRef.current.contains(event.target)) { - setMenuOpen(false); - } - }; - - document.addEventListener("mousedown", handleClickOutside); - return () => { - document.removeEventListener("mousedown", handleClickOutside); - }; - }, []); + document.addEventListener("mousedown", handleClickOutside); + return () => { + document.removeEventListener("mousedown", handleClickOutside); + }; + }, []); return ( - - - ); + ); }; export default Navbar;