-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathheader.tsx
65 lines (60 loc) · 2.52 KB
/
header.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
"use client";
import React from "react";
import { motion } from "framer-motion";
import { links } from "@/lib/data";
import Link from "next/link";
import clsx from "clsx";
import { useActiveSectionContext } from "@/context/active-section-context";
export default function Header() {
const { activeSection, setActiveSection, setTimeOfLastClick } =
useActiveSectionContext();
return (
<header className="z-[999] relative">
<motion.div
className="fixed top-0 left-1/2 h-[4.5rem] w-full rounded-none border border-white border-opacity-40 bg-white bg-opacity-80 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-950 dark:border-black/40 dark:bg-opacity-75"
initial={{ y: -100, x: "-50%", opacity: 0 }}
animate={{ y: 0, x: "-50%", opacity: 1 }}
></motion.div>
<nav className="flex fixed top-[0.15rem] left-1/2 h-12 -translate-x-1/2 py-2 sm:top-[1.7rem] sm:h-[initial] sm:py-0">
<ul className="flex w-[22rem] flex-wrap items-center justify-center gap-y-1 text-[0.9rem] font-medium text-gray-500 sm:w-[initial] sm:flex-nowrap sm:gap-5">
{links.map((link) => (
<motion.li
className="h-3/4 flex items-center justify-center relative"
key={link.hash}
initial={{ y: -100, opacity: 0 }}
animate={{ y: 0, opacity: 1 }}
>
<Link
className={clsx(
"flex w-full items-center justify-center px-3 py-3 hover:text-gray-950 transition dark:text-gray-500 dark:hover:text-gray-300",
{
"text-gray-950 dark:text-gray-200":
activeSection === link.name,
}
)}
href={link.hash}
onClick={() => {
setActiveSection(link.name);
setTimeOfLastClick(Date.now());
}}
>
{link.name}
{link.name === activeSection && (
<motion.span
className="bg-gray-100 rounded-full absolute inset-0 -z-10 dark:bg-gray-800"
layoutId="activeSection"
transition={{
type: "spring",
stiffness: 380,
damping: 30,
}}
></motion.span>
)}
</Link>
</motion.li>
))}
</ul>
</nav>
</header>
);
}