# All files / components/Header index.js

100% Statements 21/21
100% Branches 12/12
100% Functions 5/5
100% Lines 19/19

    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
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158

    2x
    2x

    2x

    2x

    2x

    2x

    2x

    2x

    2x

    2x

    2x

    2x

    6x
    6x

    1x

    1x

    2x

    2x

    2x

     import React from 'react';
    import PropTypes from 'prop-types';

    import styled from 'styled-components';
    import { Icon } from 'react-icons-kit';
    import { ic_keyboard_arrow_down as KeboardArrowDown } from 'react-icons-kit/md/ic_keyboard_arrow_down';
    import { ic_menu as Menu } from 'react-icons-kit/md/ic_menu';
    import { headerMenuButton } from '../../utils/style';

    import Avatar from '../Avatar';

    const MdKeyboardArrowDown = (props) => <Icon icon={KeboardArrowDown} {...props} />;
    const MdMenu = (props) => <Icon icon={Menu} {...props} />;

    const StyledAvatarContainer = styled.div`
      margin-bottom: 10px;
    `;

    const StyledHeaderContainer = styled.div`
      display: flex;
      justify-content: space-between;
    `;

    const StyledLeftDiv = styled.div`
      flex: 1;
      display: flex;
      margin-right: auto;
      justify-content: flex-start;
    `;

    const StyledCenterDiv = styled.div`
      display: flex;
      flex-grow: 1;
      flex-wrap: wrap;
      justify-content: center;
      align-items: center;
    `;

    const StyledRightDiv = styled.div`
      flex: 1;
      display: flex;
      margin-left: auto;
      justify-content: flex-end;
    `;

    const StyledHeaderTitle = styled.h4`
      display: flex;
      flex-basis: 100%;
      justify-content: center;
    `;

    const StyledHeaderSubTitle = styled.span`
      display: flex;
      flex-basis: 100%;
      justify-content: center;
    `;

    const StyledButtonContainer = styled.div`
      ${headerMenuButton('51px')};
    `;
    StyledButtonContainer.displayName = 'StyledButtonContainer';

    const Header = ({
      title, subtitle, person, toggleChat, openMenu, showMinimizeButton, showMenuButton, leftButtons, rightButtons,
    }) => {
      const { avatar = false, status = '' } = person;
      return (
        <StyledHeaderContainer>
          <StyledLeftDiv>
            {showMenuButton
            && (
              <StyledButtonContainer onClick={openMenu}>
                <MdMenu size={20} />
              </StyledButtonContainer>
            )}
            {leftButtons.map((btn) => (
              <StyledButtonContainer onClick={btn.onClick}>
                {btn.icon}
              </StyledButtonContainer>
            ))}
          </StyledLeftDiv>

          <StyledCenterDiv>
            {avatar
              && (
                <StyledAvatarContainer>
                  <Avatar
                    src={avatar}
                    size="medium"
                    withStatus={status.length > 0}
                    status={status}
                  />
                </StyledAvatarContainer>
              )
            }
            {title && <StyledHeaderTitle>{title}</StyledHeaderTitle>}
            {subtitle && <StyledHeaderSubTitle>{subtitle}</StyledHeaderSubTitle>}
          </StyledCenterDiv>

          <StyledRightDiv>
            {rightButtons.map((btn) => (
              <StyledButtonContainer onClick={btn.onClick}>
                {btn.icon}
              </StyledButtonContainer>
            ))}

            {showMinimizeButton
              && (
                <StyledButtonContainer onClick={toggleChat}>
                  <MdKeyboardArrowDown size={20} />
                </StyledButtonContainer>
              )
            }
          </StyledRightDiv>
        </StyledHeaderContainer>
      );
    };

    Header.propTypes = {
      title: PropTypes.string,
      subtitle: PropTypes.string,
      person: PropTypes.shape({
        avatar: PropTypes.string,
        status: PropTypes.string,
        email: PropTypes.string,
        type: PropTypes.string,
      }),
      toggleChat: PropTypes.func,
      openMenu: PropTypes.func,
      showMinimizeButton: PropTypes.bool,
      showMenuButton: PropTypes.bool,
      leftButtons: PropTypes.arrayOf(PropTypes.shape({
        onClick: PropTypes.func,
        icon: PropTypes.node,
      })),
      rightButtons: PropTypes.arrayOf(PropTypes.shape({
        onClick: PropTypes.func,
        icon: PropTypes.node,
      })),
    };

    Header.defaultProps = {
      title: '',
      subtitle: '',
      person: {},
      toggleChat: null,
      openMenu: null,
      showMinimizeButton: true,
      showMenuButton: true,
      leftButtons: [],
      rightButtons: [],
    };

    Header.displayName = 'Header';

    export default Header;