All files / lib/ContentItem/ChatContent index.js

85% Statements 17/20
66% Branches 33/50
66.67% Functions 2/3
85% Lines 17/20
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 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158          89x                           10x   10x   20x 20x   20x 10x 5x     10x 10x 5x     5x         10x                       10x                                                                                                                           89x                             89x                                                 89x    
import React from 'react';
import PropTypes from 'prop-types';
import { snakeCase } from '@collab-ui/react/utils/snakeCase';
import { Spinner } from '@collab-ui/react';
 
const ChatContentItem = props => {
  const {
    actionNode,
    aspect,
    className,
    content,
    fileSize,
    gifIcon,
    isProtected,
    loading,
    onClick,
    style,
    title,
    ...otherProps
  } = props;
 
  const kebabify = (holder, aspect) => {
 
    const cases = ['fourThree', 'sixteenNine', 'threeTwo'];
    const kebab = snakeCase(aspect);
 
      if(holder==='container'){
        if(cases.includes(aspect)){
          return ` cui-content__chat-${kebab}`;
        }
      }
      else Eif(holder ==='inner'){
        if(cases.includes(aspect)){
          return ' cui-content-file--full';
        }
        else{
          return ` cui-content-file--chat-${kebab}`;
        }
      }
  };
 
  const handleKeyDown = e => {
    if (
      e.which === 32
      || e.which === 13
      || e.charCode === 32
      || e.charCode === 13
    ) {
      onClick && onClick(e);
      e.preventDefault();
    }
  };
 
  return (
    <div
      className={
        'cui-content__chat-inner-container' +
        `${(aspect === 'wide' && ' cui-content__chat-wide-container') || ''}` +
        `${(aspect && kebabify('container', aspect)) || ''}`
      }
      {...otherProps}
    >
      <div
        className={
          `${(aspect && kebabify('inner', aspect)) || ''}` +
          `${(!aspect && ' cui-content-file--full') || ''}` +
          `${(onClick && ' cui-content-file--clickable') || ''}` +
          `${(className && ` ${className}`) || ''}`
        }
        onClick={onClick}
        onKeyDown={handleKeyDown}
        role='presentation'
        style={{
          backgroundImage: content && `url(${content})`,
          ...style
        }}
      >
        {
          loading
          &&
          <div className={`${(content ? ' cui-content--opacity' : ' cui-content--centered')}`}>
            <Spinner />
          </div>
        }
        {
          gifIcon
          &&
          <i className={`${gifIcon} cui-content__gif`} />
        }
      </div>
      {
        !loading
        &&
        <div
          className={
            'cui-content__hover' +
            `${(aspect === 'wide' && ' cui-content__hover--wide') || ''}`
          }
        >
          <div className='cui-content__hover-files'>
            <span title={title} className='cui-content__hover-files--file-name'>{title}</span>
            <span className='cui-content__hover-files--file-size'>{fileSize}</span>
          </div>
          {
            actionNode && !isProtected &&
            <div className='cui-content__hover-icons'>
              {actionNode}
            </div>
          }
        </div>
      }
    </div>
    );
  };
 
ChatContentItem.defaultProps = {
  actionNode: null,
  aspect: null,
  className: '',
  content: '',
  fileSize: '',
  gifIcon:'',
  isProtected: null,
  loading: false,
  onClick: null,
  style: null,
  title: '',
  type: '',
};
 
ChatContentItem.propTypes = {
  actionNode: PropTypes.node,
  aspect: PropTypes.oneOf([
    'oneOne',
    'tall',
    'threeFour',
    'wide',
    'fourThree',
    'nineSixteen',
    'sixteenNine',
    'twoThree',
    'threeTwo'
  ]),
  className: PropTypes.string,
  content: PropTypes.string,
  fileSize: PropTypes.string,
  gifIcon: PropTypes.string,
  isProtected: PropTypes.bool,
  loading: PropTypes.bool,
  onClick: PropTypes.func,
  style: PropTypes.object,
  title: PropTypes.string,
  type: PropTypes.string,
};
 
ChatContentItem.displayName = 'ChatContentItem';
 
export default ChatContentItem;