-
-
Notifications
You must be signed in to change notification settings - Fork 229
/
Copy pathSiteMobileMenu.tsx
95 lines (92 loc) · 3.32 KB
/
SiteMobileMenu.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
import { useState } from "react"
import { CategoryWithEntries } from "@ourworldindata/utils"
import classnames from "classnames"
import { SiteNavigationToggle } from "./SiteNavigationToggle.js"
import { Menu } from "./SiteConstants.js"
import { SiteAbout } from "./SiteAbout.js"
import { SiteResources } from "./SiteResources.js"
import { SiteMobileCategory } from "./SiteMobileCategory.js"
export const SiteMobileMenu = ({
topics,
menu,
toggleMenu,
className,
}: {
topics: CategoryWithEntries[]
menu: Menu | null
toggleMenu: (menu: Menu) => void
className?: string
}) => {
const [activeCategory, setActiveCategory] =
useState<CategoryWithEntries | null>(null)
const toggleCategory = (category: CategoryWithEntries) => {
if (activeCategory === category) {
setActiveCategory(null)
} else {
setActiveCategory(category)
}
}
return (
<div className={classnames("SiteMobileMenu", className)}>
<ul>
<li>
<span className="section__header">Browse by topic</span>
<ul className="section__dropdown--topics">
{topics.map((category) => (
<SiteMobileCategory
key={category.slug}
category={category}
isActive={activeCategory === category}
toggleCategory={toggleCategory}
/>
))}
</ul>
</li>
<li>
<a href="/latest" className="section__header">
Latest
</a>
</li>
<li>
<SiteNavigationToggle
ariaLabel="Toggle resources menu"
isActive={menu === Menu.Resources}
onToggle={() =>
toggleMenu(
menu === Menu.Resources
? Menu.Topics
: Menu.Resources
)
}
dropdown={<SiteResources />}
withCaret={true}
className="SiteNavigationToggle--lvl1"
>
Resources
</SiteNavigationToggle>
</li>
<li>
<SiteNavigationToggle
ariaLabel="Toggle about menu"
isActive={menu === Menu.About}
onToggle={() =>
toggleMenu(
menu === Menu.About ? Menu.Topics : Menu.About
)
}
dropdown={<SiteAbout />}
withCaret={true}
className="SiteNavigationToggle--lvl1"
>
About
</SiteNavigationToggle>
</li>
<li>
<a href="/donate" className="donate">
Donate
</a>
</li>
</ul>
</div>
)
}