# All files / components/ChatNotification index.js

100% Statements 15/15
75% Branches 3/4
100% Functions 2/2
100% Lines 15/15

    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

    1x

    1x

    1x

    7x

    7x

    7x

    7x

    3x

    7x

    7x

    7x

    7x

    1x

    1x

    1x

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

    import CloseButton from '../CloseButton';

    const StyledChatSnippet = styled.div`
      height: 100%;
      position: relative;
    `;
    StyledChatSnippet.displayName = 'StyledChatSnippet';

    const ChatNotification = (props) => {
      const {
        children, onDismiss, onClick, withClose, closeMargin,
        width, height, border, padding, boxShadow, borderRadius,
      } = props;

      const StyledScrollableContentContainer = styled.div`
        overflow-y: auto;
      `;
      StyledScrollableContentContainer.displayName = 'StyledScrollableContentContainer';

      const StyledNotificationContainer = styled.div`
        display: flex;
        background-color: ${() => props.background ? props.background : 'transparent'};
        width: ${width};
        height: ${height};

        border: ${border};
        padding: ${padding};
        box-shadow: ${boxShadow};

        border-radius: ${borderRadius};
        overflow-y: auto;
      `;
      StyledNotificationContainer.displayName = 'StyledNotificationContainer';

      const StyledNotificationBody = styled.div`
        &:focus {
          outline: none;
        }
      `;
      StyledNotificationBody.displayName = 'StyledNotificationBody';

      return (
        <StyledNotificationContainer>
          {withClose && (
            <CloseButton onClick={onDismiss} margin={closeMargin}></CloseButton>
          )}
          <StyledScrollableContentContainer>
            <StyledNotificationBody onClick={onClick}>
              <StyledChatSnippet>
                {children}
              </StyledChatSnippet>
            </StyledNotificationBody>
          </StyledScrollableContentContainer>
        </StyledNotificationContainer>
      );
    };

    ChatNotification.propTypes = {
      /**
       * Function to execute when user clicks Dismiss Button
       */
      onDismiss: PropTypes.func,
      /**
       * Function to execute when user clicks on Notification content
       */
      onClick: PropTypes.func,
      /**
       * Set the width of the notification
       */
      width: PropTypes.string,
      /**
       * Set the height of the notification
       */
      height: PropTypes.string,
      /**
       * Padding for the notification
       */
      padding: PropTypes.string,
      /**
       * background color for the notification
       */
      background: PropTypes.string,
      /**
       * Border-radius for the notification
       */
      borderRadius: PropTypes.string,
      /**
       * box-shadow for the notification
       */
      border: PropTypes.string,
      /**
       * box-shadow for the notification
       */
      boxShadow: PropTypes.string,
      /**
       * withClose: Whether or not show a dismiss button
       */
      withClose: PropTypes.bool,
      /**
       * closeMargin: The margin for the close button,
       */
      closeMargin: PropTypes.string,
      /**
       * Border-radius for the notification
       */
      /**
       * Children component this notification contains
       */
      children: PropTypes.node,
    };

    ChatNotification.defaultProps = {
      onDismiss: null,
      withClose: true,
      onClick: null,
      width: '100%',
      height: '100%',
      background: 'transparent',
      padding: '2px 2px 20px 20px',
      borderRadius: '10px',
      border: 'none',
      boxShadow: 'none',
    };

    ChatNotification.displayName = 'ChatNotification';

    export default ChatNotification;