|
1 |
| -import React from 'react' |
| 1 | +import React, { useEffect, useRef } from 'react' |
2 | 2 | import { Link } from 'react-router-dom'
|
3 | 3 | import { ROUTE_URL } from '../others/Globals'
|
4 | 4 | import company_logo from '../assets/images/company_logo.png'
|
5 | 5 |
|
6 | 6 | const Navbar: React.FC = () => {
|
7 |
| - const NAVBAR_HEIGHT_REM = 4 |
| 7 | + const headerRef = useRef<HTMLElement>(null) |
| 8 | + |
| 9 | + useEffect(() => { |
| 10 | + const scrollHandler = (_: any) => { |
| 11 | + const SCROLL_MIN = 300 |
| 12 | + const clamped = Math.max(0, Math.min(SCROLL_MIN, window.scrollY)) |
| 13 | + const t = Math.min(clamped / SCROLL_MIN, 0.95) |
| 14 | + if (headerRef.current?.style) { |
| 15 | + headerRef.current.style.backgroundColor = `rgba(127, 85, 170, ${t})` |
| 16 | + } |
| 17 | + } |
| 18 | + window.addEventListener('scroll', scrollHandler) |
| 19 | + return () => window.removeEventListener('scroll', scrollHandler) |
| 20 | + }, []) |
8 | 21 |
|
9 | 22 | return (
|
10 |
| - <header |
11 |
| - className='fixed top-0 left-0 right-0 z-10 flex justify-between pr-16 text-text-950' |
12 |
| - style={{ height: NAVBAR_HEIGHT_REM + "rem" }} |
| 23 | + <header |
| 24 | + ref={headerRef} |
| 25 | + className=' |
| 26 | + fixed top-0 left-0 right-0 z-10 flex justify-between items-center |
| 27 | + h-16 pr-4 md:pr-8 text-text-950 font-medium text-xl transition-colors' |
13 | 28 | >
|
14 | 29 | {/* ----- COMPANY LOGO ------ */}
|
15 |
| - <img src={company_logo} className='w-auto cursor-pointer' alt="" /> |
| 30 | + <img src={company_logo} className='h-full w-auto cursor-pointer' alt="" /> |
16 | 31 |
|
17 | 32 | {/* --- SMALL NAVBAR | HIDES WHEN SCREEN EXPANDS ---- */}
|
18 | 33 | <nav className='flex justify-between md:hidden'>
|
19 | 34 | <button className='h-full flex flex-col justify-center items-center gap-2 p-2'>
|
20 |
| - <div className='bg-black h-[2px] w-8'></div> |
21 |
| - <div className='bg-black h-[2px] w-8'></div> |
22 |
| - <div className='bg-black h-[2px] w-8'></div> |
| 35 | + <div className='bg-background-950 h-[2px] w-8'></div> |
| 36 | + <div className='bg-background-950 h-[2px] w-8'></div> |
| 37 | + <div className='bg-background-950 h-[2px] w-8'></div> |
23 | 38 | </button>
|
24 | 39 | </nav>
|
25 | 40 |
|
26 | 41 | {/* --- LARGE NAVBAR | SHOWS WHEN SCREEN EXPANDS ---- */}
|
27 |
| - <nav className='hidden md:flex justify-center items-center gap-8 font-medium text-lg'> |
28 |
| - <Link to={ROUTE_URL.HOME}>Home</Link> |
29 |
| - <Link to={ROUTE_URL.ABOUT}>About</Link> |
30 |
| - <Link to={ROUTE_URL.CONTACT_US}>Contact Us</Link> |
31 |
| - <Link to={ROUTE_URL.AUTH}>Login</Link> |
| 42 | + <nav className=' |
| 43 | + hidden md:flex justify-center items-center |
| 44 | + gap-14 lg:gap-24 |
| 45 | + '> |
| 46 | + <Link className='hover:text-accent-600 transition-colors' to={ROUTE_URL.HOME}>Home</Link> |
| 47 | + <Link className='hover:text-accent-600 transition-colors' to={ROUTE_URL.ABOUT}>About</Link> |
| 48 | + <Link className='hover:text-accent-600 transition-colors' to={ROUTE_URL.CONTACT_US}>Contact Us</Link> |
32 | 49 | </nav>
|
| 50 | + <Link className=' |
| 51 | + hidden justify-center items-center bg-primary-500 px-7 h-11 rounded-lg |
| 52 | + md:flex hover:bg-primary-600 transition-colors |
| 53 | + ' to={ROUTE_URL.AUTH}>Login</Link> |
33 | 54 | </header>
|
34 | 55 | )
|
35 | 56 | }
|
|
0 commit comments