forked from nodejs/nodejs.org
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwithNavBar.tsx
45 lines (37 loc) · 1.22 KB
/
withNavBar.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
'use client';
import { useLocale } from 'next-intl';
import { useTheme } from 'next-themes';
import type { FC } from 'react';
import NavBar from '@/components/Containers/NavBar';
import WithBanner from '@/components/withBanner';
import { useClientContext, useSiteNavigation } from '@/hooks';
import { useRouter } from '@/navigation.mjs';
import { availableLocales } from '@/next.locales.mjs';
const WithNavBar: FC = () => {
const { navigationItems } = useSiteNavigation();
const { resolvedTheme, setTheme } = useTheme();
const { pathname } = useClientContext();
const { replace } = useRouter();
const locale = useLocale();
const toggleCurrentTheme = () =>
setTheme(resolvedTheme === 'dark' ? 'light' : 'dark');
return (
<div>
<WithBanner section="index" />
<NavBar
onThemeTogglerClick={toggleCurrentTheme}
languages={{
currentLanguage: locale,
availableLanguages: availableLocales,
onChange: locale => replace(pathname!, { locale: locale.code }),
}}
navItems={navigationItems.map(([, { label, link, target }]) => ({
link,
text: label,
target,
}))}
/>
</div>
);
};
export default WithNavBar;