drfeely.com/website/components/Navbar/index.tsx

98 lines
3.1 KiB
TypeScript
Raw Normal View History

2023-07-23 22:26:35 +00:00
"use client";
2023-07-25 03:14:18 +00:00
import { useEffect, useState } from "react";
2023-07-23 22:26:35 +00:00
import { Bars3Icon, XMarkIcon } from "@heroicons/react/24/solid";
import NavPages from "./NavPages";
import logo from "@/public/content/logo.png";
import logo_small from "@/public/content/logo_small.png";
2023-08-25 19:06:28 +00:00
import Image from "next/image";
2023-08-26 02:18:11 +00:00
import { usePathname } from "next/navigation";
2023-07-23 22:26:35 +00:00
const Navbar = () => {
2023-07-25 03:14:18 +00:00
const [isTopOfPage, setIsTopOfPage] = useState(true);
2023-07-23 22:26:35 +00:00
const [menuActive, setMenuActive] = useState(false);
2023-08-26 02:18:11 +00:00
const currentPage = "/" + usePathname().split("/")[1];
2023-07-25 03:14:18 +00:00
useEffect(() => {
const handleScroll = () => {
if (window.scrollY === 0) {
setIsTopOfPage(true);
} else {
setIsTopOfPage(false);
}
};
window.addEventListener("scroll", handleScroll);
return () => window.removeEventListener("scroll", handleScroll);
}, []);
2023-08-26 02:18:11 +00:00
const useSmallNav: boolean = isTopOfPage && currentPage === "/";
2023-07-23 22:26:35 +00:00
return (
2023-07-25 03:14:18 +00:00
<nav
className={
2023-09-10 04:36:32 +00:00
"fixed top-0 z-40 w-full overflow-hidden bg-primary-500 text-primary-100 transition-all " +
2023-08-26 02:18:11 +00:00
(useSmallNav
? "bg-transparent pt-5 duration-100 md:pt-0"
: "bg-opacity-75 pt-0 drop-shadow backdrop-blur-sm delay-100 duration-200")
2023-07-25 03:14:18 +00:00
}
>
<div className="mx-auto flex w-11/12 items-center justify-between lg:w-5/6">
<div className="flex items-center justify-between">
2023-08-25 19:06:28 +00:00
<Image
2023-08-26 02:18:11 +00:00
src={useSmallNav ? logo_small : logo_small}
2023-08-25 19:06:28 +00:00
alt="Feely Center Logo"
className={
2023-08-30 22:56:17 +00:00
"drop-shadow-2xl transition-all duration-300 " +
2023-08-29 19:23:30 +00:00
(useSmallNav ? "w-24 md:w-44" : "w-16 md:w-24")
2023-08-25 19:06:28 +00:00
}
/>
<div
className={
"whitespace-nowrap p-5 font-cormorant text-2xl transition-all " +
2023-08-30 22:56:17 +00:00
(useSmallNav
? "w-0 select-none text-transparent duration-100"
: "delay-100 duration-300")
2023-08-25 19:06:28 +00:00
}
>
Richard A. Feely, DO
</div>
2023-07-25 03:14:18 +00:00
</div>
2023-07-23 22:26:35 +00:00
{/* Burger icon */}
<div className="w-[30px] text-tertiary-300 md:hidden ">
2023-07-23 22:26:35 +00:00
<Bars3Icon onClick={() => setMenuActive((e) => !e)}></Bars3Icon>
</div>
{/* Burger menu */}
{menuActive ? (
<div className="fixed right-0 top-0 z-50 h-screen animate-fadeIn bg-secondary-500 text-lg drop-shadow-lg ">
<div className="flex flex-col gap-6 px-12 py-5 text-right text-primary-500">
<div className="flex justify-end pb-3 ">
2023-07-23 22:26:35 +00:00
<XMarkIcon
className="w-[30px]"
onClick={() => setMenuActive((e) => !e)}
></XMarkIcon>
</div>
2023-08-26 02:18:11 +00:00
<NavPages currentPageClasses="text-primary-100"></NavPages>
2023-07-23 22:26:35 +00:00
</div>
</div>
) : (
<></>
)}
{/* Nav Bar */}
2023-07-25 03:14:18 +00:00
<div
className={
"hidden items-center gap-6 font-abel text-lg text-tertiary-300 transition-all duration-300 md:flex " +
2023-08-26 02:18:11 +00:00
(useSmallNav ? "px-5 py-24" : "p-5")
2023-07-25 03:14:18 +00:00
}
>
2023-08-26 02:18:11 +00:00
<NavPages currentPageClasses="text-secondary-500"></NavPages>
2023-07-23 22:26:35 +00:00
</div>
</div>
</nav>
);
};
export default Navbar;