2017-12-21 09:54:38 -06:00
|
|
|
// @flow
|
|
|
|
|
2017-11-14 11:34:00 -06: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';
|
|
|
|
|
2017-12-21 09:54:38 -06:00
|
|
|
import withStyles from 'material-ui/styles/withStyles';
|
|
|
|
import List, {ListItem, ListItemIcon, ListItemText} from 'material-ui/List';
|
|
|
|
import Icon from 'material-ui/Icon';
|
|
|
|
import Transition from 'react-transition-group/Transition';
|
|
|
|
import {Icon as FontAwesome} from 'react-fa';
|
|
|
|
|
2018-01-23 14:51:04 -06:00
|
|
|
import {MENU, DURATION} from '../common';
|
2017-11-14 11:34:00 -06:00
|
|
|
|
2018-01-23 14:51:04 -06:00
|
|
|
// styles contains the constant styles of the component.
|
|
|
|
const styles = {
|
|
|
|
menu: {
|
|
|
|
default: {
|
|
|
|
transition: `margin-left ${DURATION}ms`,
|
|
|
|
},
|
|
|
|
transition: {
|
|
|
|
entered: {marginLeft: -200},
|
|
|
|
},
|
|
|
|
},
|
2017-12-21 09:54:38 -06:00
|
|
|
};
|
2018-01-23 14:51:04 -06:00
|
|
|
|
|
|
|
// themeStyles returns the styles generated from the theme for the component.
|
|
|
|
const themeStyles = theme => ({
|
2017-12-21 09:54:38 -06:00
|
|
|
list: {
|
2018-03-08 02:22:21 -06:00
|
|
|
background: theme.palette.grey[900],
|
2017-12-21 09:54:38 -06:00
|
|
|
},
|
|
|
|
listItem: {
|
2018-03-08 02:22:21 -06:00
|
|
|
minWidth: theme.spacing.unit * 7,
|
2017-12-21 09:54:38 -06:00
|
|
|
},
|
|
|
|
icon: {
|
|
|
|
fontSize: theme.spacing.unit * 3,
|
|
|
|
},
|
2017-11-14 11:34:00 -06:00
|
|
|
});
|
2018-01-23 14:51:04 -06:00
|
|
|
|
2017-12-21 09:54:38 -06:00
|
|
|
export type Props = {
|
2018-01-23 14:51:04 -06:00
|
|
|
classes: Object, // injected by withStyles()
|
2017-12-21 09:54:38 -06:00
|
|
|
opened: boolean,
|
2018-01-23 14:51:04 -06:00
|
|
|
changeContent: string => void,
|
2017-12-21 09:54:38 -06:00
|
|
|
};
|
2018-01-23 14:51:04 -06:00
|
|
|
|
2017-12-21 09:54:38 -06:00
|
|
|
// SideBar renders the sidebar of the dashboard.
|
|
|
|
class SideBar extends Component<Props> {
|
|
|
|
shouldComponentUpdate(nextProps) {
|
|
|
|
return nextProps.opened !== this.props.opened;
|
|
|
|
}
|
2017-11-14 11:34:00 -06:00
|
|
|
|
2018-01-23 14:51:04 -06:00
|
|
|
// clickOn returns a click event handler function for the given menu item.
|
|
|
|
clickOn = menu => (event) => {
|
|
|
|
event.preventDefault();
|
|
|
|
this.props.changeContent(menu);
|
|
|
|
};
|
|
|
|
|
|
|
|
// menuItems returns the menu items corresponding to the sidebar state.
|
2017-12-21 09:54:38 -06:00
|
|
|
menuItems = (transitionState) => {
|
|
|
|
const {classes} = this.props;
|
|
|
|
const children = [];
|
|
|
|
MENU.forEach((menu) => {
|
2018-01-23 14:51:04 -06:00
|
|
|
children.push((
|
|
|
|
<ListItem button key={menu.id} onClick={this.clickOn(menu.id)} className={classes.listItem}>
|
2017-12-21 09:54:38 -06:00
|
|
|
<ListItemIcon>
|
|
|
|
<Icon className={classes.icon}>
|
|
|
|
<FontAwesome name={menu.icon} />
|
|
|
|
</Icon>
|
|
|
|
</ListItemIcon>
|
|
|
|
<ListItemText
|
|
|
|
primary={menu.title}
|
|
|
|
style={{
|
2018-01-23 14:51:04 -06:00
|
|
|
...styles.menu.default,
|
|
|
|
...styles.menu.transition[transitionState],
|
2017-12-21 09:54:38 -06:00
|
|
|
padding: 0,
|
|
|
|
}}
|
|
|
|
/>
|
2018-01-23 14:51:04 -06:00
|
|
|
</ListItem>
|
|
|
|
));
|
2017-12-21 09:54:38 -06:00
|
|
|
});
|
|
|
|
return children;
|
|
|
|
};
|
2017-11-14 11:34:00 -06:00
|
|
|
|
2017-12-21 09:54:38 -06:00
|
|
|
// menu renders the list of the menu items.
|
2018-01-23 14:51:04 -06:00
|
|
|
menu = (transitionState: Object) => (
|
|
|
|
<div className={this.props.classes.list}>
|
|
|
|
<List>
|
|
|
|
{this.menuItems(transitionState)}
|
|
|
|
</List>
|
|
|
|
</div>
|
|
|
|
);
|
2017-12-21 09:54:38 -06:00
|
|
|
|
|
|
|
render() {
|
|
|
|
return (
|
|
|
|
<Transition mountOnEnter in={this.props.opened} timeout={{enter: DURATION}}>
|
|
|
|
{this.menu}
|
|
|
|
</Transition>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
2017-11-14 11:34:00 -06:00
|
|
|
|
2018-01-23 14:51:04 -06:00
|
|
|
export default withStyles(themeStyles)(SideBar);
|