From e721a3140d7aca1a87b707ef31e32489942e99f4 Mon Sep 17 00:00:00 2001 From: Cameron Brown Date: Sun, 10 Nov 2024 18:44:01 -0500 Subject: [PATCH] src/components/Navbar.js: Add ability to have dropdown pages in Navbar --- src/components/Navbar.js | 71 ++++++++++++++++++++++++++++++++++------ 1 file changed, 61 insertions(+), 10 deletions(-) diff --git a/src/components/Navbar.js b/src/components/Navbar.js index 7870d81..9eb9f1e 100644 --- a/src/components/Navbar.js +++ b/src/components/Navbar.js @@ -1,30 +1,81 @@ -import React from 'react'; +import React, { useState, useRef } from 'react'; import { NavLink } from 'react-router-dom'; +import { FontAwesomeIcon } from '@fortawesome/react-fontawesome'; +import { faChevronDown } from '@fortawesome/free-solid-svg-icons'; import logo from '../assets/logo.png'; -const NavItem = ({ to, label }) => { +const NavItem = ({ to, label, dropdown }) => { + const [isDropdownOpen, setDropdownOpen] = useState(false); + const timeoutRef = useRef(null); + + // Handle opening the dropdown + const handleMouseEnter = () => { + clearTimeout(timeoutRef.current); + setDropdownOpen(true); + }; + + // Handle closing the dropdown with a delay + const handleMouseLeave = () => { + timeoutRef.current = setTimeout(() => { + setDropdownOpen(false); + }, 200); // Adjust delay as needed + }; + return ( - - {label} - + + {label} + {dropdown && } + + + {/* Dropdown Menu */} + {dropdown && isDropdownOpen && ( +
+ +
+ )} + ); }; function Navbar() { return ( -