|
| 1 | +import _ from 'lodash'; |
| 2 | +import React from 'react'; |
| 3 | +import PropTypes from 'prop-types'; |
| 4 | +import IconButton from 'material-ui/IconButton'; |
| 5 | +import Button from 'material-ui/Button'; |
| 6 | +import Toolbar from 'material-ui/Toolbar'; |
| 7 | +import Typography from 'material-ui/Typography'; |
| 8 | +import MenuIcon from 'material-ui-icons/Menu'; |
| 9 | +import Hidden from 'material-ui/Hidden'; |
| 10 | +import { withStyles } from 'material-ui/styles'; |
| 11 | +import withWidth from 'material-ui/utils/withWidth'; |
| 12 | +import compose from 'recompose/compose'; |
| 13 | + |
| 14 | +import styles from './styles'; |
| 15 | + |
| 16 | +class BasicNavBar extends React.PureComponent { |
| 17 | + static propTypes = { |
| 18 | + links: PropTypes.arrayOf(PropTypes.shape({})), |
| 19 | + classes: PropTypes.shape({}), |
| 20 | + title: PropTypes.string, |
| 21 | + logo: PropTypes.string, |
| 22 | + }; |
| 23 | + |
| 24 | + renderLogo = () => { |
| 25 | + const { classes, title, logo } = this.props; |
| 26 | + if (logo) { |
| 27 | + return ( |
| 28 | + <div className={classes.logo}> |
| 29 | + <img src={logo} alt={title} className={classes.image} /> |
| 30 | + </div> |
| 31 | + ); |
| 32 | + } |
| 33 | + return ( |
| 34 | + <Typography type="title" color="inherit" className={classes.flex}> |
| 35 | + {title} |
| 36 | + </Typography> |
| 37 | + ); |
| 38 | + }; |
| 39 | + |
| 40 | + handleIconClick = () => { |
| 41 | + this.props.onIconClick(); |
| 42 | + } |
| 43 | + |
| 44 | + render() { |
| 45 | + const { links, onIconClick } = this.props; |
| 46 | + return ( |
| 47 | + <Toolbar> |
| 48 | + <Hidden smUp> |
| 49 | + <IconButton color="inherit" aria-label="Menu" onClick={this.handleIconClick}> |
| 50 | + <MenuIcon /> |
| 51 | + </IconButton> |
| 52 | + </Hidden> |
| 53 | + {this.renderLogo()} |
| 54 | + <Hidden xsDown> |
| 55 | + <div> |
| 56 | + {_.map(links, link => ( |
| 57 | + <Button href={link.href} color="inherit" key={link.label}> |
| 58 | + {link.label} |
| 59 | + </Button> |
| 60 | + ))} |
| 61 | + </div> |
| 62 | + </Hidden> |
| 63 | + </Toolbar> |
| 64 | + ); |
| 65 | + } |
| 66 | +} |
| 67 | + |
| 68 | +export default compose(withStyles(styles), withWidth())(BasicNavBar); |
0 commit comments