From 1c9cd4d97e8ab533e87ffeaca88bad205c0d7d53 Mon Sep 17 00:00:00 2001 From: David Date: Sat, 15 Apr 2023 21:28:36 +0100 Subject: [PATCH] change menu toggle --- app/components/Nav.tsx | 59 +++++++++++++++++++++++++++++++++++------- 1 file changed, 50 insertions(+), 9 deletions(-) diff --git a/app/components/Nav.tsx b/app/components/Nav.tsx index d6f086d..de82ddf 100644 --- a/app/components/Nav.tsx +++ b/app/components/Nav.tsx @@ -1,5 +1,6 @@ 'use client' +import { useState, useEffect } from 'react' import { Outfit } from 'next/font/google' const outfit = Outfit({ @@ -9,11 +10,45 @@ const outfit = Outfit({ }) export default function Nav() { - let checkMenu: boolean = false + const [isMenuOpen, setIsMenuOpen] = useState(true) + + // const toggleMenu = () => { + // setIsMenuOpen(!isMenuOpen) + // const bodyEl = document.querySelector('body') + // const x1El = document.querySelector('.x-1') + // const x2El = document.querySelector('.x-2') + // const x3El = document.querySelector('.x-3') + // const menuEl = document.querySelector('.menu') + // if (isMenuOpen) { + // bodyEl?.classList.add('disable-scroll') + // x1El?.classList.add('close-x-1') + // x2El?.classList.add('close-x-2') + // x3El?.classList.add('close-x-3') + // menuEl?.classList.remove('move-menu-off') + // menuEl?.classList.add('move-menu-on') + // } else { + // bodyEl?.classList.remove('disable-scroll') + // x1El?.classList.remove('close-x-1') + // x2El?.classList.remove('close-x-2') + // x3El?.classList.remove('close-x-3') + // menuEl?.classList.remove('move-menu-on') + // menuEl?.classList.add('move-menu-off') + // setTimeout(() => { + // menuEl?.classList.remove('show-menu') + // }, 310) + // } + // } + + // useEffect(() => { + + + + // }, [toggleMenu]) +// let checkMenu: boolean = false const toggleMenu = () => { - checkMenu = !checkMenu - if (checkMenu === true) { + setIsMenuOpen(!isMenuOpen) + if (isMenuOpen) { document.querySelector('body')?.classList.add('disable-scroll') document.querySelector('.x-1')?.classList.add('close-x-1') document.querySelector('.x-2')?.classList.add('close-x-2') @@ -23,8 +58,7 @@ export default function Nav() { document.querySelector('.menu')?.classList.remove('move-menu-off') document.querySelector('.menu')?.classList.add('move-menu-on') }, 1) - } - if (checkMenu === false) { + } else { document.querySelector('body')?.classList.remove('disable-scroll') document.querySelector('.x-1')?.classList.remove('close-x-1') document.querySelector('.x-2')?.classList.remove('close-x-2') @@ -111,13 +145,20 @@ export default function Nav() { onClick={toggleMenu} className="close z-10 flex cursor-pointer flex-col items-end justify-between gap-[5px] p-[3px] duration-500 md:hidden" > - - - + + + + + + -