-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathMainNavigator.tsx
More file actions
111 lines (102 loc) · 3.34 KB
/
MainNavigator.tsx
File metadata and controls
111 lines (102 loc) · 3.34 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
import { observer } from 'mobx-react';
import dynamic from 'next/dynamic';
import { useRouter } from 'next/router';
import { AnchorHTMLAttributes, FC, useContext } from 'react';
import { Container, Image, Nav, Navbar, NavDropdown } from 'react-bootstrap';
import { DefaultImage } from '../../models/configuration';
import { i18n, I18nContext } from '../../models/Translation';
const LanguageMenu = dynamic(() => import('./LanguageMenu'), { ssr: false });
export interface MenuItem extends Pick<AnchorHTMLAttributes<HTMLAnchorElement>, 'href' | 'title'> {
subs?: MenuItem[];
}
const topNavBarMenu = ({ t }: typeof i18n): MenuItem[] => [
{
title: t('about'),
subs: [
{ href: '/article/about', title: t('about') },
{ href: '/article/history', title: t('history') },
{ href: '/article/code-of-conduct', title: t('code_of_conduct') },
],
},
{
title: t('join_us'),
subs: [
{ href: '/article/join-us', title: t('join_us') },
{
href: '/article/open-collaborator-award',
title: t('open_collaborator_award'),
},
{ href: '/volunteer', title: t('volunteer') },
],
},
{
title: t('open_source_projects'),
subs: [
{ href: '/project', title: t('open_source_projects') },
{ href: '/issue', title: 'GitHub issues' },
{
href: 'https://github.com/Open-Source-Bazaar/Git-Hackathon-scaffold',
title: t('hackathon'),
},
{ href: '/license-filter', title: t('license_filter') },
],
},
{
title: t('wiki'),
subs: [
{ href: '/wiki', title: t('wiki') },
{ href: '/policy', title: t('policy') },
],
},
{
title: t('china_public_interest_map'),
subs: [
{ href: '/organization', title: t('china_public_interest_map') },
{ href: '/organization/landscape', title: t('china_public_interest_landscape') },
],
},
];
export interface MainNavigatorProps {
menu?: MenuItem[];
}
export const MainNavigator: FC<MainNavigatorProps> = observer(({ menu }) => {
const { pathname } = useRouter(),
i18n = useContext(I18nContext);
const { t } = i18n;
menu ||= topNavBarMenu(i18n);
return (
<Navbar bg="dark" variant="dark" fixed="top" expand="lg">
<Container>
<Navbar.Brand href="/" className="fw-bolder d-flex align-items-center gap-2">
<Image width={40} src={DefaultImage} alt={t('open_source_bazaar')} />
{t('open_source_bazaar')}
</Navbar.Brand>
<Navbar.Toggle aria-controls="navbarScroll" />
<Navbar.Collapse id="navbarScroll">
<Nav className="me-auto my-2 my-lg-0" navbarScroll>
{menu.map(({ href, title, subs }) =>
subs ? (
<NavDropdown key={title} title={title}>
{subs.map(({ href, title }) => (
<NavDropdown.Item key={href} href={href}>
{title}
</NavDropdown.Item>
))}
</NavDropdown>
) : (
<Nav.Link
key={`${href}-${title}`}
href={href}
className={pathname === `${href}` ? 'fw-bolder text-light' : ''}
>
{title}
</Nav.Link>
),
)}
</Nav>
<LanguageMenu />
</Navbar.Collapse>
</Container>
</Navbar>
);
});