1
1
import { observer } from 'mobx-react';
2
2
import dynamic from 'next/dynamic';
3
3
import { useRouter } from 'next/router';
4
- import { FC, useContext } from 'react';
5
- import { Container, Nav, Navbar } from 'react-bootstrap';
4
+ import { AnchorHTMLAttributes, FC, useContext } from 'react';
5
+ import { Container, Image, Nav, Navbar, NavDropdown } from 'react-bootstrap';
6
6
7
+ import { DefaultImage } from '../../models/configuration';
7
8
import { i18n, I18nContext } from '../../models/Translation';
8
9
9
10
const LanguageMenu = dynamic(() => import('./LanguageMenu'), { ssr: false });
10
11
11
- export type MenuItem = Record<'href' | 'name', string>;
12
+ export interface MenuItem extends Pick<AnchorHTMLAttributes<HTMLAnchorElement>, 'href' | 'title'> {
13
+ subs?: MenuItem[];
14
+ }
12
15
13
16
const topNavBarMenu = ({ t }: typeof i18n): MenuItem[] => [
14
- { href: '/article/about', name: t('about') },
15
- { href: '/article/history', name: t('history') },
16
- { href: '/article/code-of-conduct', name: t('code_of_conduct') },
17
- { href: '/article/join-us', name: t('join_us') },
18
17
{
19
- href: '/article/open-collaborator-award',
20
- name: t('open_collaborator_award'),
18
+ title: t('about'),
19
+ subs: [
20
+ { href: '/article/about', title: t('about') },
21
+ { href: '/article/history', title: t('history') },
22
+ { href: '/article/code-of-conduct', title: t('code_of_conduct') },
23
+ ],
24
+ },
25
+ {
26
+ title: t('join_us'),
27
+ subs: [
28
+ { href: '/article/join-us', title: t('join_us') },
29
+ {
30
+ href: '/article/open-collaborator-award',
31
+ title: t('open_collaborator_award'),
32
+ },
33
+ { href: '/volunteer', title: t('volunteer') },
34
+ ],
35
+ },
36
+ {
37
+ title: t('open_source_projects'),
38
+ subs: [
39
+ { href: '/project', title: t('open_source_projects') },
40
+ { href: '/issue', title: 'GitHub issues' },
41
+ {
42
+ href: 'https://github.com/Open-Source-Bazaar/Git-Hackathon-scaffold',
43
+ title: t('hackathon'),
44
+ },
45
+ { href: '/license-filter', title: t('license_filter') },
46
+ ],
21
47
},
22
- { href: '/volunteer', name: t('volunteer') },
23
- { href: '/project', name: t('open_source_projects') },
24
- { href: '/issue', name: 'GitHub issues' },
25
48
{
26
- href: 'https://github.com/Open-Source-Bazaar/Git-Hackathon-scaffold',
27
- name: t('hackathon'),
49
+ title: t('wiki'),
50
+ subs: [
51
+ { href: '/wiki', title: t('wiki') },
52
+ { href: '/policy', title: t('policy') },
53
+ ],
28
54
},
29
- { href: '/license-filter', name: t('license_filter') },
30
- { href: '/policy', name: t('policy') },
31
55
];
32
56
33
57
export interface MainNavigatorProps {
@@ -44,21 +68,32 @@ export const MainNavigator: FC<MainNavigatorProps> = observer(({ menu }) => {
44
68
return (
45
69
<Navbar bg="dark" variant="dark" fixed="top" expand="lg">
46
70
<Container>
47
- <Navbar.Brand href="/" className="fw-bolder">
71
+ <Navbar.Brand href="/" className="fw-bolder d-flex align-items-center gap-2">
72
+ <Image width={40} src={DefaultImage} alt={t('open_source_bazaar')} />
48
73
{t('open_source_bazaar')}
49
74
</Navbar.Brand>
50
75
<Navbar.Toggle aria-controls="navbarScroll" />
51
76
<Navbar.Collapse id="navbarScroll">
52
77
<Nav className="me-auto my-2 my-lg-0" navbarScroll>
53
- {menu.map(({ href, name }) => (
54
- <Nav.Link
55
- key={`${href}-${name}`}
56
- href={href}
57
- className={pathname === `${href}` ? 'fw-bolder text-light' : ''}
58
- >
59
- {name}
60
- </Nav.Link>
61
- ))}
78
+ {menu.map(({ href, title, subs }) =>
79
+ subs ? (
80
+ <NavDropdown key={title} title={title}>
81
+ {subs.map(({ href, title }) => (
82
+ <NavDropdown.Item key={href} href={href}>
83
+ {title}
84
+ </NavDropdown.Item>
85
+ ))}
86
+ </NavDropdown>
87
+ ) : (
88
+ <Nav.Link
89
+ key={`${href}-${title}`}
90
+ href={href}
91
+ className={pathname === `${href}` ? 'fw-bolder text-light' : ''}
92
+ >
93
+ {title}
94
+ </Nav.Link>
95
+ ),
96
+ )}
62
97
</Nav>
63
98
64
99
<LanguageMenu />
0 commit comments