2018-03-07 21:29:21 +00:00
|
|
|
// @flow
|
|
|
|
|
2018-01-29 19:44:18 +00:00
|
|
|
// Copyright 2017 The go-ethereum Authors
|
|
|
|
// This file is part of the go-ethereum library.
|
|
|
|
//
|
|
|
|
// The go-ethereum library is free software: you can redistribute it and/or modify
|
|
|
|
// it under the terms of the GNU Lesser General Public License as published by
|
|
|
|
// the Free Software Foundation, either version 3 of the License, or
|
|
|
|
// (at your option) any later version.
|
|
|
|
//
|
|
|
|
// The go-ethereum library is distributed in the hope that it will be useful,
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
// GNU Lesser General Public License for more details.
|
|
|
|
//
|
|
|
|
// You should have received a copy of the GNU Lesser General Public License
|
|
|
|
// along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
|
|
|
import React, {Component} from 'react';
|
|
|
|
|
2019-04-03 05:14:02 +00:00
|
|
|
import withStyles from '@material-ui/core/styles/withStyles';
|
|
|
|
import List from '@material-ui/core/List';
|
|
|
|
import ListItem from '@material-ui/core/ListItem';
|
|
|
|
import ListItemIcon from '@material-ui/core/ListItemIcon';
|
|
|
|
import ListItemText from '@material-ui/core/ListItemText';
|
|
|
|
import Icon from '@material-ui/core/Icon';
|
2018-03-07 21:29:21 +00:00
|
|
|
import Transition from 'react-transition-group/Transition';
|
2019-04-03 05:14:02 +00:00
|
|
|
import {FontAwesomeIcon} from '@fortawesome/react-fontawesome';
|
2018-03-07 21:29:21 +00:00
|
|
|
|
|
|
|
import {MENU, DURATION} from '../common';
|
2018-01-29 19:44:18 +00:00
|
|
|
|
2018-03-07 21:29:21 +00:00
|
|
|
// styles contains the constant styles of the component.
|
|
|
|
const styles = {
|
|
|
|
menu: {
|
|
|
|
default: {
|
|
|
|
transition: `margin-left ${DURATION}ms`,
|
|
|
|
},
|
|
|
|
transition: {
|
|
|
|
entered: {marginLeft: -200},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
|
|
|
// themeStyles returns the styles generated from the theme for the component.
|
|
|
|
const themeStyles = theme => ({
|
|
|
|
list: {
|
2018-09-05 15:36:14 +00:00
|
|
|
background: theme.palette.grey[900],
|
2018-03-07 21:29:21 +00:00
|
|
|
},
|
|
|
|
listItem: {
|
2018-09-05 15:36:14 +00:00
|
|
|
minWidth: theme.spacing.unit * 7,
|
2018-03-07 21:29:21 +00:00
|
|
|
},
|
|
|
|
icon: {
|
|
|
|
fontSize: theme.spacing.unit * 3,
|
2019-04-03 05:14:02 +00:00
|
|
|
overflow: 'unset',
|
2018-03-07 21:29:21 +00:00
|
|
|
},
|
2018-01-29 19:44:18 +00:00
|
|
|
});
|
|
|
|
|
2018-03-07 21:29:21 +00:00
|
|
|
export type Props = {
|
|
|
|
classes: Object, // injected by withStyles()
|
|
|
|
opened: boolean,
|
|
|
|
changeContent: string => void,
|
|
|
|
};
|
2018-01-29 19:44:18 +00:00
|
|
|
|
2019-04-03 05:14:02 +00:00
|
|
|
type State = {}
|
|
|
|
|
2018-03-07 21:29:21 +00:00
|
|
|
// SideBar renders the sidebar of the dashboard.
|
2019-04-03 05:14:02 +00:00
|
|
|
class SideBar extends Component<Props, State> {
|
|
|
|
shouldComponentUpdate(nextProps: Readonly<Props>, nextState: Readonly<State>, nextContext: any) {
|
2018-03-07 21:29:21 +00:00
|
|
|
return nextProps.opened !== this.props.opened;
|
|
|
|
}
|
2018-01-29 19:44:18 +00:00
|
|
|
|
2018-03-07 21:29:21 +00:00
|
|
|
// clickOn returns a click event handler function for the given menu item.
|
|
|
|
clickOn = menu => (event) => {
|
|
|
|
event.preventDefault();
|
|
|
|
this.props.changeContent(menu);
|
|
|
|
};
|
2018-01-29 19:44:18 +00:00
|
|
|
|
2018-03-07 21:29:21 +00:00
|
|
|
// menuItems returns the menu items corresponding to the sidebar state.
|
|
|
|
menuItems = (transitionState) => {
|
|
|
|
const {classes} = this.props;
|
|
|
|
const children = [];
|
|
|
|
MENU.forEach((menu) => {
|
|
|
|
children.push((
|
|
|
|
<ListItem button key={menu.id} onClick={this.clickOn(menu.id)} className={classes.listItem}>
|
|
|
|
<ListItemIcon>
|
|
|
|
<Icon className={classes.icon}>
|
2019-04-03 05:14:02 +00:00
|
|
|
<FontAwesomeIcon icon={menu.icon} />
|
2018-03-07 21:29:21 +00:00
|
|
|
</Icon>
|
|
|
|
</ListItemIcon>
|
|
|
|
<ListItemText
|
|
|
|
primary={menu.title}
|
|
|
|
style={{
|
|
|
|
...styles.menu.default,
|
|
|
|
...styles.menu.transition[transitionState],
|
|
|
|
padding: 0,
|
|
|
|
}}
|
|
|
|
/>
|
|
|
|
</ListItem>
|
|
|
|
));
|
|
|
|
});
|
|
|
|
return children;
|
|
|
|
};
|
2018-01-29 19:44:18 +00:00
|
|
|
|
2018-03-07 21:29:21 +00:00
|
|
|
// menu renders the list of the menu items.
|
|
|
|
menu = (transitionState: Object) => (
|
|
|
|
<div className={this.props.classes.list}>
|
|
|
|
<List>
|
|
|
|
{this.menuItems(transitionState)}
|
|
|
|
</List>
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
|
|
|
|
render() {
|
|
|
|
return (
|
|
|
|
<Transition mountOnEnter in={this.props.opened} timeout={{enter: DURATION}}>
|
|
|
|
{this.menu}
|
|
|
|
</Transition>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
2018-01-29 19:44:18 +00:00
|
|
|
|
2018-03-07 21:29:21 +00:00
|
|
|
export default withStyles(themeStyles)(SideBar);
|