-
Notifications
You must be signed in to change notification settings - Fork 394
/
index.tsx
265 lines (253 loc) Β· 7.96 KB
/
index.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
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
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
import cn from 'classnames'
import React, {
useEffect,
useState,
useCallback,
MouseEvent,
KeyboardEvent
} from 'react'
import HamburgerIcon from '../HamburgerIcon'
import Link from '../Link'
import { logEvent } from '../../utils/front/ga'
import { getFirstPage } from '../../utils/shared/sidebar'
import { ReactComponent as LogoSVG } from '../../../static/img/logo-white.svg'
import { ReactComponent as TwitterIcon } from '../SocialIcon/twitter.svg'
import { ReactComponent as GithubIcon } from '../SocialIcon/github.svg'
import styles from './styles.module.css'
const docsPage = getFirstPage()
export type HamburgerHelpers = {
opened: boolean
setOpened: (newState: boolean) => void
handleToggle: () => void
handleKeyDown: (e: KeyboardEvent) => void
handleClose: () => void
handleItemClick: (name: string) => (e: MouseEvent) => void
}
export const useHamburgerMenu: () => HamburgerHelpers = () => {
const [opened, setOpened] = useState(false)
const handleToggle = useCallback(() => setOpened(!opened), [opened])
const handleKeyDown = useCallback(e => {
if (e.which === 13) {
handleToggle()
}
}, [])
const handleClose = useCallback(() => setOpened(false), [opened])
const handleItemClick = useCallback(
item => (): void => {
close()
logEvent('hamburger', item)
},
[]
)
useEffect(() => {
const method = opened ? 'add' : 'remove'
document.body.classList[method](styles.hiddenScrollbar)
}, [opened])
return {
opened,
setOpened,
handleToggle,
handleKeyDown,
handleClose,
handleItemClick
}
}
export const HamburgerMenu: React.FC<
Pick<
HamburgerHelpers,
'opened' | 'handleItemClick' | 'handleKeyDown' | 'handleToggle'
> & {
collapsed: boolean
}
> = ({ opened, handleItemClick }) => {
return (
<div className={cn(styles.wrapper, opened && styles.opened)}>
<div className={styles.logoRow}>
<Link href="/" className={styles.logo} aria-label="Home">
<LogoSVG />
</Link>
</div>
<ul className={styles.sections}>
<li className={styles.section}>
<Link
href="/features"
className={styles.sectionLink}
onClick={handleItemClick('features')}
>
Features
</Link>
</li>
<li className={styles.section}>
<Link
href={docsPage}
className={styles.sectionLink}
onClick={handleItemClick('doc')}
>
Doc
</Link>
</li>
<li className={styles.section}>
<Link
href="/blog"
className={styles.sectionLink}
onClick={handleItemClick('blog')}
>
Blog
</Link>
</li>
<li className={styles.section}>
<Link
href="/community"
className={styles.sectionLink}
onClick={handleItemClick('community')}
>
Community
</Link>
<ul className={styles.subSections}>
<li className={styles.subSection}>
<Link
href="/community#meet"
className={styles.subSectionLink}
onClick={handleItemClick('community')}
>
<img
className={styles.subSectionLinkImage}
src="/img/community/icon-community.svg"
alt=""
/>
<span className={styles.subSectionLinkTitle}>Meet Us</span>
</Link>
</li>
<li className={styles.subSection}>
<Link
href="/community#contribute"
className={styles.subSectionLink}
onClick={handleItemClick('community')}
>
<img
className={styles.subSectionLinkImage}
src="/img/community/icon-contribute.svg"
alt=""
/>
<span className={styles.subSectionLinkTitle}>Contribute</span>
</Link>
</li>
<li className={styles.subSection}>
<Link
href="/community#learn"
className={styles.subSectionLink}
onClick={handleItemClick('community')}
>
<img
className={styles.subSectionLinkImage}
src="/img/community/icon-learn.svg"
alt=""
/>
<span className={styles.subSectionLinkTitle}>Learn</span>
</Link>
</li>
<li className={styles.subSection}>
<Link
href="/community#events"
className={styles.subSectionLink}
onClick={handleItemClick('community')}
>
<img
className={styles.subSectionLinkImage}
src="/img/community/icon-events.svg"
alt=""
/>
<span className={styles.subSectionLinkTitle}>Events</span>
</Link>
</li>
</ul>
</li>
<li className={styles.section}>
<Link
href="/support"
className={styles.sectionLink}
onClick={handleItemClick('support')}
>
Support
</Link>
<ul className={styles.subSections}>
<li className={styles.subSection}>
<Link
className={styles.subSectionLink}
href="mailto:[email protected]"
target="_blank"
onClick={handleItemClick('mail')}
>
<img
className={styles.subSectionLinkImage}
src="/img/community/icon-mail.svg"
alt=""
/>
<span className={styles.subSectionLinkTitle}>E-Mail</span>
</Link>
</li>
<li className={styles.subSection}>
<Link
className={styles.subSectionLink}
href="https://github.com/iterative/dvc"
onClick={handleItemClick('github')}
target="_blank"
>
<GithubIcon className={styles.subSectionLinkImage} />
<span className={styles.subSectionLinkTitle}>GitHub</span>
</Link>
</li>
<li className={styles.subSection}>
<Link
className={styles.subSectionLink}
href="/chat"
onClick={handleItemClick('chat')}
target="_blank"
>
<img
className={styles.subSectionLinkImage}
src="/img/community/icon-discord.svg"
alt=""
/>
<span className={styles.subSectionLinkTitle}>Discord</span>
</Link>
</li>
<li className={styles.subSection}>
<Link
className={styles.subSectionLink}
href="https://twitter.com/DVCorg"
onClick={handleItemClick('twitter')}
target="_blank"
>
<TwitterIcon className={styles.subSectionLinkImage} />
<span className={styles.subSectionLinkTitle}>Twitter</span>
</Link>
</li>
</ul>
</li>
</ul>
<Link
href="/doc/start"
className={styles.linkButton}
onClick={handleItemClick('get-started')}
>
Get started
</Link>
</div>
)
}
export const HamburgerButton: React.FC<{
opened: boolean
collapsed: boolean
handleClick: (e: MouseEvent) => void
handleKeyDown: (e: KeyboardEvent) => void
}> = ({ opened, collapsed, handleClick, handleKeyDown }) => (
<button
className={cn(styles.toggleButton, collapsed || styles.expanded)}
onClick={handleClick}
onKeyDown={handleKeyDown}
aria-label="Toggle Mobile Menu"
>
<HamburgerIcon opened={opened} />
</button>
)