Skip to content

Commit af19532

Browse files
Improvements to the navbar/header
1 parent 4a08730 commit af19532

File tree

5 files changed

+60
-15
lines changed

5 files changed

+60
-15
lines changed

package-lock.json

Lines changed: 16 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
"firebase": "^11.0.1",
1515
"react": "^18.3.1",
1616
"react-dom": "^18.3.1",
17+
"react-intersection-observer": "^9.13.1",
1718
"react-router-dom": "^6.27.0"
1819
},
1920
"devDependencies": {

src/App.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import AuthPage from './pages/AuthPage'
44
import { ROUTE_URL } from './others/Globals'
55

66
const browserRouter = createBrowserRouter([
7-
{ path: ROUTE_URL.HOME, element: <HomePage/> },
7+
{ path: ROUTE_URL.HOME, element: <HomePage /> },
88
{ path: ROUTE_URL.AUTH, element: <AuthPage /> }
99
])
1010

src/common/Globals.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
const Utils = {
2+
lerp(a: number, b: number, t: number): number {
3+
return a + (b - a) * t
4+
}
5+
}
6+
7+
export default Utils

src/components/Navbar.tsx

Lines changed: 35 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,56 @@
1-
import React from 'react'
1+
import React, { useEffect, useRef } from 'react'
22
import { Link } from 'react-router-dom'
33
import { ROUTE_URL } from '../others/Globals'
44
import company_logo from '../assets/images/company_logo.png'
55

66
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+
}, [])
821

922
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'
1328
>
1429
{/* ----- 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="" />
1631

1732
{/* --- SMALL NAVBAR | HIDES WHEN SCREEN EXPANDS ---- */}
1833
<nav className='flex justify-between md:hidden'>
1934
<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>
2338
</button>
2439
</nav>
2540

2641
{/* --- 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>
3249
</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>
3354
</header>
3455
)
3556
}

0 commit comments

Comments
 (0)