NavigationMini.jsx 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  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. // @flow
  15. import React from 'react'
  16. import { observer } from 'mobx-react'
  17. import styled, { css } from 'styled-components'
  18. import Navigation from '../../organisms/Navigation'
  19. import StyleProps from '../../styleUtils/StyleProps'
  20. import menuImage from './images/menu'
  21. const Wrapper = styled.div`
  22. margin-right: 38px;
  23. margin-left: 32px;
  24. `
  25. const Close = css`
  26. transform: rotate(0deg) translateX(0) translateY(0);
  27. `
  28. const Stub = styled.div`
  29. width: 20px;
  30. `
  31. const MenuImage = styled.div`
  32. cursor: pointer;
  33. width: 20px;
  34. height: 20px;
  35. ${props => props.open ? css`position: fixed;` : ''}
  36. top: 23px;
  37. z-index: 99;
  38. #top {
  39. ${props => props.open ? css`transform: rotate(45deg) translateX(0.5px) translateY(-4.5px);` : Close}
  40. transition: all ${StyleProps.animations.swift};
  41. }
  42. #bottom {
  43. ${props => props.open ? css`transform: rotate(-45deg) translateX(-6.5px) translateY(1.5px);` : Close}
  44. transition: all ${StyleProps.animations.swift};
  45. }
  46. `
  47. const NavigationStyled = styled(Navigation)`
  48. position: fixed;
  49. left: ${props => props.open ? 0 : -80}px;
  50. top: 0;
  51. padding-top: 24px;
  52. transition: left ${StyleProps.animations.swift};
  53. z-index: 9;
  54. `
  55. export const TEST_ID = 'navigationMini'
  56. type State = {
  57. open: boolean,
  58. }
  59. @observer
  60. class NavigationMini extends React.Component<{}, State> {
  61. state = {
  62. open: false,
  63. }
  64. handleMenuToggleClick() {
  65. this.setState({ open: !this.state.open })
  66. }
  67. render() {
  68. return (
  69. <Wrapper>
  70. <MenuImage
  71. open={this.state.open}
  72. onClick={() => { this.handleMenuToggleClick() }}
  73. dangerouslySetInnerHTML={{ __html: menuImage() }}
  74. data-test-id={`${TEST_ID}-toggleButton`}
  75. />
  76. {this.state.open ? <Stub /> : null}
  77. <NavigationStyled
  78. open={this.state.open}
  79. collapsed
  80. hideLogos
  81. />
  82. </Wrapper>
  83. )
  84. }
  85. }
  86. export default NavigationMini