SideMenu.jsx 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. /*
  2. Copyright (C) 2017 Cloudbase Solutions SRL
  3. This program is free software: you can redistribute it and/or modify
  4. it under the terms of the GNU Affero General Public License as
  5. published by the Free Software Foundation, either version 3 of the
  6. License, or (at your option) any later version.
  7. This program is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. GNU Affero General Public License for more details.
  11. You should have received a copy of the GNU Affero General Public License
  12. along with this program. If not, see <http://www.gnu.org/licenses/>.
  13. */
  14. import React from 'react'
  15. import styled, { css } from 'styled-components'
  16. import StyleProps from '../../styleUtils/StyleProps'
  17. import hamburgerImage from './images/hamburger'
  18. import backgroundImage from './images/star-bg.jpg'
  19. const Wrapper = styled.div`
  20. margin-right: 20px;
  21. `
  22. const OpenTopLayer = css`
  23. transform: rotate(45deg) translateX(3px);
  24. `
  25. const OpenMiddleLayer = css`
  26. transform: rotate(-45deg) translateY(7px) translateX(-4px);
  27. `
  28. const Close = css`
  29. transform: rotate(0) translateY(0) translateX(0);
  30. opacity: 1;
  31. `
  32. const OpenBottomLayer = css`
  33. opacity: 0;
  34. `
  35. const Hamburger = styled.div`
  36. cursor: pointer;
  37. #top-layer, #middle-layer, #bottom-layer {
  38. transition: all ${StyleProps.animations.swift};
  39. }
  40. #top-layer {
  41. ${props => props.open ? OpenTopLayer : Close};
  42. }
  43. #middle-layer {
  44. transform-origin: 0% 100%;
  45. ${props => props.open ? OpenMiddleLayer : Close};
  46. }
  47. #bottom-layer {
  48. ${props => props.open ? OpenBottomLayer : Close};
  49. }
  50. `
  51. const Menu = styled.div`
  52. position: fixed;
  53. background: url('${backgroundImage}');
  54. top: 64px;
  55. left: ${props => props.open ? 0 : '-224px'};
  56. bottom: 0;
  57. width: 184px;
  58. padding-left: 40px;
  59. padding-top: 60px;
  60. transition: all ${StyleProps.animations.swift};
  61. display: flex;
  62. flex-direction: column;
  63. `
  64. const MenuItem = styled.a`
  65. font-size: 18px;
  66. color: white;
  67. margin-bottom: 24px;
  68. cursor: pointer;
  69. text-decoration: none;
  70. `
  71. class SideMenu extends React.Component {
  72. constructor() {
  73. super()
  74. this.state = {
  75. open: false,
  76. }
  77. }
  78. handleHamburgerClick() {
  79. this.setState({ open: !this.state.open })
  80. }
  81. render() {
  82. return (
  83. <Wrapper>
  84. <Hamburger
  85. open={this.state.open}
  86. onClick={() => { this.handleHamburgerClick() }}
  87. dangerouslySetInnerHTML={{ __html: hamburgerImage() }}
  88. />
  89. <Menu open={this.state.open}>
  90. <MenuItem href="/#/replicas">Replicas</MenuItem>
  91. <MenuItem href="/#/migrations">Migrations</MenuItem>
  92. <MenuItem href="/#/endpoints">Cloud Endpoints</MenuItem>
  93. </Menu>
  94. </Wrapper>
  95. )
  96. }
  97. }
  98. export default SideMenu