|
1 |
| -import useReadingProgress from '@/hooks/useReadingProgress' |
| 1 | +'use client' |
| 2 | + |
2 | 3 | import ThemeSwitch from './ThemeSwitch';
|
3 | 4 |
|
4 | 5 | const Navbar = () => {
|
5 |
| - const completion = useReadingProgress(); |
| 6 | + // const completion = useReadingProgress(); |
6 | 7 |
|
7 | 8 | return (
|
8 | 9 | <header className="sticky top-0 z-50 py-6 backdrop-blur-xl mx-auto max-w-full px-4 sm:px-12 md:px-16 lg:max-w-5xl xl:max-w-6xl 2xl:max-w-7xl">
|
9 |
| - <nav className="flex items-center justify-between"> |
10 |
| - <ul className="flex gap-4 sm:gap-8"> |
11 |
| - <li><a href="/" className="hover:underline hover:underline-offset-4">home</a></li> |
12 |
| - <li><a href="#experience" className="hover:underline hover:underline-offset-4">experience</a></li> |
13 |
| - {/* <li><a href="#education" className="hover:underline hover:underline-offset-4">education</a></li> */} |
14 |
| - <li><a href="#projects" className="hover:underline hover:underline-offset-4">projects</a></li> |
15 |
| - </ul> |
16 |
| - <div className="flex gap-0 sm:gap-4"> |
17 |
| - <ThemeSwitch /> |
18 |
| - </div> |
19 |
| - </nav> |
| 10 | + <nav className="flex items-center justify-between"> |
| 11 | + <ul className="flex gap-4 sm:gap-8" onClick={ |
| 12 | + (event: React.SyntheticEvent) => { |
| 13 | + event.preventDefault(); |
| 14 | + const target = event.target as HTMLAnchorElement; |
| 15 | + const id = target.getAttribute('href'); |
| 16 | + if (id !== "#") { |
| 17 | + const element = document.getElementById(String(id?.replace('#', ''))); |
| 18 | + const y = element && element.getBoundingClientRect().top + window.scrollY - 100; |
| 19 | + if (y !== null) { |
| 20 | + window.scrollTo({top: y, behavior: 'smooth'}); |
| 21 | + } else { |
| 22 | + element?.scrollIntoView({ |
| 23 | + behavior: 'smooth' |
| 24 | + }); |
| 25 | + } |
| 26 | + } else { |
| 27 | + window.scrollTo({ |
| 28 | + top: 0, |
| 29 | + behavior: 'smooth' |
| 30 | + }); |
| 31 | + } |
| 32 | + } |
| 33 | + }> |
| 34 | + <li><a href="#" className="hover:underline hover:underline-offset-4">home</a></li> |
| 35 | + <li><a href="#experience" className="hover:underline hover:underline-offset-4">experience</a></li> |
| 36 | + {/* <li><a href="#education" className="hover:underline hover:underline-offset-4">education</a></li> */} |
| 37 | + <li><a href="#projects" className="hover:underline hover:underline-offset-4">projects</a></li> |
| 38 | + </ul> |
| 39 | + <div className="flex gap-0 sm:gap-4"> |
| 40 | + <ThemeSwitch /> |
| 41 | + </div> |
| 42 | + </nav> |
20 | 43 | </header>
|
21 | 44 | )
|
22 | 45 | }
|
|
0 commit comments