feat(SW-272) implemented mobile design
This commit is contained in:
111
components/Header/MainMenu/NavigationMenu/MegaMenu/index.tsx
Normal file
111
components/Header/MainMenu/NavigationMenu/MegaMenu/index.tsx
Normal file
@@ -0,0 +1,111 @@
|
||||
"use client"
|
||||
|
||||
import useDropdownStore from "@/stores/main-menu"
|
||||
|
||||
import { ArrowRightIcon, ChevronLeftIcon } from "@/components/Icons"
|
||||
import Card from "@/components/TempDesignSystem/Card"
|
||||
import Link from "@/components/TempDesignSystem/Link"
|
||||
import Caption from "@/components/TempDesignSystem/Text/Caption"
|
||||
import Subtitle from "@/components/TempDesignSystem/Text/Subtitle"
|
||||
import { useHandleKeyUp } from "@/hooks/useHandleKeyUp"
|
||||
import { useTrapFocus } from "@/hooks/useTrapFocus"
|
||||
|
||||
import styles from "./megaMenu.module.css"
|
||||
|
||||
import { MegaMenuProps } from "@/types/components/header/megaMenu"
|
||||
|
||||
export default function MegaMenu({
|
||||
isMobile,
|
||||
title,
|
||||
seeAllLink,
|
||||
submenu,
|
||||
card,
|
||||
}: MegaMenuProps) {
|
||||
const { openMegaMenu, toggleMegaMenu } = useDropdownStore()
|
||||
const megaMenuRef = useTrapFocus()
|
||||
const isMegaMenuOpen = openMegaMenu === title
|
||||
|
||||
useHandleKeyUp((event: KeyboardEvent) => {
|
||||
if (event.key === "Escape" && isMegaMenuOpen) {
|
||||
toggleMegaMenu(false)
|
||||
}
|
||||
})
|
||||
|
||||
function closeMegaMenu() {
|
||||
toggleMegaMenu(false)
|
||||
}
|
||||
return (
|
||||
<nav>
|
||||
{isMobile ? (
|
||||
<div className={styles.backWrapper}>
|
||||
<button
|
||||
type="button"
|
||||
className={styles.backButton}
|
||||
onClick={closeMegaMenu}
|
||||
>
|
||||
<ChevronLeftIcon color="red" />
|
||||
<Subtitle type="one" color="burgundy">
|
||||
{title}
|
||||
</Subtitle>
|
||||
</button>
|
||||
</div>
|
||||
) : null}
|
||||
<div className={styles.megaMenuContent} ref={megaMenuRef}>
|
||||
<div className={styles.seeAllLink}>
|
||||
{seeAllLink?.link ? (
|
||||
<Link
|
||||
href={seeAllLink.link.url}
|
||||
color="burgundy"
|
||||
variant="icon"
|
||||
onClick={closeMegaMenu}
|
||||
>
|
||||
{seeAllLink.title}
|
||||
<ArrowRightIcon color="burgundy" />
|
||||
</Link>
|
||||
) : null}
|
||||
</div>
|
||||
<ul className={styles.submenus}>
|
||||
{submenu.map((item) => (
|
||||
<li key={item.title} className={styles.submenusItem}>
|
||||
<Caption textTransform="uppercase" asChild>
|
||||
<span>{item.title}</span>
|
||||
</Caption>
|
||||
<ul className={styles.submenu}>
|
||||
{item.links.map(({ title, link }) =>
|
||||
link ? (
|
||||
<li key={title} className={styles.submenuItem}>
|
||||
<Link
|
||||
href={link.url}
|
||||
color="burgundy"
|
||||
className={styles.link}
|
||||
onClick={closeMegaMenu}
|
||||
>
|
||||
{title}
|
||||
</Link>
|
||||
</li>
|
||||
) : null
|
||||
)}
|
||||
</ul>
|
||||
</li>
|
||||
))}
|
||||
</ul>
|
||||
{card ? (
|
||||
<div className={styles.cardWrapper}>
|
||||
<Card
|
||||
className={styles.card}
|
||||
backgroundImage={card.backgroundImage}
|
||||
bodyText={card.body_text}
|
||||
heading={card.heading}
|
||||
primaryButton={card.primaryButton}
|
||||
secondaryButton={card.secondaryButton}
|
||||
scriptedTopTitle={card.scripted_top_title}
|
||||
onPrimaryButtonClick={closeMegaMenu}
|
||||
onSecondaryButtonClick={closeMegaMenu}
|
||||
theme="image"
|
||||
/>
|
||||
</div>
|
||||
) : null}
|
||||
</div>
|
||||
</nav>
|
||||
)
|
||||
}
|
||||
Reference in New Issue
Block a user