# All files / layouts/Form BinaryField.js

20% Statements 1/5
100% Branches 0/0
0% Functions 0/3
20% Lines 1/5

    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

    5x

     import React from 'react';
    import PropTypes from 'prop-types';
    import warning from 'warning';

    /**
     * DEPRECATED
     *
     * @class BinaryField
     * @extends {React.Component}
     */
    class BinaryField extends React.Component {
      static propTypes = {
        /**
         * A collection of input-related properties. All passed to the input.
         */
        input: PropTypes.shape({
          value: PropTypes.oneOfType([PropTypes.string, PropTypes.bool]),
          onChange: PropTypes.func,
          disabled: PropTypes.bool,
        }),
        /**
         * Content of the label above the input.
         */
        label: PropTypes.string,
        /**
         * Adds an id to the input element.
         */
        id: PropTypes.string,
        /**
         * Adds a class name to the input element.
         */
        className: PropTypes.string,
        /**
         * The component to render the input with.
         */
        Input: PropTypes.func.isRequired,
      };

      static defaultProps = {
        input: {
          value: 'false',
        },
        label: null,
        id: null,
        className: null,
      };

      componentDidMount() {
        warning(true, 'DEPRECATED: the Field system is now deprecated. Please use Flow instead. (from BinaryField)');
      }

      handleClick = () => {
        this.props.input.onChange(!this.props.input.value);
      };

      render() {
        const { label, id, input: { value, disabled }, Input, className } = this.props;

        return (
          <Input
            id={id}
            className={className}
            type="checkbox"
            value={value}
            disabled={disabled}
            onClick={this.handleClick}
            description={label}
          />
        );
      }
    }

    BinaryField.usage = `
    # BinaryField

    This is really more of a base class for inputs which switch between two values (see: Toggle and Checkbox).

    Props:

    * \`input\`: supplied by Redux Form's Field component, you can also specify this manually. Should contain \`value\` and \`onChange\` at least.
    * \`label\`: a renderable label to go above the component
    * \`helpText\`: some text to be rendered below the component
    * \`disabled\`: disables the component
    * \`required\`: adds a required mark and HTML field validation
    `;

    export default BinaryField;