-
Notifications
You must be signed in to change notification settings - Fork 6.5k
Expand file tree
/
Copy pathwithNavBar.tsx
More file actions
109 lines (94 loc) · 3.46 KB
/
withNavBar.tsx
File metadata and controls
109 lines (94 loc) · 3.46 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
'use client';
import LanguageDropdown from '@node-core/ui-components/Common/LanguageDropDown';
import Skeleton from '@node-core/ui-components/Common/Skeleton';
import SkipToContentButton from '@node-core/ui-components/Common/SkipToContentButton';
import NavBar from '@node-core/ui-components/Containers/NavBar';
// TODO(@AvivKeller): I don't like that we are importing styles from another module
import styles from '@node-core/ui-components/Containers/NavBar/index.module.css';
import GitHubIcon from '@node-core/ui-components/Icons/Social/GitHub';
import { availableLocales } from '@node-core/website-i18n';
import classNames from 'classnames';
import dynamic from 'next/dynamic';
import { useLocale, useTranslations } from 'next-intl';
import { useTheme } from 'next-themes';
import SearchButton from '#site/components/Common/Searchbox';
import Link from '#site/components/Link';
import WithBanner from '#site/components/withBanner';
import WithNodejsLogo from '#site/components/withNodejsLogo';
import { useScrollDirection } from '#site/hooks/client';
import { useSiteNavigation } from '#site/hooks/generic';
import { useRouter, usePathname } from '#site/navigation.mjs';
import type { Theme } from '@node-core/ui-components/Common/ThemeToggle';
import type { SimpleLocaleConfig } from '@node-core/ui-components/types';
import type { FC } from 'react';
const ThemeToggle = dynamic(
() => import('@node-core/ui-components/Common/ThemeToggle'),
{
ssr: false,
loading: () => (
<Skeleton className={styles.themeToggleSkeleton} loading={true} />
),
}
);
const WithNavBar: FC = () => {
const { navigationItems } = useSiteNavigation();
const { theme, setTheme } = useTheme();
const { replace } = useRouter();
const pathname = usePathname();
const t = useTranslations();
const locale = useLocale();
const scrollDirection = useScrollDirection();
const changeLanguage = (locale: SimpleLocaleConfig) =>
replace(pathname!, { locale: locale.code });
return (
<div
className={classNames(styles.navBarWrapper, {
[styles.hidden]: scrollDirection === 'down',
})}
>
<SkipToContentButton>
{t('components.common.skipToContent')}
</SkipToContentButton>
<WithBanner section="index" />
<NavBar
navItems={navigationItems.map(([, { label, link, target }]) => ({
link,
text: label,
target,
}))}
pathname={pathname}
as={Link}
Logo={WithNodejsLogo}
sidebarItemTogglerAriaLabel={t(
'components.containers.navBar.controls.toggle'
)}
>
<SearchButton />
<ThemeToggle
onChange={setTheme}
currentTheme={(theme as Theme) ?? 'system'}
ariaLabel={t('components.header.buttons.theme')}
themeLabels={{
system: t('components.header.buttons.themeSystem'),
light: t('components.header.buttons.themeLightMode'),
dark: t('components.header.buttons.themeDarkMode'),
}}
/>
<LanguageDropdown
onChange={changeLanguage}
availableLanguages={availableLocales}
currentLanguage={locale}
ariaLabel={t('components.common.languageDropdown.label')}
/>
<Link
href="https://github.com/nodejs/node"
aria-label="Node.js Github"
className={styles.ghIconWrapper}
>
<GitHubIcon />
</Link>
</NavBar>
</div>
);
};
export default WithNavBar;