@@ -4,37 +4,40 @@ import { motion, useScroll } from "framer-motion";
44import { cn } from "@/lib/utils" ;
55import { useEffect , useRef , useState } from "react" ;
66import { useNavigate , useLocation } from "react-router" ;
7- import {
8- Sheet ,
9- SheetClose ,
10- SheetContent ,
11- SheetFooter ,
12- SheetHeader ,
13- SheetTitle ,
14- SheetTrigger ,
15- } from "./ui/sheet" ;
16- import { X } from "lucide-react" ;
7+ import { FolderOpenDot , User } from "lucide-react" ;
178import simonIcon from "@/assets/simon-icon.png" ;
189
1910export function Header ( ) {
2011 const [ isScrolled , setIsScrolled ] = useState ( false ) ;
2112 const [ isVisible , setIsVisible ] = useState ( true ) ;
2213 const { scrollY } = useScroll ( ) ;
2314 const lastScrollY = useRef ( 0 ) ;
15+ const lastVisibilityChangeY = useRef ( 0 ) ;
2416 const navigate = useNavigate ( ) ;
2517 const location = useLocation ( ) ;
2618
2719 useEffect ( ( ) => {
2820 return scrollY . on ( "change" , ( latest ) => {
2921 const isScrolledNow = latest > 50 ;
3022 const isScrollingDown = latest > lastScrollY . current ;
23+ const scrollDelta = latest - lastVisibilityChangeY . current ;
3124
3225 // Always show header when near top
3326 if ( ! isScrolledNow ) {
3427 setIsVisible ( true ) ;
28+ lastVisibilityChangeY . current = latest ;
3529 } else {
36- // When scrolled, show on scroll up, hide on scroll down
37- setIsVisible ( ! isScrollingDown ) ;
30+ // When scrolling up, show immediately
31+ if ( ! isScrollingDown ) {
32+ setIsVisible ( true ) ;
33+ lastVisibilityChangeY . current = latest ;
34+ } else {
35+ // When scrolling down, only hide after 50px delay
36+ if ( scrollDelta >= 50 ) {
37+ setIsVisible ( false ) ;
38+ lastVisibilityChangeY . current = latest ;
39+ }
40+ }
3841 }
3942
4043 setIsScrolled ( isScrolledNow ) ;
@@ -72,7 +75,7 @@ export function Header() {
7275 className = { cn (
7376 "mx-auto rounded-full transition-colors max-w-5xl flex justify-between items-center mx-auto" ,
7477 isScrolled
75- ? "bg-card shadow-lg backdrop-blur-lg supports-[backdrop-filter]:bg-card /50"
78+ ? "bg-card shadow-lg backdrop-blur-lg supports-[backdrop-filter]:bg-input /50"
7679 : "bg-transparent"
7780 ) }
7881 animate = { {
@@ -89,100 +92,25 @@ export function Header() {
8992 </ Button >
9093
9194 < nav className = "flex items-center" >
92- < div className = "hidden md:flex" >
93- < Button
94- variant = "ghost"
95- onClick = { ( e ) => handleClick ( "projects" , e ) }
96- >
97- Projects
98- </ Button >
99- < Button variant = "ghost" onClick = { ( e ) => handleClick ( "about" , e ) } >
100- About
101- </ Button >
102- < Button
103- variant = "ghost"
104- onClick = { ( e ) => handleClick ( "contact" , e ) }
105- >
106- Contact
107- </ Button >
108- </ div >
95+ < Button
96+ variant = "ghost"
97+ size = "icon"
98+ onClick = { ( e ) => handleClick ( "projects" , e ) }
99+ >
100+ < FolderOpenDot />
101+ </ Button >
102+ < Button
103+ variant = "ghost"
104+ size = "icon"
105+ onClick = { ( e ) => handleClick ( "about" , e ) }
106+ >
107+ < User />
108+ </ Button >
109109
110- < div className = "flex items-center" >
111- < ModeToggle />
112- < Sheet >
113- < SheetTrigger asChild className = "md:hidden" >
114- < Button variant = "ghost" size = "icon" >
115- < MenuIcon className = "h-6 w-6" />
116- </ Button >
117- </ SheetTrigger >
118- < SheetContent side = "right" >
119- < SheetHeader >
120- < SheetTitle >
121- < img
122- src = { simonIcon }
123- alt = "Simon Manzler"
124- className = "h-6 w-6"
125- />
126- </ SheetTitle >
127- </ SheetHeader >
128- < div className = "flex flex-col" >
129- < Button
130- variant = "link"
131- className = "justify-start"
132- onClick = { ( e ) => handleClick ( "projects" , e ) }
133- >
134- Projects
135- </ Button >
136- < Button
137- variant = "link"
138- className = "justify-start"
139- onClick = { ( e ) => handleClick ( "about" , e ) }
140- >
141- About
142- </ Button >
143- < Button
144- variant = "link"
145- className = "justify-start"
146- onClick = { ( e ) => handleClick ( "contact" , e ) }
147- >
148- Contact
149- </ Button >
150- </ div >
151- < SheetFooter >
152- < SheetClose asChild >
153- < Button variant = "ghost" >
154- < X className = "h-6 w-6" />
155- Close
156- </ Button >
157- </ SheetClose >
158- </ SheetFooter >
159- </ SheetContent >
160- </ Sheet >
161- </ div >
110+ < ModeToggle />
162111 </ nav >
163112 </ motion . div >
164113 </ div >
165114 </ motion . header >
166115 ) ;
167116}
168-
169- function MenuIcon ( props : React . SVGProps < SVGSVGElement > ) {
170- return (
171- < svg
172- { ...props }
173- xmlns = "http://www.w3.org/2000/svg"
174- width = "24"
175- height = "24"
176- viewBox = "0 0 24 24"
177- fill = "none"
178- stroke = "currentColor"
179- strokeWidth = "2"
180- strokeLinecap = "round"
181- strokeLinejoin = "round"
182- >
183- < line x1 = "4" x2 = "20" y1 = "12" y2 = "12" />
184- < line x1 = "4" x2 = "20" y1 = "6" y2 = "6" />
185- < line x1 = "4" x2 = "20" y1 = "18" y2 = "18" />
186- </ svg >
187- ) ;
188- }
0 commit comments