Newer
Older
import React from 'react';
import PropTypes from 'prop-types';
import AppBar from '@material-ui/core/AppBar';
import Toolbar from '@material-ui/core/Toolbar';
import IconButton from '@material-ui/core/IconButton';
import InputBase from '@material-ui/core/InputBase';
import MenuItem from '@material-ui/core/MenuItem';
import Menu from '@material-ui/core/Menu';
import { fade } from '@material-ui/core/styles/colorManipulator';
import { withStyles } from '@material-ui/core/styles';
import SearchIcon from '@material-ui/icons/Search';
import MoreIcon from '@material-ui/icons/MoreVert';
import Button from '@material-ui/core/Button';
import { Link, NavLink } from 'react-router-dom';
root: {
//width: '100%',
},
grow: {
flexGrow: 1,
menuButton: {
marginLeft: -12,
marginRight: 20,
},
title: {
display: 'none',
[theme.breakpoints.up('sm')]: {
display: 'block',
},
search: {
position: 'relative',
borderRadius: theme.shape.borderRadius,
backgroundColor: fade(theme.palette.common.white, 0.15),
'&:hover': {
backgroundColor: fade(theme.palette.common.white, 0.25),
},
marginRight: theme.spacing.unit * 2,
marginLeft: 0,
width: '100%',
[theme.breakpoints.up('sm')]: {
marginLeft: theme.spacing.unit * 3,
width: 'auto',
},
searchIcon: {
width: theme.spacing.unit * 9,
height: '100%',
position: 'absolute',
pointerEvents: 'none',
display: 'flex',
alignItems: 'center',
justifyContent: 'center',
inputRoot: {
color: 'inherit',
width: '100%',
inputInput: {
paddingTop: theme.spacing.unit,
paddingRight: theme.spacing.unit,
paddingBottom: theme.spacing.unit,
paddingLeft: theme.spacing.unit * 10,
transition: theme.transitions.create('width'),
width: '100%',
[theme.breakpoints.up('md')]: {
width: 200,
},
sectionDesktop: {
display: 'none',
[theme.breakpoints.up('md')]: {
display: 'flex',
},
sectionMobile: {
display: 'flex',
[theme.breakpoints.up('md')]: {
display: 'none',
},
appBarButton: {
color: 'white !important'
appBarButtonActive: {
border: '1px solid white'
}
});
class TopBar extends React.Component {
state = {
anchorEl: null,
mobileMoreAnchorEl: null,
handleProfileMenuOpen = event => {
this.setState({ anchorEl: event.currentTarget });
};
handleMenuClose = () => {
this.setState({ anchorEl: null });
this.handleMobileMenuClose();
handleMobileMenuOpen = event => {
this.setState({ mobileMoreAnchorEl: event.currentTarget });
handleMobileMenuClose = () => {
this.setState({ mobileMoreAnchorEl: null });
const isMobileMenuOpen = Boolean(mobileMoreAnchorEl);
const perspectives = [ 'manuscripts', 'works', 'events', 'people',
'organizations', 'places' ];
const renderMobileMenu = (
<Menu
anchorEl={mobileMoreAnchorEl}
anchorOrigin={{ vertical: 'top', horizontal: 'right' }}
transformOrigin={{ vertical: 'top', horizontal: 'right' }}
open={isMobileMenuOpen}
onClose={this.handleMobileMenuClose}
>
{perspectives.map(perspective =>
<MenuItem
key={perspective}
component={Link}
to={`/${perspective}`}
>
{perspective.toUpperCase()}
</MenuItem>
)}
</Menu>
);
return (
<div className={classes.root}>
<AppBar position="absolute">
<Toolbar>
<Button
className={classes.appBarButton}
<Typography className={classes.title} variant="h6" color="inherit" noWrap>
MMM
</Typography>
</Button>
<div className={classes.search}>
<div className={classes.searchIcon}>
<SearchIcon />
</div>
<InputBase
placeholder="Search…"
classes={{
root: classes.inputRoot,
input: classes.inputInput,
}}
<div className={classes.grow} />
<div className={classes.sectionDesktop}>
{perspectives.map(perspective =>
<Button
key={perspective}
className={classes.appBarButton}
component={NavLink}
to={`/${perspective}`}
isActive={(match, location) => location.pathname.startsWith(`/${perspective}`)}
activeClassName={classes.appBarButtonActive}
>
{perspective}
</Button>
)}
</div>
<div className={classes.sectionMobile}>
<IconButton aria-haspopup="true" onClick={this.handleMobileMenuOpen} color="inherit">
<MoreIcon />
</IconButton>
</div>
</Toolbar>
</AppBar>
{renderMobileMenu}
</div>