Skip to content

Commit 54af68e

Browse files
committed
Stagger menu
1 parent dccb5c6 commit 54af68e

File tree

2 files changed

+36
-18
lines changed

2 files changed

+36
-18
lines changed

src/components/Layout/Header.component.tsx

+35-18
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,12 @@ import Link from "next/link";
55
import { usePathname } from "next/navigation";
66
import { motion } from "framer-motion";
77

8-
import { MotionDiv, MotionLi } from "@/lib/framer/client";
9-
import { useMobile } from "@/hooks/useMobile";
8+
import { MotionDiv, MotionLi, MotionUl } from "@/lib/framer/client";
109

1110
import MobileMenu from "./MobileMenu.component";
1211

1312
export default function Header() {
1413
const pathname = usePathname();
15-
const isMobile = useMobile();
1614

1715
const links = [
1816
{ title: "Home", name: "Hjem", hash: "#hjem", href: "/" },
@@ -36,25 +34,44 @@ export default function Header() {
3634
<header className="z-[999] relative">
3735
<MotionDiv
3836
className="bg-slate-800 bg-opacity-80 fixed top-0 left-1/2 h-[4.5rem] w-full shadow rounded-none shadow-lg shadow-black/[0.03] backdrop-blur-[0.5rem] sm:top-6 sm:h-[3.25rem] sm:w-[36rem] sm:rounded-full dark:bg-gray-900 dark:border-black/40 dark:bg-opacity-75"
39-
//initial={isMobile ? { x: 0 } : { y: -50, x: "-50%", opacity: 0 }}
40-
//animate={isMobile ? { x: 0 } : { y: 0, x: "-50%", opacity: 1 }}
41-
42-
initial={{ y: -50, x: "-50%", opacity: 0 }}
43-
animate={{ y: 0, x: "-50%", opacity: 1 }}
44-
transition={{ duration: 0.6 }}
45-
></MotionDiv>
46-
37+
initial={{ y: -100, x: "-50%", opacity: 0 }}
38+
animate={{
39+
y: 0,
40+
x: "-50%",
41+
opacity: 1,
42+
transition: {
43+
y: { duration: 0.6, ease: "easeOut" },
44+
opacity: { duration: 0.6, ease: "easeOut" },
45+
},
46+
}}
47+
/>
4748
<nav className="flex fixed top-[0.65rem] left-1/2 h-12 -translate-x-1/2 py-2 sm:top-[1.7rem] sm:h-[initial] sm:py-0 w-full max-w-[370px] justify-end md:justify-between items-center">
48-
<ul className="hidden md:flex md:w-[22rem] flex-wrap items-center justify-center gap-y-1 text-[0.9rem] font-medium text-slate-200 sm:w-[initial] sm:flex-nowrap sm:gap-5">
49+
<MotionUl
50+
className="hidden md:flex md:w-[22rem] flex-wrap items-center justify-center gap-y-1 text-[0.9rem] font-medium text-slate-200 sm:w-[initial] sm:flex-nowrap sm:gap-5"
51+
variants={{
52+
hidden: { opacity: 0 },
53+
visible: {
54+
opacity: 1,
55+
transition: {
56+
staggerChildren: 0.1,
57+
delayChildren: 0.3,
58+
},
59+
},
60+
}}
61+
initial="hidden"
62+
animate="visible"
63+
>
4964
{links.map((link) => (
5065
<MotionLi
5166
className="h-3/4 flex items-center justify-center relative"
5267
key={link.hash}
53-
initial={isMobile ? {} : { y: -50, opacity: 0 }}
54-
animate={isMobile ? {} : { y: 0, opacity: 1 }}
55-
transition={{ duration: 0.6 }}
68+
variants={{
69+
hidden: { y: -20, opacity: 0 },
70+
visible: { y: 0, opacity: 1 },
71+
}}
72+
transition={{ duration: 0.3 }}
5673
>
57-
<motion.div className="relative" whileHover="hover">
74+
<MotionDiv className="relative" whileHover="hover">
5875
<Link
5976
prefetch={true}
6077
className={`flex w-full items-center justify-center px-2 py-2 hover:text-white transition font-semibold text-lg ${
@@ -78,10 +95,10 @@ export default function Header() {
7895
/>
7996
</div>
8097
</Link>
81-
</motion.div>
98+
</MotionDiv>
8299
</MotionLi>
83100
))}
84-
</ul>
101+
</MotionUl>
85102
<div id="hamburger-div" data-cy="hamburger-div" className="md:hidden">
86103
<MobileMenu links={links} />
87104
</div>

src/lib/framer/client.ts

+1
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,4 @@ import { motion } from "framer-motion";
44

55
export const MotionDiv = motion.div;
66
export const MotionLi = motion.li;
7+
export const MotionUl = motion.ul;

0 commit comments

Comments
 (0)