# All files / components/Header index.js

100% Statements 9/9
100% Branches 12/12
100% Functions 3/3
100% Lines 9/9

    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

    2x

    2x

    6x
    6x

    1x

    1x

    2x

    2x

    2x

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

    import styled from 'styled-components';
    import { Flex, Box } from 'grid-styled';
    import {
      MdKeyboardArrowDown, MdMenu,
    } from 'react-icons/md';
    import Avatar from '../Avatar';

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

    const Header = ({
      title, subtitle, person, toggleChat, openMenu, showMinimizeButton, showMenuButton, leftButtons, rightButtons,
    }) => {
      const { avatar = false, status = '' } = person;
      return (
        <div>
          <Flex alignItems="center">
            {showMenuButton
            && (
              <Box flex="0 0 auto" mb="auto" width="40px">
                <button onClick={openMenu}>
                  <MdMenu size={20} />
                </button>
              </Box>
            )
            }
            {leftButtons.map((btn) => (
              <Box key={btn.id} flex="0 0 auto" mb="auto" width="40px">
                <button onClick={btn.onClick}>
                  {btn.icon}
                </button>
              </Box>
            ))}

            <Box flex="1 1 auto">
              {avatar
              && (
                <StyledAvatarContainer>
                  <Avatar
                    src={avatar}
                    size="medium"
                    withStatus={status.length > 0}
                    status={status}
                  />
                </StyledAvatarContainer>
              )
              }
              {title && <h4>{title}</h4>}
              {subtitle && <span>{subtitle}</span>}
            </Box>

            {rightButtons.map((btn) => (
              <Box key={btn.id} flex="0 0 auto" mb="auto" width="40px">
                <button onClick={btn.onClick}>
                  {btn.icon}
                </button>
              </Box>
            ))}

            {showMinimizeButton
            && (
              <Box flex="0 0 auto" mb="auto" width="40px">
                <button onClick={toggleChat}>
                  <MdKeyboardArrowDown size={20} />
                </button>
              </Box>
            )
            }
          </Flex>
        </div>
      );
    };

    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;