forked from nodejs/nodejs.org
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwithNavBar.tsx
More file actions
98 lines (83 loc) · 3.09 KB
/
withNavBar.tsx
File metadata and controls
98 lines (83 loc) · 3.09 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
'use client';
import LanguageDropdown from '@node-core/ui-components/Common/LanguageDropDown';
import Skeleton from '@node-core/ui-components/Common/Skeleton';
import ThemeToggle from '@node-core/ui-components/Common/ThemeToggle';
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 type { SimpleLocaleConfig } from '@node-core/ui-components/types';
import dynamic from 'next/dynamic';
import { useLocale, useTranslations } from 'next-intl';
import { useTheme } from 'next-themes';
import { useState, useEffect } from 'react';
import type { FC } from 'react';
import Link from '#site/components/Link';
import WithBanner from '#site/components/withBanner';
import WithNodejsLogo from '#site/components/withNodejsLogo';
import { useSiteNavigation } from '#site/hooks';
import { useRouter, usePathname } from '#site/navigation.mjs';
import { availableLocales } from '#site/next.locales.mjs';
const SearchButton = dynamic(() => import('#site/components/Common/Search'), {
ssr: false,
loading: () => (
<Skeleton className={styles.searchButtonSkeleton} loading={true} />
),
});
const WithNavBar: FC = () => {
const { navigationItems } = useSiteNavigation();
const { resolvedTheme, setTheme } = useTheme();
const { replace } = useRouter();
const pathname = usePathname();
const t = useTranslations();
const locale = useLocale();
const [mounted, setMounted] = useState(false);
useEffect(() => setMounted(true), []);
const toggleCurrentTheme = () =>
setTheme(resolvedTheme === 'dark' ? 'light' : 'dark');
const themeToggleAriaLabel = !mounted
? t('components.common.themeToggle.loading')
: resolvedTheme === 'dark'
? t('components.common.themeToggle.light')
: t('components.common.themeToggle.dark');
const changeLanguage = (locale: SimpleLocaleConfig) =>
replace(pathname!, { locale: locale.code });
return (
<div>
<WithBanner section="index" />
<NavBar
navItems={navigationItems.map(([, { label, link, target }]) => ({
link: link,
text: label,
target: target,
}))}
pathname={pathname}
as={Link}
Logo={WithNodejsLogo}
sidebarItemTogglerAriaLabel={t(
'components.containers.navBar.controls.toggle'
)}
>
<SearchButton />
<ThemeToggle
onClick={toggleCurrentTheme}
aria-label={themeToggleAriaLabel}
/>
<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;