From 773085b2e08a67f724459beb4cb29d7be718abf8 Mon Sep 17 00:00:00 2001 From: Timothy Pidashev Date: Mon, 18 Mar 2024 22:56:35 -0700 Subject: [PATCH] Stagger tabs on animate --- src/web/src/components/header.jsx | 86 +++++++++++++++++-------------- 1 file changed, 47 insertions(+), 39 deletions(-) diff --git a/src/web/src/components/header.jsx b/src/web/src/components/header.jsx index 07ded97..b1985e6 100644 --- a/src/web/src/components/header.jsx +++ b/src/web/src/components/header.jsx @@ -2,7 +2,7 @@ import ThemeToggle from "@/components/theme-toggle" import Link from "next/link"; -import { motion } from "framer-motion"; +import { motion, AnimatePresence } from "framer-motion"; import { useState, useEffect } from "react"; @@ -30,46 +30,54 @@ function Header() { setMounted(true); }, []); - if (!mounted) { - return ( -
- {tabs.map((tab) => ( -
- {/* Placeholder for each tab */} -
- ))} -
- ); - } - return (
-
- {tabs.map((tab) => ( - - setActiveTab(tab.id)} - className={`${ - activeTab === tab.id ? "" : "hover:text-white/60" - } relative rounded-full px-3 py-1.5 text-sm text-light-foreground dark:text-dark-foreground transition-all focus-visible:outline-2`} - style={{ - WebkitTapHighlightColor: "transparent", - }} - > - {activeTab === tab.id && ( - - )} - {tab.label} - - - ))} - -
+ + {mounted && ( + + {tabs.map((tab, index) => ( + + setActiveTab(tab.id)} + className={`${ + activeTab === tab.id ? "" : "" + } relative rounded-full px-3 py-1.5 text-sm text-light-foreground dark:text-dark-foreground transition-all focus-visible:outline-2`} + style={{ + WebkitTapHighlightColor: "transparent", + }} + variants={{ + visible: { opacity: 1, x: 0 }, + hidden: { opacity: 0, x: -50 } + }} + transition={{ duration: 0.3 }} + > + {activeTab === tab.id && ( + + )} + {tab.label} + + + ))} + + )} +
); }