All files / src/FlipCard FlipCard.js

53.33% Statements 8/15
90.9% Branches 20/22
50% Functions 2/4
53.33% Lines 8/15

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 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                            81x 81x 81x                                                                                             81x     81x 81x                                                                                                                                                   2x 2x            
import React, { Component } from 'react';
import { defaultProps } from './props/defaultProps';
import { propTypes } from './props/propTypes';
import AvatarUser from '../avatar/AvatarUser/AvatarUser';
import AvatarIcon from '../avatar/AvatarIcon/AvatarIcon';
import CheckBox from '@zohodesk/components/lib/CheckBox/CheckBox';
import { Container } from '@zohodesk/components/lib/Layout';
import ChannelIcon from '../ChannelIcon/ChannelIcon';
import AvatarSize from '@zohodesk/components/lib/Provider/AvatarSize';
import style from './FlipCard.module.css';
import { stopBubbling } from '../utils/General';
 
export default class FlipCard extends Component {
  constructor(props) {
    super(props);
    this.onChange = this.onChange.bind(this);
    this.onClick = this.onClick.bind(this);
  }
 
  onClick(e) {
    let { noNeedFlip } = this.props;
    if (!noNeedFlip) {
      stopBubbling(e);
    }
  }
 
  onChange(isChecked, e) {
    let { onChange } = this.props;
    stopBubbling(e);
    let { id } = this.props;
    onChange(id, isChecked, e);
  }
 
  render() {
    let {
      id,
      action,
      name,
      initial,
      isChecked,
      noNeedFlip,
      size,
      channel,
      isPaidUser,
      isPortalUser,
      src,
      icon,
      iconSize,
      iconClass,
      ticListContainer,
      ticList,
      dataId,
      className,
      palette,
      textPalette,
      customTextClass,
      frontClass,
      needTitle,
      iconColor,
      tourId,
      isFilledCheckbox,
      channelTitle,
      customProps
    } = this.props;
 
 
    const { CheckBoxProps = {}, ChannelIconProps = {}, AvatarIconProps = {}, AvatarUserProps = {} } = customProps;
    return (
      <div
        className={`${AvatarSize(size)}  ${noNeedFlip ? style.flipNone : isChecked ? style.notFlip : style.flip}`}
        onClick={this.onClick}
        data-id={ticListContainer}
        data-test-id={ticListContainer}
        data-tour={tourId}
      >
        <div className={style.container} data-id={ticList} data-test-id={ticList}>
          {!noNeedFlip ? (
            <Container align='both' className={`${style.front} ${frontClass ? frontClass : ''}`}>
              <CheckBox
                isFilled={isFilledCheckbox}
                checked={isChecked}
                onChange={this.onChange}
                id={`checkbox_${id}`}
                dataId={`listViewCheckBox_${id}`}
                {...CheckBoxProps}
              />
            </Container>
          ) : null}
          <Container align='both' className={style.back}>
            {channel && action ? (
              <ChannelIcon
                name={channel}
                action={action}
                size={size}
                iconSize={iconSize}
                iconClass={iconClass}
                dataId={channel}
                className={className}
                palette={palette}
                textPalette={textPalette}
                customTextClass={customTextClass}
                iconColor={iconColor}
                title={channelTitle}
                iconTitle={channelTitle}
                {...ChannelIconProps}
              />
            ) : icon ? (
              <AvatarIcon
                name={icon}
                iconSize={iconSize}
                size={size}
                iconClass={iconClass}
                dataId={icon}
                className={className}
                iconColor={iconColor}
                title={needTitle ? name : ''}
                {...AvatarIconProps}
              />
            ) : (
              <AvatarUser
                name={name}
                initial={initial}
                size={size}
                isPaid={isPaidUser}
                isPortal={isPortalUser}
                src={src}
                dataId={dataId}
                needTitle={needTitle}
                palette={palette}
                textPalette={textPalette}
                customTextClass={customTextClass}
                {...AvatarUserProps}
              />
            )}
          </Container>
        </div>
      </div>
    );
  }
}
 
FlipCard.propTypes = propTypes;
FlipCard.defaultProps = defaultProps;
// if (__DOCS__) {
//   FlipCard.docs = {
//     componentGroup: 'Molecule'
//   };
// }