Header.jsx 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. // Copyright 2017 The go-ethereum Authors
  2. // This file is part of the go-ethereum library.
  3. //
  4. // The go-ethereum library is free software: you can redistribute it and/or modify
  5. // it under the terms of the GNU Lesser General Public License as published by
  6. // the Free Software Foundation, either version 3 of the License, or
  7. // (at your option) any later version.
  8. //
  9. // The go-ethereum library is distributed in the hope that it will be useful,
  10. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. // GNU Lesser General Public License for more details.
  13. //
  14. // You should have received a copy of the GNU Lesser General Public License
  15. // along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>.
  16. import React, {Component} from 'react';
  17. import PropTypes from 'prop-types';
  18. import classNames from 'classnames';
  19. import {withStyles} from 'material-ui/styles';
  20. import AppBar from 'material-ui/AppBar';
  21. import Toolbar from 'material-ui/Toolbar';
  22. import Typography from 'material-ui/Typography';
  23. import IconButton from 'material-ui/IconButton';
  24. import MenuIcon from 'material-ui-icons/Menu';
  25. import {DRAWER_WIDTH} from './Common.jsx';
  26. // Styles for the Header component.
  27. const styles = theme => ({
  28. appBar: {
  29. position: 'absolute',
  30. transition: theme.transitions.create(['margin', 'width'], {
  31. easing: theme.transitions.easing.sharp,
  32. duration: theme.transitions.duration.leavingScreen,
  33. }),
  34. },
  35. appBarShift: {
  36. marginLeft: DRAWER_WIDTH,
  37. width: `calc(100% - ${DRAWER_WIDTH}px)`,
  38. transition: theme.transitions.create(['margin', 'width'], {
  39. easing: theme.transitions.easing.easeOut,
  40. duration: theme.transitions.duration.enteringScreen,
  41. }),
  42. },
  43. menuButton: {
  44. marginLeft: 12,
  45. marginRight: 20,
  46. },
  47. hide: {
  48. display: 'none',
  49. },
  50. });
  51. // Header renders a header, which contains a sidebar opener icon when that is closed.
  52. class Header extends Component {
  53. render() {
  54. // The classes property is injected by withStyles().
  55. const {classes} = this.props;
  56. return (
  57. <AppBar className={classNames(classes.appBar, this.props.opened && classes.appBarShift)}>
  58. <Toolbar disableGutters={!this.props.opened}>
  59. <IconButton
  60. color="contrast"
  61. aria-label="open drawer"
  62. onClick={this.props.open}
  63. className={classNames(classes.menuButton, this.props.opened && classes.hide)}
  64. >
  65. <MenuIcon />
  66. </IconButton>
  67. <Typography type="title" color="inherit" noWrap>
  68. Go Ethereum Dashboard
  69. </Typography>
  70. </Toolbar>
  71. </AppBar>
  72. );
  73. }
  74. }
  75. Header.propTypes = {
  76. classes: PropTypes.object.isRequired,
  77. opened: PropTypes.bool.isRequired,
  78. open: PropTypes.func.isRequired,
  79. };
  80. export default withStyles(styles)(Header);