97 lines
3.6 KiB
TypeScript
Raw Normal View History

2025-03-10 13:27:47 +00:00
"use client"
2025-03-17 12:43:28 +00:00
import Image from "next/image";
import Link from "next/link";
2025-03-17 13:56:42 +00:00
import { usePathname } from 'next/navigation'
2025-03-17 13:21:02 +00:00
import { useState, useEffect, useRef } from "react";
2025-03-10 13:27:47 +00:00
export default function Navbar() {
const [isDropdownOpen, setIsDropdownOpen] = useState(false);
2025-03-17 13:56:42 +00:00
const pathname = usePathname()
2025-03-10 13:27:47 +00:00
const dropdownRef = useRef<HTMLDivElement>(null);
useEffect(() => {
const handleClickOutside = (event: MouseEvent) => {
if (
dropdownRef.current &&
!dropdownRef.current.contains(event.target as Node)
) {
setIsDropdownOpen(false);
}
};
2025-03-17 13:21:02 +00:00
2025-03-10 13:27:47 +00:00
const handleEscapeKey = (event: KeyboardEvent) => {
if (event.key === "Escape") {
setIsDropdownOpen(false);
}
};
2025-03-17 13:21:02 +00:00
2025-03-10 13:27:47 +00:00
document.addEventListener("mousedown", handleClickOutside);
document.addEventListener("keydown", handleEscapeKey);
2025-03-17 13:21:02 +00:00
2025-03-10 13:27:47 +00:00
return () => {
document.removeEventListener("mousedown", handleClickOutside);
document.removeEventListener("keydown", handleEscapeKey);
};
}, []);
return (
<div className="w-full flex h-14 border-b border-neutral-300 text-black">
2025-03-17 12:43:28 +00:00
<div className="my-1 flex aspect-square ml-2 mr-4">
<Link href="/">
<Image height={2000} width={2000} alt="Background Image" src="/logo.png"></Image>
</Link>
2025-03-10 13:27:47 +00:00
</div>
<div className="flex">
2025-03-17 13:56:42 +00:00
<button className="px-6 border-b-2 border-black">
2025-03-17 13:21:02 +00:00
<Link href="/earthquakes">
Earthquakes
</Link>
</button>
2025-03-17 13:56:42 +00:00
<button className="px-6 border-b-2 border-black">
2025-03-17 13:21:02 +00:00
<Link href="/observatories">
Observatories
</Link>
</button>
2025-03-17 13:56:42 +00:00
<button className="px-6 border-b-2 border-black">
2025-03-17 13:21:02 +00:00
<Link href="/warehouse">
Warehouse
</Link>
</button>
2025-03-17 13:56:42 +00:00
<button className="px-6 border-b-2 border-black">
2025-03-17 13:21:02 +00:00
<Link href="/shop">
Shop
</Link>
</button>
2025-03-10 13:27:47 +00:00
<div className="my-auto relative">
<button
className="px-6"
onClick={() => setIsDropdownOpen(!isDropdownOpen)}
>
About Us
</button>
{isDropdownOpen && (
<div ref={dropdownRef} className="absolute top-full left-0 mt-4 w-40 bg-white border border-neutral-300 rounded-lg shadow-lg z-50">
<ul>
<li className="px-4 py-2 hover:bg-neutral-100 rounded-lg cursor-pointer">Our Mission</li>
<li className="px-4 py-2 hover:bg-neutral-100 cursor-pointer">The Team</li>
<li className="px-4 py-2 hover:bg-neutral-100 rounded-lg cursor-pointer">Contact Us</li>
</ul>
</div>
)}
</div>
</div>
<div className="flex-grow"></div>
<div className="my-2 mr-2 w-10 flex border rounded-full">
2025-03-17 13:56:42 +00:00
<p className="m-auto text-sm">
<Link href="/user">
User
</Link>
</p>
2025-03-10 13:27:47 +00:00
</div>
</div>
);
}