# All files / components/FileMessage index.js

75% Statements 21/28
100% Branches 0/0
30% Functions 3/10
77.78% Lines 21/27

    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

    3x

    3x

    3x

    3x

    3x

    3x

    3x

    3x

    3x

    3x

    3x

    3x
    3x

    1x
    1x

    3x
    3x
    3x

    3x

    3x

    3x

     import React, { Component } from 'react';
    import PropTypes from 'prop-types';
    import styled from 'styled-components';
    import { Icon } from 'react-icons-kit';
    import { file } from 'react-icons-kit/fa/file';

    // Helpers components
    import MessageTimeBox from '../MessageBox/MessageTimeBox';

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

    const FaFile = (props) => <Icon icon={file} {...props} />;

    const StyledFileMessageContainer = styled.div`
      display: inline-block;
    `;
    StyledFileMessageContainer.displayName = 'StyledFileMessageContainer';

    const StyledFileMessageBody = styled.div`
      background: #e9e9e9;
      cursor: pointer;
      display: flex;
      border-radius: 5px;
      margin-top: -3px;
      margin-right: -6px;
      margin-left: -6px;
      align-items: center;
      min-height: 52px;
      padding: 5px;
      outline: none;
      border:none;
    `;
    StyledFileMessageBody.displayName = 'StyledFileMessageBody';

    const StyledFileIcon = styled.div`
      font-size: 30px;
      align-items: center;
      display: flex;
      padding: 0 10px;
      color: ${(props) => themeColor(props.theme, 'accent', 'base')};

      div {
        font-size: 10px;
        margin-top: 3px;
        max-width: 52px;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
      }
    `;
    StyledFileIcon.displayName = 'StyledFileIcon';

    const StyledFileName = styled.div`
      color: ${(props) => textColor(props.theme, 'light', 'primary')};
      font-size: ${(props) => props.theme.typography.classes.footnote.fontSize};
      line-height: ${(props) => props.theme.typography.classes.footnote.lineHeight};
      font-weight: ${(props) => props.theme.typography.weights.fontWeightMedium};
      min-width: 100px;
      max-width: 80%;
      white-space: nowrap;
      overflow: hidden;
      text-overflow: ellipsis;
    `;
    StyledFileName.displayName = 'StyledFileName';

    const StyledFileDownloadButton = styled.div`
      color: ${(props) => themeColor(props.theme, 'primary', 'base')};
      padding: 0 10px;
      font-size: 30px;
      align-items: center;
      display: flex;
      user-select: none;
    `;
    StyledFileDownloadButton.displayName = 'StyledFileDownloadButton';

    export class FileMessage extends Component {
      constructor(props) {
        super(props);
        this.onClick = this.onClick.bind(this);
      }

      onClick() {
        const { onOpen } = this.props;
        onOpen();
      }

      render() {
        const { className, message } = this.props;
        const { text } = message;
        return (
          <StyledFileMessageContainer className={className}>
            <StyledFileMessageBody onClick={this.onClick}>
              <StyledFileIcon>
                <FaFile />
              </StyledFileIcon>
              <StyledFileName>
                {text}
              </StyledFileName>
            </StyledFileMessageBody>
            <MessageTimeBox
              message={message}
            />
          </StyledFileMessageContainer>
        );
      }
    }

    FileMessage.propTypes = {
      className: PropTypes.string,
      message: PropTypes.object.isRequired,
      onOpen: PropTypes.func,
    };

    FileMessage.defaultProps = {
      className: 'LT-FileMessage-Container',
      onOpen: null,
    };

    FileMessage.displayName = 'FileMessage';

    export default FileMessage;