import SectionContainer from '~/components/Layouts/SectionContainer' import { isBrowser } from 'common' import { ArrowUpRight, ChevronDown } from 'lucide-react' import Link from 'next/link' import React, { FC, useEffect, useRef, useState } from 'react' import { Button, cn, DropdownMenu, DropdownMenuContent, DropdownMenuItem, DropdownMenuTrigger, } from 'ui' import { mainDays, WeekDayProps } from './data' const LWXStickyNav: FC = () => { const days = mainDays() const [activeNavItem, setActiveNavItem] = useState('Mon') const OFFSET = 66 const anchors = useRef | null>(null) const links = useRef | null>(null) const handleScroll = () => { let newActiveAnchor: string = '' anchors.current?.forEach((anchor) => { const { y: offsetFromTop } = anchor.getBoundingClientRect() if (offsetFromTop - OFFSET < 0) { newActiveAnchor = anchor.id // Set the active nav item based on the anchor ID const matchingDay = days.find((day) => day.id === newActiveAnchor) if (matchingDay) { setActiveNavItem(matchingDay.dd) } else if (newActiveAnchor === 'build-stage') { setActiveNavItem('Build Stage') } } }) links.current?.forEach((link) => { link.classList.remove('text-foreground!') const sanitizedHref = decodeURI(link.getAttribute('href') ?? '') .split('#') .splice(-1) .join('') const isMatch = sanitizedHref === newActiveAnchor if (isMatch) { link.classList.add('text-foreground!') } }) } useEffect(() => { if (!isBrowser) return anchors.current = document.querySelectorAll('.lw-nav-anchor') links.current = document.querySelectorAll('.lw-sticky-nav li a') window.addEventListener('scroll', handleScroll) return () => { window.removeEventListener('scroll', handleScroll) } }, []) return (
) } export default LWXStickyNav