diff --git a/hifi-src/src/components/Navbar.jsx b/hifi-src/src/components/Navbar.jsx index d6adbee..ac8a891 100644 --- a/hifi-src/src/components/Navbar.jsx +++ b/hifi-src/src/components/Navbar.jsx @@ -11,26 +11,37 @@ const SHOP_URL = 'https://www.audio4cars.de/'; const digitsOnly = (value) => (value || '').replace(/[^\d+]/g, ''); +const ITEM_DELAY_MS = 70; +const FLY_DURATION_MS = 500; + export default function Navbar() { const [open, setOpen] = useState(false); + const [mounted, setMounted] = useState(false); const [menuVisible, setMenuVisible] = useState(false); const { user } = useAuth(); const { phone, whatsapp } = useSiteSettings(); + const totalItems = whatsapp ? 8 : 7; useEffect(() => { - if (!open) { - setMenuVisible(false); - return; + if (open) { + setMounted(true); + const id = requestAnimationFrame(() => setMenuVisible(true)); + return () => cancelAnimationFrame(id); } - const id = requestAnimationFrame(() => setMenuVisible(true)); - return () => cancelAnimationFrame(id); - }, [open]); + setMenuVisible(false); + const closeDuration = FLY_DURATION_MS + (totalItems - 1) * ITEM_DELAY_MS; + const id = setTimeout(() => setMounted(false), closeDuration); + return () => clearTimeout(id); + }, [open, totalItems]); const flyIn = () => `transition-all duration-500 ease-out ${menuVisible ? 'opacity-100' : 'opacity-0'}`; - const flyInStyle = (index) => ({ - transitionDelay: `${index * 70}ms`, - transform: menuVisible ? 'translateY(0)' : 'translateY(-140px)', - }); + const flyInStyle = (index) => { + const delayIndex = menuVisible ? index : totalItems - 1 - index; + return { + transitionDelay: `${delayIndex * ITEM_DELAY_MS}ms`, + transform: menuVisible ? 'translateY(0)' : 'translateY(-140px)', + }; + }; const AdminIcon = user && (