Skip to content

Commit 6ef75a7

Browse files
committed
Toggle menu panel with menu and close button
1 parent 4b1ecc2 commit 6ef75a7

File tree

3 files changed

+40
-6
lines changed

3 files changed

+40
-6
lines changed

public/icons/close-icon.svg

Lines changed: 4 additions & 0 deletions
Loading

src/components/MenuPanel.js

Lines changed: 30 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ const Overlay = styled.div`
1111
left: 0;
1212
top: 0;
1313
background-color: rgba(0, 0, 0, 0.5);
14+
display: ${({ isMenuPanelVisible }) => !isMenuPanelVisible && "none"};
1415
`;
1516

1617
const MenuPanelStyled = styled.div`
@@ -21,7 +22,15 @@ const MenuPanelStyled = styled.div`
2122
top: 0;
2223
right: 0;
2324
height: 100vh;
24-
padding-top: 30px;
25+
padding-top: 50px;
26+
padding-right: 50px;
27+
display: ${({ isMenuPanelVisible }) => !isMenuPanelVisible && "none"};
28+
`;
29+
30+
const CloseButton = styled.span`
31+
cursor: pointer;
32+
display: flex;
33+
justify-content: flex-end;
2534
`;
2635

2736
const Links = styled.ul`
@@ -46,12 +55,27 @@ const Links = styled.ul`
4655
}
4756
`;
4857

49-
const MenuPanel = ({ isAuthenticated, handleLogout }) => {
58+
const MenuPanel = ({
59+
isMenuPanelVisible,
60+
toggleMenuPanelVisible,
61+
isAuthenticated,
62+
handleLogout,
63+
}) => {
5064
return (
5165
<>
52-
<Overlay></Overlay>
66+
<Overlay isMenuPanelVisible={isMenuPanelVisible}></Overlay>
5367

54-
<MenuPanelStyled>
68+
<MenuPanelStyled isMenuPanelVisible={isMenuPanelVisible}>
69+
<CloseButton
70+
onClick={() => toggleMenuPanelVisible(!isMenuPanelVisible)}
71+
>
72+
<img
73+
src="/icons/close-icon.svg"
74+
alt="Close Icon"
75+
width={50}
76+
height={50}
77+
/>
78+
</CloseButton>
5579
<Links>
5680
<li>
5781
<Link to="/artists">Artists</Link>
@@ -77,6 +101,8 @@ const MenuPanel = ({ isAuthenticated, handleLogout }) => {
77101
};
78102

79103
MenuPanel.propTypes = {
104+
isMenuPanelVisible: PropTypes.bool,
105+
toggleMenuPanelVisible: PropTypes.func,
80106
isAuthenticated: PropTypes.bool,
81107
handleLogout: PropTypes.func,
82108
};

src/components/Navigation.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import React from "react";
1+
import React, { useState } from "react";
22
import styled from "styled-components";
33
import { Link } from "react-router-dom";
44
import { connect } from "react-redux";
@@ -45,6 +45,8 @@ const MenuButton = styled.span`
4545
`;
4646

4747
const Navigation = ({ isAuthenticated, handleLogout }) => {
48+
const [isMenuPanelVisible, toggleMenuPanelVisible] = useState(true);
49+
4850
return (
4951
<>
5052
<NavigationStyled>
@@ -70,7 +72,7 @@ const Navigation = ({ isAuthenticated, handleLogout }) => {
7072
</li>
7173
)}
7274
</Links>
73-
<MenuButton>
75+
<MenuButton onClick={() => toggleMenuPanelVisible(!isMenuPanelVisible)}>
7476
<img
7577
src="/icons/menu-icon.svg"
7678
alt="Menu Icon"
@@ -81,6 +83,8 @@ const Navigation = ({ isAuthenticated, handleLogout }) => {
8183
</NavigationStyled>
8284

8385
<MenuPanel
86+
isMenuPanelVisible={isMenuPanelVisible}
87+
toggleMenuPanelVisible={toggleMenuPanelVisible}
8488
isAuthenticated={isAuthenticated}
8589
handleLogout={handleLogout}
8690
></MenuPanel>

0 commit comments

Comments
 (0)