'use client'; import { DocSearch } from '@docsearch/react'; import clsx from 'clsx'; import Link from 'next/link'; import { memo, useEffect, useState } from 'react'; import { FiMenu } from 'react-icons/fi'; import DarkModeBtn from './dark-mode-btn'; const txtMenu = [ { id: 1, name: 'Blog', path: '/blog', }, { id: 2, name: 'Projects', path: '/projects', }, { id: 3, name: 'Tags', path: '/tags', }, { id: 4, name: 'Friends', path: '/friends', }, { id: 5, name: 'About', path: '/about', }, ]; /** * Check element's id and it's parents * @param el * @returns */ const parentIdChecker = (el: HTMLElement | null): boolean => { if (!el) return false; if (!el?.id) return parentIdChecker(el.parentElement); return ( !!['menu', 'menu-icon'].filter((item) => item === el.id).length || parentIdChecker(el.parentElement) ); }; const HeadBar = () => { const [showMenu, setShowMenu] = useState(false); const handleClick = () => { setShowMenu((showMenu) => !showMenu); }; const [mounted, setMounted] = useState(false); useEffect(() => setMounted(true), []); /** * Click anywhere to close nav on mobile. */ const handleCloseNav = (e: TouchEvent) => { parentIdChecker(e.target as HTMLElement) || setShowMenu(false); }; useEffect(() => { window.addEventListener('touchstart', handleCloseNav); return () => { window.removeEventListener('touchstart', handleCloseNav); }; }, []); return ( <>
RUA!
); }; export default memo(HeadBar);