# All files / components/FileMessage index.js

89.29% Statements 25/28
87.5% Branches 14/16
60% Functions 3/5
92.59% Lines 25/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
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138

    3x

    3x

    3x

    3x

    3x

    3x

    3x

    3x

    3x

    3x

    4x
    4x

    2x
    2x
    2x
    2x
    1x
    1x
    1x

    4x
    4x
    4x

    3x

    3x

    3x

     import React, { Component } from 'react';
    import PropTypes from 'prop-types';
    import styled from 'styled-components';

    import {
      FaCloudDownloadAlt, FaFile,
    } from 'react-icons/fa';

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

    const StyledFileMessageContainer = styled.div`
      display: inline-block;
      margin-bottom: 10px;
      max-width: calc(100% - 10px);
    `;
    StyledFileMessageContainer.displayName = 'StyledFileMessageContainer';

    const StyledFileMessageBody = styled.div`
      background: #e9e9e9;
      display: flex;
      border-radius: 5px;
      margin-top: -3px;
      margin-right: -6px;
      margin-left: -6px;
      margin-bottom: 10px;
      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`
      font-size: 13.6px;
      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;
      cursor: pointer;
      user-select: none;
    `;
    StyledFileDownloadButton.displayName = 'StyledFileDownloadButton';

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

      onClick() {
        const { data, onDownload, onOpen } = this.props;
        const { status } = data;
        Iif (!status) { return; }
        if (!status.download && onDownload) {
          onDownload();
        } else Eif (status.download && onOpen) {
          onOpen();
        }
      }

      render() {
        const { className, data, text } = this.props;
        const { status } = data;
        return (
          <StyledFileMessageContainer className={className}>
            <StyledFileMessageBody>
              <StyledFileIcon>
                <FaFile />
              </StyledFileIcon>
              <StyledFileName>
                {text}
              </StyledFileName>
              <StyledFileDownloadButton onClick={this.onClick}>
                {
                  status && <FaCloudDownloadAlt />
                }
              </StyledFileDownloadButton>
              {
                status
                    && typeof status.loading === 'number'
                    && status.loading !== 0
                    && <div />
              }
            </StyledFileMessageBody>
          </StyledFileMessageContainer>
        );
      }
    }

    FileMessage.propTypes = {
      className: PropTypes.string,
      text: PropTypes.string,
      data: PropTypes.object,
      onDownload: PropTypes.func,
      onOpen: PropTypes.func,
    };

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

    FileMessage.displayName = 'FileMessage';

    export default FileMessage;