2023-05-23 14:07:44 +03:00
|
|
|
"use client";
|
2023-05-18 14:37:03 +03:00
|
|
|
import Image from "next/image";
|
2023-05-23 14:07:44 +03:00
|
|
|
import { FC, useEffect, useRef, useState } from "react";
|
2023-05-26 14:56:29 +03:00
|
|
|
|
2023-05-23 14:07:44 +03:00
|
|
|
import { motion } from "framer-motion";
|
2023-05-26 14:56:29 +03:00
|
|
|
import Link from "next/link";
|
2023-05-24 09:20:55 +03:00
|
|
|
import MobileMenu from "./MobileMenu";
|
|
|
|
import NavItems from "./NavItems";
|
2023-05-18 14:37:03 +03:00
|
|
|
|
2023-05-26 14:56:29 +03:00
|
|
|
const NavBar: FC = () => {
|
2023-05-23 14:07:44 +03:00
|
|
|
const scrollPos = useRef<number>(0);
|
|
|
|
const [hidden, setHidden] = useState(false);
|
|
|
|
|
|
|
|
useEffect(() => {
|
|
|
|
const handleScroll = (e: Event) => {
|
|
|
|
const target = e.currentTarget as Window;
|
2023-05-26 12:34:52 +03:00
|
|
|
if (target.scrollY > scrollPos.current) {
|
2023-05-23 14:07:44 +03:00
|
|
|
setHidden(true);
|
|
|
|
} else {
|
|
|
|
setHidden(false);
|
|
|
|
}
|
|
|
|
scrollPos.current = target.scrollY;
|
|
|
|
};
|
|
|
|
|
|
|
|
window.addEventListener("scroll", handleScroll);
|
|
|
|
return () => window.removeEventListener("scroll", handleScroll);
|
2023-05-26 12:34:52 +03:00
|
|
|
}, []);
|
2023-05-23 14:07:44 +03:00
|
|
|
|
2023-05-18 14:37:03 +03:00
|
|
|
return (
|
2023-05-23 14:07:44 +03:00
|
|
|
<motion.header
|
|
|
|
animate={{
|
|
|
|
y: hidden ? "-100%" : "0%",
|
|
|
|
transition: { ease: "circOut" },
|
|
|
|
}}
|
2023-05-24 09:20:55 +03:00
|
|
|
className="fixed top-0 w-full border-b border-b-black/10 dark:border-b-white/25 bg-white dark:bg-black z-20"
|
2023-05-23 14:07:44 +03:00
|
|
|
>
|
2023-05-24 09:20:55 +03:00
|
|
|
<nav className="max-w-screen-xl mx-auto py-1 flex items-center justify-between gap-8">
|
2023-05-18 14:37:03 +03:00
|
|
|
<Link href={"/"} className="flex items-center gap-4">
|
|
|
|
<Image
|
|
|
|
className="rounded-full"
|
2023-05-26 14:56:29 +03:00
|
|
|
src={"/logo.png"}
|
2023-05-18 14:37:03 +03:00
|
|
|
alt="Quivr Logo"
|
|
|
|
width={48}
|
|
|
|
height={48}
|
|
|
|
/>
|
|
|
|
<h1 className="font-bold">Quivr</h1>
|
|
|
|
</Link>
|
2023-05-24 09:20:55 +03:00
|
|
|
<NavItems className="hidden sm:flex" />
|
|
|
|
<MobileMenu />
|
2023-05-18 14:37:03 +03:00
|
|
|
</nav>
|
2023-05-23 14:07:44 +03:00
|
|
|
</motion.header>
|
2023-05-18 14:37:03 +03:00
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
export default NavBar;
|