|
1 | | -import React from "react"; |
| 1 | +import React, { useState, useEffect } from "react"; |
2 | 2 | import { Disclosure } from "@headlessui/react"; |
3 | 3 | import { Bars3Icon, XMarkIcon } from "@heroicons/react/24/outline"; |
4 | | -import { Link, NavLink, useLocation } from "react-router-dom"; |
| 4 | +import { Link, NavLink } from "react-router-dom"; |
5 | 5 | import { useAuth } from "../../../context/AuthContext.tsx"; |
| 6 | +import logo from "../../../images/LabConnect_Logo-removebg-preview.png"; // Adjust path if needed |
6 | 7 |
|
7 | 8 | export default function MainNavigation() { |
8 | | - |
9 | 9 | const { auth } = useAuth(); |
| 10 | + const [isDarkMode, setIsDarkMode] = useState(false); |
| 11 | + |
| 12 | + // Toggle dark mode by adding or removing the "dark" class on the HTML element. |
| 13 | + useEffect(() => { |
| 14 | + if (isDarkMode) { |
| 15 | + document.documentElement.classList.add("dark"); |
| 16 | + } else { |
| 17 | + document.documentElement.classList.remove("dark"); |
| 18 | + } |
| 19 | + }, [isDarkMode]); |
10 | 20 |
|
11 | | - const location = useLocation().pathname; |
| 21 | + // Define navigation routes based on authentication. |
12 | 22 | const routes = auth.isAuthenticated |
13 | 23 | ? [ |
14 | | - { name: "Opportunities", href: "/opportunities", current: true }, |
15 | | - { name: "Create", href: "/create", current: false }, |
16 | | - { name: "Staff", href: "/staff", current: false }, |
17 | | - { name: "Profile", href: "/profile", current: false }, |
18 | | - { name: "Sign Out", href: "/signout", current: false }, |
19 | | - ] |
20 | | - : [{ name: "Sign In", href: "/signin", current: false }]; |
| 24 | + { name: "Opportunities", href: "/opportunities" }, |
| 25 | + { name: "Create", href: "/create" }, |
| 26 | + { name: "Staff", href: "/staff" }, |
| 27 | + { name: "Profile", href: "/profile" }, |
| 28 | + { name: "Sign Out", href: "/signout" } |
| 29 | + ] |
| 30 | + : [{ name: "Sign In", href: "/signin" }]; |
21 | 31 |
|
22 | 32 | return ( |
23 | | - <Disclosure as="nav" className="bg-slate-100"> |
| 33 | + <Disclosure as="nav" className="bg-blue-600 text-white shadow-inner"> |
24 | 34 | {({ open }) => ( |
25 | 35 | <> |
26 | | - <div className="mainnav sm:px-6 lg:px-8"> |
27 | | - <div className="mainnav-header"> |
28 | | - <div className="mainnav-desc sm:hidden"> |
29 | | - {/* Mobile menu button*/} |
30 | | - <Disclosure.Button className="btn-disclosure hover:bg-gray-700 hover:text-white focus:outline-none focus:ring-2 focus:ring-inset focus:ring-white"> |
31 | | - <span className="absolute -inset-0.5" /> |
32 | | - <span className="sr-only">Open main menu</span> |
| 36 | + <div className="w-full px-4 py-6 flex items-center justify-between"> |
| 37 | + {/* Left Section: Branding */} |
| 38 | + <div className="flex items-center space-x-4"> |
| 39 | + <Link to="/"> |
| 40 | + <img |
| 41 | + src={logo} |
| 42 | + alt="LabConnect Logo" |
| 43 | + className="h-16 w-auto filter brightness-0 invert" |
| 44 | + /> |
| 45 | + </Link> |
| 46 | + <span className="font-bold text-xl">LabConnect</span> |
| 47 | + </div> |
| 48 | + {/* Center Section: Navigation Links */} |
| 49 | + <div className="hidden md:flex flex-grow justify-center"> |
| 50 | + <nav className="flex space-x-12"> |
| 51 | + {routes.map((item) => ( |
| 52 | + <NavLink |
| 53 | + key={item.name} |
| 54 | + to={item.href} |
| 55 | + className={({ isActive }) => |
| 56 | + `text-2xl font-bold hover:underline ${ |
| 57 | + isActive ? "underline" : "" |
| 58 | + }` |
| 59 | + } |
| 60 | + > |
| 61 | + {item.name} |
| 62 | + </NavLink> |
| 63 | + ))} |
| 64 | + </nav> |
| 65 | + </div> |
| 66 | + {/* Right Section: Dark Mode Toggle and Mobile Menu Button */} |
| 67 | + <div className="flex items-center"> |
| 68 | + <label className="flex items-center cursor-pointer"> |
| 69 | + <div className="relative"> |
| 70 | + <input |
| 71 | + type="checkbox" |
| 72 | + className="sr-only" |
| 73 | + checked={isDarkMode} |
| 74 | + onChange={() => setIsDarkMode((prev) => !prev)} |
| 75 | + /> |
| 76 | + <div className="w-11 h-6 bg-gray-300 dark:bg-gray-600 rounded-full" /> |
| 77 | + <div |
| 78 | + className={`absolute left-1 top-1 bg-white w-4 h-4 rounded-full transition-transform ${ |
| 79 | + isDarkMode ? "translate-x-5" : "" |
| 80 | + }`} |
| 81 | + ></div> |
| 82 | + </div> |
| 83 | + <span className="ml-3 text-white text-lg font-bold"> |
| 84 | + Enable Dark Mode |
| 85 | + </span> |
| 86 | + </label> |
| 87 | + <div className="md:hidden ml-4"> |
| 88 | + <Disclosure.Button className="p-2 rounded hover:bg-gray-700 hover:text-white focus:outline-none"> |
33 | 89 | {open ? ( |
34 | | - <XMarkIcon className="blck66" aria-hidden="true" /> |
| 90 | + <XMarkIcon className="h-6 w-6" aria-hidden="true" /> |
35 | 91 | ) : ( |
36 | | - <Bars3Icon className="blck66" aria-hidden="true" /> |
| 92 | + <Bars3Icon className="h-6 w-6" aria-hidden="true" /> |
37 | 93 | )} |
38 | 94 | </Disclosure.Button> |
39 | 95 | </div> |
40 | | - <div className="mainnav-desc2 sm:items-stretch sm:justify-start"> |
41 | | - <div className="mainnav-title-link"> |
42 | | - <Link to="/" className="blue-link hover:text-blue-900 focus:text-blue-900"> |
43 | | - LabConnect |
44 | | - </Link> |
45 | | - </div> |
46 | | - <div className="hidden sm:ml-6 sm:block"> |
47 | | - <div className="flex space-x-4 "> |
48 | | - {routes.map((item) => ( |
49 | | - <NavLink |
50 | | - key={item.name} |
51 | | - to={item.href} |
52 | | - className={`${location === item.href |
53 | | - ? "text-black" |
54 | | - : "text-gray-600" |
55 | | - } hover:text-gray-800 hover:bg-gray-200 mainnav-link`} |
56 | | - aria-current={item.current} |
57 | | - > |
58 | | - {item.name} |
59 | | - </NavLink> |
60 | | - ))} |
61 | | - </div> |
62 | | - </div> |
63 | | - </div> |
64 | 96 | </div> |
65 | 97 | </div> |
66 | | - |
67 | | - <Disclosure.Panel className="sm:hidden"> |
68 | | - <div className="space-y-1 px-2 pb-3 pt-2"> |
| 98 | + {/* Mobile Panel */} |
| 99 | + <Disclosure.Panel className="md:hidden"> |
| 100 | + <div className="px-4 pb-3 pt-2 space-y-1"> |
69 | 101 | {routes.map((item) => ( |
70 | 102 | <Disclosure.Button |
71 | 103 | key={item.name} |
72 | | - as="a" |
73 | | - href={item.href} |
74 | | - className="btn-disclosure2 hover:bg-gray-200" |
75 | | - aria-current={item.current ? "page" : undefined} |
| 104 | + as={Link} |
| 105 | + to={item.href} |
| 106 | + className="block text-2xl font-bold hover:underline" |
76 | 107 | > |
77 | 108 | {item.name} |
78 | 109 | </Disclosure.Button> |
79 | 110 | ))} |
| 111 | + {/* Dark Mode Toggle Switch */} |
| 112 | + <label className="absolute top-4 right-4 flex items-center cursor-pointer"> |
| 113 | + <input |
| 114 | + type="checkbox" |
| 115 | + className="sr-only peer" |
| 116 | + checked={isDarkMode} |
| 117 | + onChange={() => setIsDarkMode(prev => !prev)} |
| 118 | + /> |
| 119 | + <div className="w-11 h-6 bg-gray-300 dark:bg-gray-600 rounded-full peer-focus:outline-none peer-checked:bg-blue-600 relative transition-all duration-300"> |
| 120 | + <div |
| 121 | + className={`absolute left-1 top-1 bg-white dark:bg-gray-300 w-4 h-4 rounded-full transition-transform duration-300 ${ |
| 122 | + isDarkMode ? "translate-x-5" : "" |
| 123 | + }`} |
| 124 | + ></div> |
| 125 | + </div> |
| 126 | + <span className="ml-3 text-gray-700 dark:text-gray-200 font-medium"> |
| 127 | + Enable Dark Mode |
| 128 | + </span> |
| 129 | + </label> |
80 | 130 | </div> |
81 | 131 | </Disclosure.Panel> |
82 | 132 | </> |
|
0 commit comments