-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathSingleHeroNavMenuAsDropdown.tsx
More file actions
73 lines (66 loc) · 2.42 KB
/
SingleHeroNavMenuAsDropdown.tsx
File metadata and controls
73 lines (66 loc) · 2.42 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
'use client';
import React from 'react';
import { HeroManager } from '@/entities/Hero';
import { usePathname } from 'next/navigation';
import cls from './SingleHeroNavMenuAsDropdown.module.scss';
import {
NavMenuWithDropdowns,
NavMenuWithDropdownsProps,
DropdownItem,
} from '@/shared/ui/NavMenuWithDropdownsV2';
import { getRouteOneHeroPage } from '@/shared/appLinks/RoutePaths';
import { useClientTranslation } from '@/shared/i18n';
import useSizes from '@/shared/lib/hooks/useSizes';
const SingleHeroNavMenuAsDropdown: React.FC = () => {
const { isMobileSize, isTabletSize } = useSizes();
const isTouchDevice = isMobileSize || isTabletSize;
const { t } = useClientTranslation('heroes');
const pathname = usePathname();
const selectedHero = pathname.split('/')[3];
const heroManager = new HeroManager(t);
const allHeroGroups = heroManager.getGroupsWithHeroesAsArray();
const dropdownItems: DropdownItem[] = allHeroGroups.map((group) => ({
title: group.name.charAt(0) + group.name.slice(1).toLowerCase(),
openByDefault: false,
elements: group.heroes.map((hero) => ({
elementText: hero.title,
id: hero.id.toString(),
active: selectedHero === hero.slug,
link: {
path: getRouteOneHeroPage(hero.slug),
isExternal: false,
},
})),
}));
const navMenuWithDropdownsMobileProps: NavMenuWithDropdownsProps = {
title: t('defense-classes'),
openByDefault: false,
dropdownItems: dropdownItems,
};
const navMenuWithDropdownsDesktopProps: NavMenuWithDropdownsProps = {
title: t('defense-classes'),
openByDefault: true,
staticDropdown: true,
dropdownItems: dropdownItems,
};
return (
<div>
{isTouchDevice ? (
<nav className={cls.NavMenuWithDropdownsTouch}>
<NavMenuWithDropdowns
className={cls.Width}
{...navMenuWithDropdownsMobileProps}
/>
</nav>
) : (
<nav className={cls.marginTop}>
<NavMenuWithDropdowns
className={cls.Width}
{...navMenuWithDropdownsDesktopProps}
/>
</nav>
)}
</div>
);
};
export default SingleHeroNavMenuAsDropdown;