forked from nodejs/nodejs.org
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwithProgressionSidebar.tsx
More file actions
62 lines (52 loc) · 1.69 KB
/
withProgressionSidebar.tsx
File metadata and controls
62 lines (52 loc) · 1.69 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
'use client';
import ProgressionSidebar from '@node-core/ui-components/Common/ProgressionSidebar';
import { usePathname } from 'next/navigation';
import { useLocale, useTranslations } from 'next-intl';
import type { RichTranslationValues } from 'next-intl';
import type { ComponentProps, FC } from 'react';
import Link from '#site/components/Link';
import { useSiteNavigation } from '#site/hooks/server';
import { useRouter } from '#site/navigation.mjs';
import type { NavigationKeys } from '#site/types';
type Group = ComponentProps<typeof ProgressionSidebar>['groups'][number];
type WithProgressionSidebarProps =
| {
navKey: NavigationKeys;
context?: Record<string, RichTranslationValues>;
groups?: never;
}
| {
groups: Array<Group>;
navKey?: never;
context?: never;
};
const WithProgressionSidebar: FC<WithProgressionSidebarProps> = props => {
const { getSideNavigation } = useSiteNavigation();
const pathname = usePathname();
const locale = useLocale();
const t = useTranslations();
const { push } = useRouter();
let groups: Array<Group> = [];
if ('navKey' in props && props.navKey) {
const [[, sidebarNavigation]] = getSideNavigation(
[props.navKey],
props.context
);
groups = sidebarNavigation.items.map(([, { label, items }]) => ({
groupName: label,
items: items.map(([, item]) => item),
}));
} else if ('groups' in props) {
groups = props.groups;
}
return (
<ProgressionSidebar
groups={groups}
pathname={pathname?.replace(`/${locale}`, '')}
title={t('components.common.sidebar.title')}
onSelect={push}
as={Link}
/>
);
};
export default WithProgressionSidebar;