From f55e4a8e112b13aa11bbb0918526a91d65c49899 Mon Sep 17 00:00:00 2001 From: Barry Low Date: Tue, 6 Nov 2018 23:11:53 -0800 Subject: [PATCH] Add Responsive mobile menu button --- client/src/views/header/index.js | 134 +++++++++++++++++++++---------- 1 file changed, 91 insertions(+), 43 deletions(-) diff --git a/client/src/views/header/index.js b/client/src/views/header/index.js index d96f17c85..d594153c0 100644 --- a/client/src/views/header/index.js +++ b/client/src/views/header/index.js @@ -2,6 +2,7 @@ import React, { Component } from 'react' import PropTypes from 'prop-types' import { withStyles } from '@material-ui/core/styles' +import withWidth from '@material-ui/core/withWidth' import AppBar from '@material-ui/core/AppBar' import Toolbar from '@material-ui/core/Toolbar' import Typography from '@material-ui/core/Typography' @@ -11,6 +12,7 @@ import Button from '@material-ui/core/Button' // icons import HomeIcon from '@material-ui/icons/Home' import ExitIcon from '@material-ui/icons/ExitToApp' +import MenuIcon from '@material-ui/icons/Menu' import { Link } from 'react-router-dom' @@ -72,15 +74,23 @@ const styles = theme => ({ }, dropdownButtons: { display: 'block' + }, + mobileMenu: { + color: theme.palette.common.white, + boxShadow: 'none', + border: `1px solid ${theme.palette.common.white}`, + background: 'none' } }) class Header extends Component { constructor (props) { super(props) + this.toggleMenu = this.toggleMenu.bind(this) this.state = { user: null, - open: null + open: null, + mobileOpen: false } } @@ -90,7 +100,7 @@ class Header extends Component { } render () { - let { classes, auth } = this.props + let { classes, auth, width } = this.props let { open } = this.state let user = JSON.parse(this.state.user) @@ -117,6 +127,34 @@ class Header extends Component { ) }) + const mobileMenusButton = ( + + ) + + const mobileMenus = allMenus.map((menu, index) => { + return ( +
this.setState({ open: index })} + onMouseLeave={() => this.setState({ open: null })} + > + +
+ { + menu.submenus.map((submenu, index) => { + // const Icon = submenu.icon + return ( + + ) + })} +
+
+ ) + }) + return (
  - - - - - - - - { menus } - - - - {this.state.user !== undefined && this.state.user !== null ? ( + {(width !== 'xs' && width !== 'sm') && - - - ) : ( - - )} + + + - - - + + + + + {this.state.user !== undefined && this.state.user !== null ? ( + + + + ) : ( + + )} + + + + + + } + { (width === 'xs' || width === 'sm') ? mobileMenusButton : menus } + { (width === 'xs' || width === 'sm') && this.state.mobileOpen ? mobileMenus : '' }
) } + + toggleMenu () { + this.setState({ mobileOpen: !this.state.mobileOpen }) + } } Header.propTypes = { classes: PropTypes.object.isRequired, - auth: PropTypes.object.isRequired + auth: PropTypes.object.isRequired, + width: PropTypes.string } -export default withStyles(styles)(Header) +const HeaderWithStyles = withStyles(styles)(Header) + +export default withWidth()(HeaderWithStyles)