All files / src/Attachment Attachment.js

100% Statements 5/5
52.63% Branches 10/19
100% Functions 1/1
100% Lines 5/5

Press n or j to go to the next uncovered block, b, p or k for the previous block.

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                                              1x 1x 1x                                                                                                                                       1x 1x              
import React from 'react';
import { defaultProps } from './props/defaultProps';
import { propTypes } from './props/propTypes';
import { Icon } from '@zohodesk/icons';
import { Container, Box } from '@zohodesk/components/lib/Layout';
import Link from '../Link/Link';
import style from './Attachment.module.css';
export default class Attachment extends React.Component {
  render() {
    let {
      onClick,
      dataId,
      size,
      iconName,
      fileName,
      fileSize,
      downloadLink,
      palette,
      tooltip,
      fileInfo,
      i18nKeys,
      dataSelectorId,
      isDisabled
    } = this.props;
    let { downloadTitle = 'Download' } = i18nKeys;
    return (
      <Container
        isInline
        className={`${style.attachment} ${ isDisabled ? style.disableAttachment : "" } ${onClick ? style.attachmentHover : ''} ${style[`palette_${palette}`]} ${
          style[size]
        }`}
        onClick={onClick}
        dataId={dataId}
        data-title={tooltip}
        alignBox='row'
        isCover={false}
        dataSelectorId={dataSelectorId}
        tabIndex="0"
      >
        {iconName ? (
          <Box className={style.attachleft}>
            <Container align='both'>
              <Icon name={iconName} iconClass={style.attachIcon} />
            </Container>
          </Box>
        ) : null}
        <Box flexible className={style.attachright}>
          <Container align='horizontal'>
            {fileName ? (
              <Box className={style.atatchName} data-title={fileName}>
                {fileName}
              </Box>
            ) : null}
            <Box className={style.footer}>
              <Container alignBox='row' align='baseline' isCover={false}>
                {fileSize ? (
                  <Box className={style.attachSize} adjust shrink data-title={fileSize}>
                    {fileSize}
                  </Box>
                ) : null}
 
                {fileInfo ? (
                  <>
                    <Box className={style.dot}></Box>
                    <Box className={style.attachSize} adjust shrink data-title={fileInfo}>
                      {fileInfo}
                    </Box>
                  </>
                ) : null}
              </Container>
            </Box>
          </Container>
        </Box>
        {downloadLink && !isDisabled ? (
          <Link
            target='_self'
            href={downloadLink}
            className={style.attachDownload}
            title={downloadTitle}
            hasReload={true}
            dataId={`${dataId}_download`}
          >
            <Icon name='ZD-downloadNew' iconClass={style.downIcon} />
          </Link>
        ) : null}
        {
          isDisabled ? 
          <div data-title={tooltip} className={style.disableLayer}></div> : null
        }
      </Container>
    );
  }
}
Attachment.propTypes = propTypes;
Attachment.defaultProps = defaultProps;
 
// if (__DOCS__) {
//   Attachment.docs = {
//     componentGroup: 'Attachment'
//   };
// }