Overview
TheHeader component is a fixed navigation bar that adapts its appearance based on scroll position and current route. It features a responsive design with a collapsible mobile menu and smooth transitions.
Features
- Scroll-Based Styling: Background becomes opaque with blur effect after scrolling 50px
- Route-Aware: Automatically adapts styling on the
/cotizacionpage - Responsive Design: Desktop horizontal menu and mobile hamburger menu
- Fixed Positioning: Stays at the top of the viewport for easy navigation
- Smooth Transitions: All state changes are animated with CSS transitions
Component Structure
The Header component is a client-side component that doesn’t accept any props.Navigation Structure
The header includes the following navigation links:- Inicio: Links to
/#inicio - Servicios: Links to
/#servicios - Planes: Links to
/#planes - Contacto: Links to
/#contacto
Implementation
Basic Usage
State Management
The component manages two internal states:scrolled: Tracks whether the user has scrolled more than 50pxmenuOpen: Controls the visibility of the mobile menu
Scroll Detection
The component uses an effect to listen for scroll events:Styling Behavior
Default State (Top of Page)
- Transparent background
- Larger padding (py-5)
- No shadow
Scrolled State
- Dark blue background with 95% opacity (
bg-[#001f3d]/95) - Backdrop blur effect
- Box shadow for depth
- Reduced padding (py-3)
On Cotizacion Page
The header automatically applies the scrolled styling when on the/cotizacion route:
Logo
The header displays the Seguros NAG logo:Mobile Menu
Toggle Button
The mobile menu is controlled by a hamburger button:Menu Animation
The mobile menu uses height and opacity transitions:Design Tokens
Colors
- Primary Background:
#001f3d(Dark Blue) - Hover Color:
#163594(Medium Blue) - Text: White
Breakpoints
- Mobile: Default
- Desktop:
md:(768px and up)
Accessibility
- Semantic HTML with
<header>and<nav>elements - Clear hover states for all interactive elements
- Mobile menu closes automatically when a link is clicked
Dependencies
The component uses Next.js’s
usePathname hook to detect the current route and Link component for client-side navigation.Source Code Location
/app/components/Header.tsx