diff --git a/src/components/layout/Header.tsx b/src/components/layout/Header.tsx index 7cd87fe..b03eebc 100644 --- a/src/components/layout/Header.tsx +++ b/src/components/layout/Header.tsx @@ -9,6 +9,7 @@ import { HeroLogo } from "@/components/ui/HeroLogo"; export function Header() { const [menuOpen, setMenuOpen] = useState(false); const [scrolled, setScrolled] = useState(false); + const [activeSection, setActiveSection] = useState(""); useEffect(() => { function handleScroll() { @@ -18,6 +19,42 @@ export function Header() { return () => window.removeEventListener("scroll", handleScroll); }, []); + useEffect(() => { + const sectionIds = NAV_LINKS.map((l) => l.href.replace("#", "")); + const observers: IntersectionObserver[] = []; + + // Observe hero — when visible, clear active section + const hero = document.querySelector("section:first-of-type"); + if (hero) { + const heroObserver = new IntersectionObserver( + ([entry]) => { + if (entry.isIntersecting) setActiveSection(""); + }, + { rootMargin: "-20% 0px -70% 0px" }, + ); + heroObserver.observe(hero); + observers.push(heroObserver); + } + + sectionIds.forEach((id) => { + const el = document.getElementById(id); + if (!el) return; + + const observer = new IntersectionObserver( + ([entry]) => { + if (entry.isIntersecting) { + setActiveSection(id); + } + }, + { rootMargin: "-40% 0px -55% 0px" }, + ); + observer.observe(el); + observers.push(observer); + }); + + return () => observers.forEach((o) => o.disconnect()); + }, []); + return (
@@ -75,16 +119,23 @@ export function Header() { }`} >