# All files / layouts/Form ToggleField.js

50% Statements 1/2
100% Branches 0/0
0% Functions 0/1
50% Lines 1/2

    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

    5x

     import React from 'react';
    import PropTypes from 'prop-types';
    import Toggle from '../../components/Toggle/Toggle';
    import BinaryField from './BinaryField';

    /**
     * DEPRECATED
     *
     * @class ToggleField
     * @extends {React.Component}
     */
    class ToggleField extends React.Component {
      static propTypes = {
        /**
         * A collection of input props. Passed to the input.
         */
        input: PropTypes.shape({
          value: PropTypes.oneOfType([PropTypes.string, PropTypes.bool]),
          onChange: PropTypes.func,
          disabled: PropTypes.bool,
        }),
        /**
         * Contents of a label on the field.
         */
        label: PropTypes.string,
        /**
         * Adds an id to the input.
         */
        id: PropTypes.string,
        /**
         * Adds a class name to the input.
         */
        className: PropTypes.string,
      };

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

      render() {
        return (
          <BinaryField {...this.props} Input={Toggle} />
        );
      }
    }

    ToggleField.usage = `
    # ToggleField

    A toggle-based field. See BinaryField for prop types.

    \`\`\`
    <ToggleField input={{ value: 'true', onChange=this.onChange }} label="Yes?" disabled />
    \`\`\`
    `;

    export default ToggleField;