From dc365b92328fef9d17ab3f23f39a21c56c61f3c1 Mon Sep 17 00:00:00 2001 From: Daniel Gent Date: Fri, 27 Aug 2021 15:57:48 +0200 Subject: [PATCH] Working menu button with open and closed state. --- .../common/Navbar/MenuButton.module.css | 8 ++ components/common/Navbar/MenuButton.tsx | 7 +- components/common/Navbar/Navbar.tsx | 78 ++++++++++--------- 3 files changed, 54 insertions(+), 39 deletions(-) diff --git a/components/common/Navbar/MenuButton.module.css b/components/common/Navbar/MenuButton.module.css index 7bdbf29e3..ba8c18605 100644 --- a/components/common/Navbar/MenuButton.module.css +++ b/components/common/Navbar/MenuButton.module.css @@ -23,3 +23,11 @@ .menuButton::before { transform: translateY(-5px); } + +.menuButton.isOpen::before { + transform: rotate(45deg); +} + +.menuButton.isOpen::after { + transform: rotate(-45deg); +} diff --git a/components/common/Navbar/MenuButton.tsx b/components/common/Navbar/MenuButton.tsx index 7bc34ea43..0de8f0ade 100644 --- a/components/common/Navbar/MenuButton.tsx +++ b/components/common/Navbar/MenuButton.tsx @@ -1,17 +1,18 @@ import { FC } from 'react' import PropTypes from 'prop-types' import s from './MenuButton.module.css' +import cn from 'classnames' interface MenuButtonProps { - isOpen: boolean - onClick: any + isOpen: boolean + onClick: any } const MenuButton: FC = ({ isOpen, onClick }) => { return (
) } diff --git a/components/common/Navbar/Navbar.tsx b/components/common/Navbar/Navbar.tsx index 1286f251d..492af69b4 100644 --- a/components/common/Navbar/Navbar.tsx +++ b/components/common/Navbar/Navbar.tsx @@ -1,4 +1,4 @@ -import { FC } from 'react' +import { FC, useState } from 'react' import Link from 'next/link' import s from './Navbar.module.css' import NavbarRoot from './NavbarRoot' @@ -14,43 +14,49 @@ interface NavbarProps { links?: Link[] } -const Navbar: FC = ({ links }) => ( - -
- -
-
- - - - - - -
- {}} /> -
- -
-
-
-
- {process.env.COMMERCE_SEARCH_ENABLED && ( -
+const Navbar: FC = ({ links }) => { + const [isMenuOpen, setIsMenuOpen] = useState(false) + return ( + +
- +
+
+ + + + + + +
+ setIsMenuOpen(!isMenuOpen)} + /> +
+ +
+
- )} -
-) + {process.env.COMMERCE_SEARCH_ENABLED && ( +
+ + + +
+ )} + + ) +} export default Navbar