# All files / layouts/Form RadioField.js

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

    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

    5x

    5x

     import React from 'react';
    import PropTypes from 'prop-types';
    import styled from 'styled-components';
    import RadioGroup from '../../components/RadioGroup';
    import FieldWrapper from './FieldWrapper';

    const Container = styled.div`
      display: flex;
      flex-direction: row;
    `;

    /**
     * DEPRECATED
     *
     * @class RadioField
     * @extends {React.Component}
     */
    class RadioField extends React.Component {
      static propTypes = {
        /**
         * A list of strings or rendered nodes to render as the choices.
         */
        choices: PropTypes.oneOfType([
          PropTypes.arrayOf(PropTypes.string),
          PropTypes.objectOf(PropTypes.node),
        ]).isRequired,
        /**
         * Contents of the label above the field.
         */
        label: PropTypes.string,
        /**
         * A collection of input properties. Passed to the input.
         */
        input: PropTypes.shape({
          name: PropTypes.string.isRequired,
          value: PropTypes.string.isRequired,
          onChange: PropTypes.func.isRequired,
        }).isRequired,
        /**
         * Indicates whether the user can interact with this field.
         */
        disabled: PropTypes.bool,
        /**
         * Contents of the help text below the field.
         */
        helpText: PropTypes.string,
        /**
         * Indicates whether this field is required for form submission.
         */
        required: PropTypes.bool,
        /**
         * Adds an id to the radio group element.
         */
        id: PropTypes.string,
        /**
         * Adds a class name to the radio group element.
         */
        className: PropTypes.string,
      };

      static defaultProps = {
        groupLabel: null,
        label: null,
        disabled: false,
        helpText: null,
        required: false,
        id: null,
        className: null,
      };

      render() {
        const { label, disabled, required, helpText, input, choices, id, className } = this.props;
        return (
          <FieldWrapper
            label={label}
            disabled={disabled}
            required={required}
            helpText={helpText}
          >
            <RadioGroup {...input} choices={choices} id={id} className={className} />
          </FieldWrapper>
        );
      }
    }

    RadioField.usage = `
    # RadioField

    RadioField is a fully functional input. It generates its own radio buttons from the options you supply. You can use it manually by passing in a valid \`input\` prop which contains a \`value\` and \`onChange\` handler. It's a controlled component, so it won\'t update its own value.

    \`\`\`
    <RadioField value="a" onChange={handleChange} choices={['a', 'b']} />
    \`\`\`
    `;

    export default RadioField;