import { cn } from "@/lib/utils"; import { AnimatePresence, motion, useScroll, useMotionValueEvent, } from "motion/react"; import { Cross as HamburgerCross } from "hamburger-react"; import { useEffect, useState } from "react"; function useWindowDimensions() { const hasWindow = typeof window !== "undefined"; function getWindowDimensions() { const width = hasWindow ? window.innerWidth : 0; const height = hasWindow ? window.innerHeight : 0; return { width, height, }; } const [windowDimensions, setWindowDimensions] = useState( getWindowDimensions(), ); useEffect(() => { if (hasWindow) { function handleResize() { setWindowDimensions(getWindowDimensions()); } window.addEventListener("resize", handleResize); return () => window.removeEventListener("resize", handleResize); } }, [hasWindow]); return windowDimensions; } export const HoverNavigation = ({ items, className, }: { items: { label: string; link: string; }[]; className?: string; }) => { const [hoveredIndex, setHoveredIndex] = useState(null); const { scrollYProgress } = useScroll(); const [navVisible, setNavVisible] = useState(true); const [availableVisible, setAvailableVisible] = useState(false); const [onContactPage, setOnContactPage] = useState(false); const [hamburgerOpen, setHamburgerOpen] = useState(false); const { width } = useWindowDimensions(); // if on contact page, do not do width 0% useEffect(() => { setOnContactPage(window.location.href.includes("/contact")); }, []); useEffect(() => { updateNavBarState(width); }, [width]); const updateNavBarState = ( width: number, scrollProgress: number = 0, scrollUp: boolean = false, ) => { if (width && width < 1024) { setNavVisible(false); setAvailableVisible(true); } else if (scrollProgress < 0.05) { setNavVisible(true); setAvailableVisible(false); } else if (!onContactPage) { setNavVisible(scrollUp); setAvailableVisible(!scrollUp); } else { setNavVisible(true); setAvailableVisible(false); } }; useMotionValueEvent(scrollYProgress, "change", (current) => { // Check if current is not undefined and is a number if (typeof current === "number") { let direction = current! - scrollYProgress.getPrevious()!; let scrollUp = direction <= 0; let scrollProgress = scrollYProgress.get(); updateNavBarState(width, scrollProgress, scrollUp); } }); return (
Ryan
Available for work
{items.map((item, idx) => ( setHoveredIndex(idx)} onMouseLeave={() => setHoveredIndex(null)} > {hoveredIndex === idx && ( )} {item.label} ))}
{items.map((item, idx) => ( {item.label} ))}
); }; export const NavBarLink = ({ className, children, }: { className?: string; children: React.ReactNode; }) => { return (
{children}
); };