-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathNavigation.jsx
More file actions
236 lines (223 loc) · 7.22 KB
/
Navigation.jsx
File metadata and controls
236 lines (223 loc) · 7.22 KB
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
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
import { useRef } from 'react'
import Link from 'next/link'
import { useRouter } from 'next/router'
import clsx from 'clsx'
import { AnimatePresence, motion } from 'framer-motion'
import { Button } from '@/components/Button'
import { useIsInsideMobileNavigation } from '@/components/MobileNavigation'
import { Tag } from '@/components/Tag'
function useInitialValue(value, condition = true) {
let initialValue = useRef(value).current
return condition ? initialValue : value
}
function TopLevelNavItem({ href, children }) {
return (
<li className="">
<Link
href={href}
className="block py-4 text-sm text-zinc-600 transition hover:text-zinc-900 dark:text-zinc-400 dark:hover:text-white"
>
{children}
</Link>
</li>
)
}
function NavLink({ href, tag, active, level = 0, children }) {
let leftPaddingClass = {
0: 'pl-0',
1: 'pl-4',
2: 'pl-4',
}[level] ?? 'pl-12'
return (
<Link
href={href}
aria-current={active ? 'page' : undefined}
className={clsx(
'flex justify-between gap-2 py-1 pr-3 text-sm transition',
leftPaddingClass,
active
? 'text-zinc-900 dark:text-white'
: 'text-zinc-600 hover:text-zinc-900 dark:text-zinc-400 dark:hover:text-white'
)}
>
<span className="truncate">{children}</span>
{tag && (
<Tag variant="small" color="zinc">
{tag}
</Tag>
)}
</Link>
)
}
function isLinkActive(link, pathname) {
if (link.href === pathname) {
return true
}
return (link.links ?? []).some((childLink) => isLinkActive(childLink, pathname))
}
function NavigationLinkItem({ link, pathname, level = 0 }) {
let isActive = isLinkActive(link, pathname)
return (
<motion.li layout="position" className="relative">
<NavLink href={link.href} active={isActive} level={level}>
{link.title}
</NavLink>
<AnimatePresence mode="popLayout" initial={false}>
{isActive && (link.links?.length ?? 0) > 0 && (
<motion.ul
role="list"
className={clsx(level === 0 && 'relative')}
initial={{ opacity: 0 }}
animate={{
opacity: 1,
transition: { delay: 0.1 },
}}
exit={{
opacity: 0,
transition: { duration: 0.15 },
}}
>
{level === 0 && (
<motion.div
layout
className="absolute inset-y-0 left-0 w-px bg-zinc-900/10 dark:bg-white/5"
/>
)}
{link.links.map((childLink) => (
<NavigationLinkItem
key={childLink.href}
link={childLink}
pathname={pathname}
level={level + 1}
/>
))}
</motion.ul>
)}
</AnimatePresence>
</motion.li>
)
}
function NavigationGroup({ group, className }) {
// If this is the mobile navigation then we always render the initial
// state, so that the state does not change during the close animation.
// The state will still update when we re-open (re-render) the navigation.
let isInsideMobileNavigation = useIsInsideMobileNavigation()
let router = useInitialValue(useRouter(), isInsideMobileNavigation)
return (
<li className={clsx('relative mt-6', className)}>
<motion.h2
layout="position"
className="text-xs font-semibold text-zinc-900 dark:text-white"
>
{group.href ? (
<a href={group.href}>{group.title}</a>
) : (
<span>{group.title}</span>
)}
</motion.h2>
<div className="relative mt-3">
<ul role="list" className="border-l border-transparent">
{group.links.map((link) => (
<NavigationLinkItem key={link.href} link={link} pathname={router.pathname} />
))}
</ul>
</div>
</li>
)
}
export const navigation = [
{
title: 'Documentation',
href: '/docs',
links: [
{ title: 'Introduction', href: '/docs/introduction' },
{ title: 'Install', href: '/docs/install' },
{ title: 'Advanced', href: '/docs/advanced' },
{ title: 'Ops ⛨', href: '/docs/ops' },
]
},
{
title: 'Quickstart',
href: '/docs/quickstart',
links: [
{
title: 'Node.js',
href: '/docs/secrets-for-nodejs',
links: [
{ title: 'Introduction', href: '/docs/secrets-for-nodejs' },
{ title: 'Express', href: '/docs/secrets-for-express' },
],
},
]
},
{
title: 'Ops ⛨',
href: '/docs/ops',
links: [
{ title: 'Install', href: '/docs/ops/install' },
{ title: 'Basics', href: '/docs/ops/quickstart' },
{ title: 'Advanced', href: '/docs/ops/advanced' },
]
},
{
title: 'Guides',
href: '/docs/guides',
links: [
{ title: 'Quickstart: Run', href: '/docs/quickstart/run' },
{ title: 'Quickstart: Environments', href: '/docs/quickstart/environments' },
{ title: 'Quickstart: Encrypt', href: '/docs/quickstart/encryption' },
{ title: 'Quickstart: Deploy', href: '/docs/quickstart/deploy' },
{ title: 'Digital Ocean', href: '/docs/platforms/digital-ocean' },
{ title: 'Docker', href: '/docs/platforms/docker' },
{ title: 'Docker Compose', href: '/docs/platforms/docker-compose' },
{ title: 'Fly', href: '/docs/platforms/fly' },
{ title: 'GitHub Actions', href: '/docs/cis/github-actions' },
{ title: 'Heroku', href: '/docs/platforms/heroku' },
{ title: 'Netlify', href: '/docs/platforms/netlify' },
{ title: 'NPM', href: '/docs/package-managers/npm' },
{ title: 'Nx', href: '/docs/monorepos/nx' },
{ title: 'Render', href: '/docs/platforms/render' },
{ title: 'Railway', href: '/docs/platforms/railway' },
{ title: 'Trigger', href: '/docs/background-jobs/triggerdotdev' },
{ title: 'Turborepo', href: '/docs/monorepos/turborepo' },
{ title: 'Vercel', href: '/docs/platforms/vercel' },
{ title: 'Cloudflare', href: '/docs/platforms/cloudflare' },
{ title: 'More', href: '/docs/guides' },
]
},
{
title: 'Resources',
links: [
{ title: '.env', href: '/docs/env-file' },
{ title: '.env.keys', href: '/docs/env-keys-file' },
{ title: 'Statistics', href: '/docs/stats' },
{ title: 'Deprecated', href: '/docs/deprecated' },
{ title: 'Chrome', href: 'https://dotenvx.com/chrome-extension' },
{ title: 'Heroku', href: 'https://github.com/dotenvx/heroku-buildpack-dotenvx' },
{ title: 'VSCode', href: 'https://dotenvx.com/vscode-extension' },
{ title: 'llms-full.txt', href: '/llms-full.txt' },
{ title: 'llms.txt', href: '/llms.txt' },
]
},
]
export function Navigation(props) {
return (
<nav {...props}>
<ul role="list">
{navigation.map((group, groupIndex) => (
<NavigationGroup
key={group.title}
href={group.href}
group={group}
className={groupIndex === 0 && 'md:mt-0'}
/>
))}
<li className="sticky bottom-0 z-10 mt-6 min-[416px]:hidden">
<Button href="#" variant="filled" className="w-full">
Sign in
</Button>
</li>
</ul>
</nav>
)
}