import React, { useEffect, FC, useRef, ReactType, useState } from 'react'; import DefaultLink, { LinkProps } from '../../blocks/Link'; import css from './index.module.css'; import { MilaGridColumn, MilaGridVoid } from '../../index'; import classnames from 'classnames'; import { NavigationItem, NavigationItemProps } from '../Footer'; import SimpleBar from 'simplebar-react'; export interface NavigationProps { items?: { name: string; Link?: ReactType; LinkProps: LinkProps; items?: { name: string; Link?: ReactType; LinkProps: LinkProps; }[]; }[]; LoginProps?: LinkProps; SignUpProps?: LinkProps; Link?: ReactType; setMobileNavOpen?: (open: boolean) => {}; isStickyHeader: boolean; Search: ReactType; SearchProps: any; navigationItems: { name: string; items: {}[]; }[]; contactNavigation: { name: string; items: { Link: ReactType; LinkProps: LinkProps; }[]; }; } const Navigation: FC = ({ items, LoginProps, SignUpProps, Link = DefaultLink, setMobileNavOpen, isStickyHeader, Search, SearchProps, navigationItems, contactNavigation, }) => { const navigationElement = useRef(null); const node = useRef(); const burgerRef = useRef(); const mobileOverlay = useRef(); const [isNavOpen, setIsNavOpen] = useState(false); const keepWholeNavigation = ['ch', 'de', 'gb', 'uk'].includes( SearchProps?.region?.toLowerCase(), ); useEffect(() => { setMobileNavOpen(isNavOpen); }, [isNavOpen]); const handleClickOutside = (e): void => { if (!isNavOpen || !mobileOverlay.current) { return; } // @ts-ignore null check above if (mobileOverlay?.current?.contains(e.target)) { setIsNavOpen(false); } }; useEffect(() => { document.addEventListener('mousedown', handleClickOutside); return (): void => { document.removeEventListener('mousedown', handleClickOutside); }; }); return ( <>
setIsNavOpen(!isNavOpen)} >
{keepWholeNavigation && ( <>
)}
{isNavOpen && (
)}
    {items && items.map(item => { return (
  • {item.name}
  • ); })}
{navigationItems && navigationItems.map((item, i) => (
    {item.items && item.items.map((item: NavigationItemProps, i) => !item.hideInPartnerPages ? ( ) : null, )}
))} {contactNavigation && (
    {contactNavigation.items && contactNavigation.items.map( (item: NavigationItemProps, i) => ( ), )}
)}
); }; export default Navigation;