|
1 |
| -import { useState } from "react" |
2 | 1 | import { Box, type BoxProps, Flex } from "@chakra-ui/react"
|
3 | 2 | import * as NavigationMenu from "@radix-ui/react-navigation-menu"
|
4 | 3 |
|
5 | 4 | import { Button } from "@/components/Buttons"
|
6 | 5 |
|
7 |
| -// import { trackCustomEvent } from "@/lib/utils/matomo" |
8 | 6 | import { SECTION_LABELS } from "@/lib/constants"
|
9 | 7 |
|
10 |
| -import type { NavSectionKey, NavSections } from "../types" |
| 8 | +import type { NavSections } from "../types" |
11 | 9 |
|
12 | 10 | import LvlContent from "./LvlContent"
|
13 |
| - |
14 |
| -import { useNavMenuColors } from "@/hooks/useNavMenuColors" |
15 |
| -import { useRtlFlip } from "@/hooks/useRtlFlip" |
| 11 | +import { useNavMenu } from "./useNavMenu" |
16 | 12 |
|
17 | 13 | type NavMenuProps = BoxProps & {
|
18 | 14 | sections: NavSections
|
19 | 15 | }
|
20 | 16 |
|
21 | 17 | const Menu = ({ sections, ...props }: NavMenuProps) => {
|
22 |
| - const { direction } = useRtlFlip() |
23 |
| - const menuColors = useNavMenuColors() |
24 |
| - const [activeSection, setActiveSection] = useState<NavSectionKey | null>(null) |
25 |
| - |
26 |
| - const getEnglishSectionName = ( |
27 |
| - activeSection: string |
28 |
| - ): NavSectionKey | null => { |
29 |
| - const index = Object.values(sections).findIndex( |
30 |
| - (section) => section.label === activeSection |
31 |
| - ) |
32 |
| - if (index < 0) return null |
33 |
| - return Object.keys(sections)[index] as NavSectionKey |
34 |
| - } |
| 18 | + const { direction, menuColors, activeSection, handleSectionChange } = |
| 19 | + useNavMenu(sections) |
35 | 20 |
|
36 | 21 | return (
|
37 | 22 | <Box {...props}>
|
38 | 23 | <NavigationMenu.Root
|
39 | 24 | dir={direction}
|
40 | 25 | orientation="horizontal"
|
41 | 26 | delayDuration={750}
|
42 |
| - onValueChange={(activeSection) => { |
43 |
| - setActiveSection(getEnglishSectionName(activeSection)) |
44 |
| - }} |
| 27 | + onValueChange={handleSectionChange} |
45 | 28 | >
|
46 | 29 | <NavigationMenu.List asChild>
|
47 | 30 | <Flex as="ul" listStyleType="none">
|
|
0 commit comments