# All files / checkbox CheckBoxIcon.js

75% Statements 6/8
55.56% Branches 10/18
100% Functions 1/1
75% Lines 6/8

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

    2x

    1x

    1x

    1x

    1x

    2x

     import React from 'react';
    import PropTypes from 'prop-types';
    import FAIcon from 'react-native-vector-icons/FontAwesome';

    import getIconType from '../helpers/getIconType';

    const CheckBoxIcon = ({
      checked,
      onIconPress,
      onLongIconPress,
      size,
      checkedIcon,
      uncheckedIcon,
      iconType,
      checkedColor,
      uncheckedColor,
    }) => {
      Iif (checked && React.isValidElement(checkedIcon)) {
        return checkedIcon;
      }

      Iif (!checked && React.isValidElement(uncheckedIcon)) {
        return uncheckedIcon;
      }

      const VectorIcon = iconType ? getIconType(iconType) : FAIcon;

      return (
        <VectorIcon
          color={checked ? checkedColor : uncheckedColor}
          name={checked ? checkedIcon : uncheckedIcon}
          size={size || 24}
          style={{ minWidth: size || 24 }}
          onLongPress={onLongIconPress}
          onPress={onIconPress}
        />
      );
    };

    CheckBoxIcon.propTypes = {
      checked: PropTypes.bool,
      onIconPress: PropTypes.func,
      onLongIconPress: PropTypes.func,
      size: PropTypes.number,
      checkedIcon: PropTypes.oneOfType([PropTypes.string, PropTypes.element]),
      uncheckedIcon: PropTypes.oneOfType([PropTypes.string, PropTypes.element]),
      iconType: PropTypes.string,
      checkedColor: PropTypes.string,
      uncheckedColor: PropTypes.string,
    };

    export default CheckBoxIcon;