@@ -3,39 +3,82 @@ import Image from 'next/image';
33import Link from 'next/link' ;
44import Navbar from '@/components/elements/Navbar' ;
55import MobileDrawer from '@/components/elements/MobileDrawer' ;
6- import { useState } from 'react' ;
6+ import { useState , useEffect , useRef } from 'react' ;
77import { Bars3Icon } from '@heroicons/react/24/outline' ;
88import PillButton from '@/components/elements/PillButton' ;
99import LanguageSwitcher from '@/components/elements/LanguageSwitcher' ;
1010import { useLanguage } from '@/contexts/LanguageContext' ;
11- import headerConfig from '@/data/header.json ' ;
11+ import { headerConfig } from '@/data/headerConfig ' ;
1212
1313const Header = ( ) => {
1414 const [ isMenuOpen , setIsMenuOpen ] = useState ( false ) ;
15+ const [ useSmallLogo , setUseSmallLogo ] = useState ( false ) ;
1516 const { language } = useLanguage ( ) ;
17+ const headerRef = useRef ( null ) ;
18+
19+ useEffect ( ( ) => {
20+ const checkHeaderFit = ( ) => {
21+ if ( headerRef . current ) {
22+ const headerWidth = headerRef . current . offsetWidth ;
23+
24+ // Switch to small logo when header is getting tight
25+ // This threshold can be adjusted based on when overflow starts happening
26+ const shouldUseSmallLogo = headerWidth < 1200 && headerWidth > 700 ; // Adjust this value as needed
27+
28+ setUseSmallLogo ( shouldUseSmallLogo ) ;
29+ }
30+ } ;
31+
32+ // Use ResizeObserver for better performance
33+ const resizeObserver = new ResizeObserver ( checkHeaderFit ) ;
34+
35+ if ( headerRef . current ) {
36+ resizeObserver . observe ( headerRef . current ) ;
37+ }
38+
39+ // Initial check
40+ checkHeaderFit ( ) ;
41+
42+ return ( ) => {
43+ resizeObserver . disconnect ( ) ;
44+ } ;
45+ } , [ language ] ) ;
1646
1747 return (
1848 < header className = "sticky top-0 z-50 mt-0 px-3" >
1949 < div className = "bg-white container mx-auto flex items-center justify-between pt-5" >
20- < div className = "bg-gray-100 container mx-auto flex items-center justify-between p-5 rounded-2xl" >
50+ < div ref = { headerRef } className = "bg-gray-100 container mx-auto flex items-center justify-between p-5 rounded-2xl" >
2151
22- { /* Logo and other elements on the left */ }
23- < Link href = { headerConfig . logo . href } >
52+ { /* Logo - switches to small version when space is tight */ }
53+ < Link href = { headerConfig . logo . href } className = "flex-shrink-0 min-w-0 pr-6" >
2454 < Image
25- src = { headerConfig . logo . src }
26- width = { headerConfig . logo . width }
27- height = { headerConfig . logo . height }
55+ src = { useSmallLogo ? headerConfig . smallLogo . src : headerConfig . logo . src }
56+ width = { useSmallLogo ? headerConfig . smallLogo . width : headerConfig . logo . width }
57+ height = { useSmallLogo ? headerConfig . smallLogo . height : headerConfig . logo . height }
2858 alt = { headerConfig . logo . alt [ language ] }
2959 priority = { true }
60+ className = "max-w-full h-auto object-contain"
3061 />
3162 </ Link >
3263
3364 < div className = "flex flex-row items-center gap-4" >
3465 { /* Navigation (Desktop) on the right */ }
3566 < Navbar isMobile = { false } />
3667 < LanguageSwitcher className = "hidden md:flex" />
37- < PillButton className = "ml-3 hidden md:flex" href = { headerConfig . cta . href }
38- label = { headerConfig . cta . label [ language ] } />
68+ { useSmallLogo ? (
69+ < a
70+ href = { headerConfig . cta . href }
71+ target = "_blank"
72+ rel = "noopener noreferrer"
73+ className = "hidden md:flex p-2 hover:bg-gray-200 rounded-full"
74+ aria-label = { headerConfig . compactIcon . ariaLabel [ language ] }
75+ >
76+ < headerConfig . compactIcon . component className = { headerConfig . compactIcon . className } />
77+ </ a >
78+ ) : (
79+ < PillButton className = "ml-3 hidden md:flex" href = { headerConfig . cta . href }
80+ label = { headerConfig . cta . label [ language ] } />
81+ ) }
3982
4083 </ div >
4184 { /* Hamburger Menu (Mobile) */ }
0 commit comments