# All files / components/ChatCard index.js

100% Statements 21/21
100% Branches 4/4
100% Functions 10/10
100% Lines 21/21

    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

    1x

    4x

    4x

    2x

    2x
    2x

    4x

    4x
    2x
    2x
    2x

    4x

    4x
    2x
    2x
    2x

    4x

    4x

    1x

    1x

    1x

     import React from 'react';
    import PropTypes from 'prop-types';
    import styled from 'styled-components';
    import { Flex, Box } from 'grid-styled';

    import { ellipsis, textColor, themeColor } from '../../utils/style';

    const ChatCard = (props) => {
      const {
        title, body, onClick,
        width, height, border, borderRadius, boxShadow,
      } = props;

      const StyledCardContainer = styled.div`
        max-width: ${width}px;
        max-height: ${height}px;
        padding: 15px;
        -webkit-box-sizing: border-box;
        box-sizing: border-box;
        background-color: ${(innerProps) => themeColor(innerProps.theme, 'background', 'light')};
        border: ${border};
        border-radius: ${borderRadius};
        box-shadow: ${boxShadow};
        font-size: ${(innerProps) => innerProps.theme.typography.classes.caption.fontSize};
        line-height: ${(innerProps) => innerProps.theme.typography.classes.caption.lineHeight};
        height: 100%;
        position: relative;
      `;
      StyledCardContainer.displayName = 'StyledCardContainer';

      const StyledCardBody = styled.div`
        color: ${(innerProps) => textColor(innerProps.theme, 'light', 'primary')};
        font-size: ${(innerProps) => innerProps.theme.typography.classes.footnote.fontSize};
        line-height: ${(innerProps) => innerProps.theme.typography.classes.footnote.lineHeight};
        overflow: hidden;
        -webkit-animation: intercom-notification-body-animation .5s ease;
        animation: intercom-notification-body-animation .5s ease;
        display: -webkit-box;
        -webkit-line-clamp: 2;
        -webkit-box-orient: vertical;
      `;
      StyledCardBody.displayName = 'StyledCardBody';

      const StyledCardTitle = styled.div`
        color: ${(innerProps) => textColor(innerProps.theme, 'light', 'primary')};
        font-size: ${(innerProps) => innerProps.theme.typography.classes.caption.fontSize};
        font-weight: ${(innerProps) => innerProps.theme.typography.weights.fontWeightBold};
        display: inline-block;
        vertical-align: middle;
        line-height: 1.2;
        margin-bottom: 4px;
        ${ellipsis('100%')}
      `;
      StyledCardTitle.displayName = 'StyledCardTitle';

      return (
        <StyledCardContainer onClick={onClick}>
          {!!title.length && (
            <Flex flex="1 1 auto" alignItems="center">
              <StyledCardTitle>{title}</StyledCardTitle>
            </Flex>
          )}
          {!!body.length && (
            <Flex flex="1 1 auto">
              <Box ml="auto" width={1}>
                <StyledCardBody>{body}</StyledCardBody>
              </Box>
            </Flex>
          )}
        </StyledCardContainer>
      );
    };

    ChatCard.propTypes = {
      /**
       * types: default, rounded, circle
       */
      title: PropTypes.string,
      /**
       * types: default, rounded, circle
       */
      body: PropTypes.string,
      /**
       * Function to execute when user clicks on Notification content
       */
      onClick: PropTypes.func,
      /**
       * width: Set the width of the notification
       */
      width: PropTypes.number,
      /**
       * height: Set the height of the card
       */
      height: PropTypes.number,
      /**
       * border: Set the border property of the card
       */
      border: PropTypes.string,
      /**
       * borderRadius: Set the borderRadius property of the card
       */
      borderRadius: PropTypes.string,
      /**
       * boxShadow: Set the boxShadow property of the card
       */
      boxShadow: PropTypes.string,
    };

    ChatCard.defaultProps = {
      title: '',
      body: '',
      border: 'none',
      borderRadius: '6px',
      boxShadow: 'none',
      onClick: null,
      height: 150,
      width: 250,
    };

    ChatCard.displayName = 'ChatCard';

    export default ChatCard;