Files
webb/src/components/ui/Navbar.tsx
T

288 lines
13 KiB
TypeScript

'use client';
import React, { useState, useEffect } from 'react';
import Link from 'next/link';
import { usePathname } from 'next/navigation';
import {
Menu,
X,
Smartphone,
Layers,
ArrowUpRight,
Home,
ChevronRight,
Wrench,
Sparkles,
ShieldCheck
} from 'lucide-react';
import { SiteConfig, resolveLocalised } from '@/types';
import { BrandLogo } from './BrandLogo';
interface NavbarProps {
config: SiteConfig;
currentLocale: string;
}
export function Navbar({ config, currentLocale }: NavbarProps) {
const [isScrolled, setIsScrolled] = useState(false);
const [mobileMenuOpen, setMobileMenuOpen] = useState(false);
const pathname = usePathname();
useEffect(() => {
let lastScrolled = window.scrollY > 20;
if (lastScrolled !== isScrolled) {
setIsScrolled(lastScrolled);
}
const handleScroll = () => {
const nextScrolled = window.scrollY > 20;
if (nextScrolled !== lastScrolled) {
lastScrolled = nextScrolled;
setIsScrolled(nextScrolled);
}
};
window.addEventListener('scroll', handleScroll, { passive: true });
return () => window.removeEventListener('scroll', handleScroll);
}, []);
// Close mobile menu on Escape key
useEffect(() => {
if (!mobileMenuOpen) return;
const closeOnEscape = (event: KeyboardEvent) => {
if (event.key === 'Escape') setMobileMenuOpen(false);
};
document.addEventListener('keydown', closeOnEscape);
return () => document.removeEventListener('keydown', closeOnEscape);
}, [mobileMenuOpen]);
// Lock body scroll on iOS/Mobile when mobile menu is open to prevent background bleed/scroll
useEffect(() => {
if (mobileMenuOpen) {
document.body.style.overflow = 'hidden';
document.body.style.touchAction = 'none';
} else {
document.body.style.overflow = '';
document.body.style.touchAction = '';
}
return () => {
document.body.style.overflow = '';
document.body.style.touchAction = '';
};
}, [mobileMenuOpen]);
return (
<header
className={`fixed top-0 left-0 right-0 w-full z-50 transition-colors duration-200 ${
mobileMenuOpen
? 'bg-[#FAF8F5] pointer-events-auto border-b border-slate-200/90 shadow-sm'
: 'pointer-events-none'
}`}
>
{/* 1. Ultra-Smooth High-Performance Gradient Blur Canopy (Active only when menu is closed) */}
{!mobileMenuOpen && (
<div className="absolute top-0 inset-x-0 h-16 sm:h-18 pointer-events-none overflow-hidden select-none">
<div
className="absolute inset-0 backdrop-blur-md"
style={{
maskImage: 'linear-gradient(to bottom, rgba(0,0,0,1) 0%, rgba(0,0,0,1) 70%, rgba(0,0,0,0) 100%)',
WebkitMaskImage: 'linear-gradient(to bottom, rgba(0,0,0,1) 0%, rgba(0,0,0,1) 70%, rgba(0,0,0,0) 100%)',
}}
/>
<div
className="absolute inset-0 bg-gradient-to-b from-[#FAF8F5] via-[#FAF8F5]/90 to-transparent pointer-events-none"
/>
</div>
)}
{/* 2. Top Prismatic Micro-Highlight */}
{!mobileMenuOpen && (
<div className="absolute top-0 inset-x-0 h-[1px] bg-gradient-to-r from-transparent via-white/80 to-transparent pointer-events-none z-30" />
)}
{/* 3. Main Aligned Edge-to-Edge Navigation Bar */}
<div className="relative z-30 pointer-events-auto py-3 sm:py-3.5">
<div className="max-w-[1640px] mx-auto px-4 sm:px-6 lg:px-10 flex items-center justify-between">
{/* Brand Logo */}
<div className="relative z-20 flex-shrink-0">
<BrandLogo size="md" />
</div>
{/* Center Navigation Links - Protected Optical Floating Pill (Desktop only) */}
<nav className="hidden md:flex items-center gap-1 px-2 py-1 rounded-full bg-white/60 backdrop-blur-md border border-white/80 shadow-sm relative z-20">
{/* Dedicated Top Home Button */}
<Link
href="/"
aria-current={pathname === '/' ? 'page' : undefined}
className={`relative flex items-center gap-1.5 px-4 py-2 rounded-full text-xs font-bold tracking-wide transition-[background-color,color,box-shadow] duration-200 ease-[cubic-bezier(0.16,1,0.3,1)] ${
pathname === '/'
? 'text-blue-700 bg-white shadow-sm border border-slate-900/[0.06]'
: 'text-slate-800 hover:text-slate-950 hover:bg-white/60'
}`}
>
<Home className="w-3.5 h-3.5" />
<span>Home</span>
</Link>
{config.nav.header.map((item) => {
const active = pathname === item.href || (item.href !== '/' && pathname.startsWith(`${item.href}/`));
return (
<Link
key={item.href}
href={item.href}
aria-current={active ? 'page' : undefined}
className={`relative px-4 py-2 rounded-full text-xs font-bold tracking-wide transition-[background-color,color,box-shadow] duration-200 ease-[cubic-bezier(0.16,1,0.3,1)] ${
active
? 'text-blue-700 bg-white shadow-sm border border-slate-900/[0.06]'
: 'text-slate-800 hover:text-slate-950 hover:bg-white/60'
}`}
>
{resolveLocalised(item.label, currentLocale)}
</Link>
);
})}
{/* Direct Anchor to Studio Suite */}
<Link
href="/#studio-suite"
className="flex items-center gap-1.5 px-4 py-2 rounded-full text-xs font-bold tracking-wide text-blue-700 hover:text-blue-900 hover:bg-blue-50/70 transition-colors"
>
<Layers className="w-3.5 h-3.5 text-blue-600" />
<span>Creative Suite</span>
</Link>
</nav>
{/* Right CTA Button (Desktop only) */}
<div className="hidden md:flex items-center space-x-3 relative z-20 flex-shrink-0">
<Link
href={config.nav.cta.href}
className="group relative inline-flex items-center gap-1.5 lg:gap-2 px-3.5 py-2 lg:px-5 lg:py-2.5 rounded-full text-xs font-bold text-white bg-gradient-to-r from-blue-600 via-indigo-600 to-blue-600 hover:from-blue-700 hover:to-indigo-700 shadow-md shadow-blue-500/25 hover:shadow-lg hover:shadow-blue-500/35 transition-[transform,opacity,box-shadow] duration-300 ease-[cubic-bezier(0.16,1,0.3,1)] hover:scale-105 active:scale-95"
>
<Smartphone className="w-3.5 h-3.5 lg:w-4 lg:h-4 text-white group-hover:rotate-6 transition-transform" />
<span>{resolveLocalised(config.nav.cta.label, currentLocale)}</span>
<ArrowUpRight className="w-3.5 h-3.5 opacity-80 group-hover:translate-x-0.5 group-hover:-translate-y-0.5 transition-transform" />
</Link>
</div>
{/* Mobile Menu Trigger */}
<div className="flex md:hidden items-center space-x-2 relative z-20">
<button
onClick={() => setMobileMenuOpen(!mobileMenuOpen)}
className="p-2.5 rounded-xl text-slate-800 bg-white hover:bg-slate-50 border border-slate-200/90 shadow-sm transition-colors active:scale-95"
aria-label={mobileMenuOpen ? 'Close navigation menu' : 'Open navigation menu'}
aria-expanded={mobileMenuOpen}
aria-controls="mobile-navigation"
>
{mobileMenuOpen ? <X className="w-5 h-5 text-blue-600" /> : <Menu className="w-5 h-5" />}
</button>
</div>
</div>
</div>
{/* Mobile Solid Opaque Drawer (100% Solid Warm Canvas - Zero Transparency Bleed or Text Collision) */}
{mobileMenuOpen && (
<nav
id="mobile-navigation"
aria-label="Mobile navigation"
className="md:hidden fixed inset-x-0 top-[60px] sm:top-[68px] bottom-0 z-50 bg-[#FAF8F5] overflow-y-auto px-4 py-5 flex flex-col justify-between pointer-events-auto border-t border-slate-200/90 animate-in fade-in duration-200"
>
<div className="w-full max-w-md mx-auto space-y-2.5">
{/* Home Card */}
<Link
href="/"
onClick={() => setMobileMenuOpen(false)}
aria-current={pathname === '/' ? 'page' : undefined}
className={`flex items-center justify-between px-4 py-3.5 rounded-2xl text-sm font-semibold transition-all border ${
pathname === '/'
? 'text-blue-700 bg-white border-blue-200 shadow-sm'
: 'text-slate-800 bg-white hover:bg-slate-50 border-slate-200/80 shadow-xs'
}`}
>
<div className="flex items-center gap-3">
<div className="w-9 h-9 rounded-xl bg-blue-50 flex items-center justify-center text-blue-600">
<Home className="w-4 h-4" />
</div>
<span className="text-sm font-bold">Home</span>
</div>
<ChevronRight className="w-4 h-4 text-slate-400" />
</Link>
{/* Header Navigation Cards */}
{config.nav.header.map((item) => {
const active = pathname === item.href || (item.href !== '/' && pathname.startsWith(`${item.href}/`));
let Icon = Wrench;
let iconColor = 'text-indigo-600';
let iconBg = 'bg-indigo-50';
if (item.href.includes('app')) {
Icon = Smartphone;
iconColor = 'text-sky-600';
iconBg = 'bg-sky-50';
} else if (item.href.includes('pricing')) {
Icon = Sparkles;
iconColor = 'text-amber-600';
iconBg = 'bg-amber-50';
} else if (item.href.includes('trust')) {
Icon = ShieldCheck;
iconColor = 'text-emerald-600';
iconBg = 'bg-emerald-50';
}
return (
<Link
key={item.href}
href={item.href}
onClick={() => setMobileMenuOpen(false)}
aria-current={active ? 'page' : undefined}
className={`flex items-center justify-between px-4 py-3.5 rounded-2xl text-sm font-semibold transition-all border ${
active
? 'text-blue-700 bg-white border-blue-200 shadow-sm'
: 'text-slate-800 bg-white hover:bg-slate-50 border-slate-200/80 shadow-xs'
}`}
>
<div className="flex items-center gap-3">
<div className={`w-9 h-9 rounded-xl ${iconBg} flex items-center justify-center ${iconColor}`}>
<Icon className="w-4 h-4" />
</div>
<span className="text-sm font-bold">{resolveLocalised(item.label, currentLocale)}</span>
</div>
<ChevronRight className="w-4 h-4 text-slate-400" />
</Link>
);
})}
{/* Creative Suite Card */}
<Link
href="/#studio-suite"
onClick={() => setMobileMenuOpen(false)}
className="flex items-center justify-between px-4 py-3.5 rounded-2xl text-sm font-semibold text-blue-700 bg-blue-50/90 hover:bg-blue-100/90 border border-blue-200 transition-colors shadow-xs"
>
<div className="flex items-center gap-3">
<div className="w-9 h-9 rounded-xl bg-blue-600 text-white flex items-center justify-center shadow-xs">
<Layers className="w-4 h-4" />
</div>
<span className="text-sm font-bold">Creative Suite</span>
</div>
<ChevronRight className="w-4 h-4 text-blue-400" />
</Link>
</div>
{/* Bottom Primary Handoff Card */}
<div className="w-full max-w-md mx-auto pt-5 pb-3 border-t border-slate-200/90 mt-4 space-y-3">
<Link
href={config.nav.cta.href}
onClick={() => setMobileMenuOpen(false)}
className="flex items-center justify-center gap-2 w-full py-4 rounded-2xl text-sm font-bold text-white bg-gradient-to-r from-blue-600 via-indigo-600 to-blue-600 shadow-lg shadow-blue-500/25 active:scale-[0.98] transition-transform"
>
<Smartphone className="w-4 h-4" />
<span>{resolveLocalised(config.nav.cta.label, currentLocale)}</span>
<ArrowUpRight className="w-4 h-4 opacity-80" />
</Link>
<p className="text-center text-[11px] font-medium text-slate-500">
Zero Photo Retention • 100% Client-Side Privacy
</p>
</div>
</nav>
)}
</header>
);
}