-
Notifications
You must be signed in to change notification settings - Fork 1.4k
/
Copy pathsidebar.tsx
123 lines (118 loc) · 3.4 KB
/
sidebar.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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
'use client';
import clsx from 'clsx';
import { usePathname } from 'next/navigation';
import Link from 'next/link';
import { LayoutGroup, motion } from 'framer-motion';
const navItems = {
'/': {
name: 'home',
},
'/about': {
name: 'about',
},
'/blog': {
name: 'blog',
},
'/guestbook': {
name: 'guestbook',
},
};
function Logo() {
return (
<Link aria-label="Lee Robinson" href="/">
<motion.svg
className="text-black dark:text-white h-[25px] md:h-[37px]"
width="25"
height="37"
viewBox="0 0 232 316"
fill="none"
xmlns="http://www.w3.org/2000/svg"
>
<motion.path
initial={{
opacity: 0,
pathLength: 0,
}}
animate={{
opacity: 1,
pathLength: 1,
}}
transition={{
duration: 0.5,
type: 'spring',
stiffness: 50,
}}
d="M39 316V0"
stroke="currentColor"
strokeWidth={78}
/>
<motion.path
initial={{ x: -200, opacity: 0 }}
animate={{ x: 0, opacity: 1 }}
transition={{
duration: 0.5,
type: 'spring',
stiffness: 50,
}}
d="M232 314.998H129.852L232 232.887V314.998Z"
fill="currentColor"
/>
</motion.svg>
</Link>
);
}
export default function Navbar() {
let pathname = usePathname() || '/';
if (pathname.includes('/blog/')) {
pathname = '/blog';
}
return (
<aside className="md:w-[150px] md:flex-shrink-0 -mx-4 md:mx-0 md:px-0 font-serif">
<div className="lg:sticky lg:top-20">
<div className="ml-2 md:ml-[12px] mb-2 px-4 md:px-0 md:mb-8 space-y-10 flex flex-col md:flex-row items-start ">
<Logo />
</div>
<LayoutGroup>
<nav
className="flex flex-row md:flex-col items-start relative px-4 md:px-0 pb-0 fade md:overflow-auto scroll-pr-6 md:relative"
id="nav"
>
<div className="flex flex-row md:flex-col space-x-0 pr-10 mb-2 mt-2 md:mt-0">
{Object.entries(navItems).map(([path, { name }]) => {
const isActive = path === pathname;
return (
<Link
key={path}
href={path}
className={clsx(
'transition-all hover:text-neutral-800 dark:hover:text-neutral-200 flex align-middle',
{
'text-neutral-500': !isActive,
'font-bold': isActive,
}
)}
>
<span className="relative py-[5px] px-[10px]">
{name}
{path === pathname ? (
<motion.div
className="absolute inset-0 bg-neutral-100 dark:bg-neutral-800 rounded-md z-[-1]"
layoutId="sidebar"
transition={{
type: 'spring',
stiffness: 350,
damping: 30,
}}
/>
) : null}
</span>
</Link>
);
})}
</div>
</nav>
</LayoutGroup>
</div>
</aside>
);
}