-
Notifications
You must be signed in to change notification settings - Fork 6.5k
Expand file tree
/
Copy pathindex.tsx
More file actions
53 lines (42 loc) · 1.46 KB
/
index.tsx
File metadata and controls
53 lines (42 loc) · 1.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
'use client';
import { useTranslations } from 'next-intl';
import type { ComponentProps, FC } from 'react';
import { useRef } from 'react';
import ProgressionSidebarGroup from '@/components/Common/ProgressionSidebar/ProgressionSidebarGroup';
import WithRouterSelect from '@/components/withRouterSelect';
import { useClientContext, useNavigationState } from '@/hooks';
import styles from './index.module.css';
type ProgressionSidebarProps = {
groups: Array<ComponentProps<typeof ProgressionSidebarGroup>>;
};
const ProgressionSidebar: FC<ProgressionSidebarProps> = ({ groups }) => {
const t = useTranslations();
const { pathname } = useClientContext();
const ref = useRef<HTMLElement>(null);
useNavigationState('progressionSidebar', ref);
const selectItems = groups.map(({ items, groupName }) => ({
label: groupName,
items: items.map(({ label, link }) => ({ value: link, label })),
}));
const currentItem = selectItems
.map(item => item.items)
.flat()
.find(item => pathname === item.value);
return (
<nav className={styles.wrapper} ref={ref}>
<WithRouterSelect
label={t('components.common.sidebar.title')}
values={selectItems}
defaultValue={currentItem?.value}
/>
{groups.map(({ groupName, items }) => (
<ProgressionSidebarGroup
key={groupName.toString()}
groupName={groupName}
items={items}
/>
))}
</nav>
);
};
export default ProgressionSidebar;