File size: 1,344 Bytes
1e92f2d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
// @flow
import * as React from 'react';
import Icon from 'src/components/icon';
import { Wrapper, MenuContainer, MenuOverlay, Absolute } from './style';

type Props = {
  hasNavBar?: boolean,
  darkContext?: boolean,
  hasTabBar?: boolean,
  children: React$Node,
};

type State = {
  menuIsOpen: boolean,
};
class Menu extends React.Component<Props, State> {
  state = {
    menuIsOpen: false,
  };

  toggleMenu() {
    this.setState({ menuIsOpen: !this.state.menuIsOpen });
  }

  render() {
    const { hasNavBar, darkContext, hasTabBar } = this.props;
    const { menuIsOpen } = this.state;
    return (
      <Wrapper darkContext={darkContext}>
        <Icon
          data-cy={'community-menu-open'}
          glyph={'menu'}
          onClick={() => this.toggleMenu()}
        />
        <Absolute open={this.state.menuIsOpen} hasNavBar={hasNavBar}>
          <MenuContainer hasNavBar={hasNavBar} hasTabBar={hasTabBar}>
            {menuIsOpen && this.props.children}
          </MenuContainer>
          <Icon
            glyph={'view-close'}
            onClick={() => this.toggleMenu()}
            hasNavBar={hasNavBar}
          />
          <MenuOverlay
            data-cy={'community-menu-close'}
            onClick={() => this.toggleMenu()}
          />
        </Absolute>
      </Wrapper>
    );
  }
}

export default Menu;