Skip to content

Commit

Permalink
feat: created hamburger menu component
Browse files Browse the repository at this point in the history
  • Loading branch information
zstix committed Apr 22, 2020
1 parent 89e4277 commit ecc9e1f
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 0 deletions.
31 changes: 31 additions & 0 deletions src/components/HamburgerMenu.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import React, { useState } from 'react';
import PropTypes from 'prop-types';
import cx from 'classnames';

import './HamburgerMenu.scss';

const HamburgerMenu = ({ onClick }) => {
const [open, updateOpen] = useState(false);

return (
<button
aria-expanded={open}
aria-label="Mobile Menu"
className={cx('HamburgerMenu', { HamburgerMenu__open: open })}
onClick={() => {
updateOpen(!open);
onClick();
}}
>
<div />
<div />
<div />
</button>
);
};

HamburgerMenu.propTypes = {
onClick: PropTypes.func.isRequired,
};

export default HamburgerMenu;
29 changes: 29 additions & 0 deletions src/components/HamburgerMenu.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
button.HamburgerMenu {
background: none;
border: 0;
cursor: pointer;
width: 3rem;

div {
width: 100%;
height: 4px;
background-color: var(--color-black);
margin: 5px 0;
border-radius: 2px;
transition: 0.18s;
}

&.HamburgerMenu__open {
:nth-child(1) {
transform: rotate(-45deg) translate(-6px, 6px);
}

:nth-child(2) {
opacity: 0;
}

:nth-child(3) {
transform: rotate(45deg) translate(-6px, -6px);
}
}
}

0 comments on commit ecc9e1f

Please sign in to comment.