# All files / layouts/Form TextField.js

33.33% Statements 1/3
100% Branches 0/0
0% Functions 0/1
33.33% Lines 1/3

    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

    5x

     import React from 'react';
    import PropTypes from 'prop-types';
    import TextInput from '../../components/Input';
    import FieldWrapper from './FieldWrapper';

    /**
     * DEPRECATED
     *
     * @class TextField
     * @extends {React.Component}
     */
    class TextField extends React.Component {
      static propTypes = {
        /**
         * A collection of input props. Passed to input.
         */
        input: PropTypes.shape({
          value: PropTypes.oneOfType([PropTypes.string, PropTypes.number]),
          onChange: PropTypes.func,
        }).isRequired,

        meta: PropTypes.shape({
          error: PropTypes.string,
          invalid: PropTypes.bool,
          pristine: PropTypes.bool,
          warning: PropTypes.string,
        }),
        /**
         * Indicates whether the user can change this field.
         */
        disabled: PropTypes.bool,
        /**
         * Indicates whether this field is required for form submission.
         */
        required: PropTypes.bool,
        /**
         * Contents of a label above the field.
         */
        label: PropTypes.string,
        /**
         * Adds an id to the input.
         */
        id: PropTypes.string,
        /**
         * Adds a class name to the input.
         */
        className: PropTypes.string,
        /**
         * Indicates the type of text this field accepts.
         */
        type: PropTypes.string,
        /**
         * Contents of help text below the field.
         */
        helpText: PropTypes.string,
        /**
         * Optional callout contents when a user hovers the field.
         */
        callout: PropTypes.node,
        /**
         * Placeholder text to render inside the input.
         */
        placeholder: PropTypes.string,
      };

      static defaultProps = {
        disabled: false,
        required: false,
        label: null,
        id: null,
        className: null,
        type: 'text',
        helpText: null,
        callout: null,
        placeholder: null,
        meta: {
          error: null,
          invalid: false,
          pristine: false,
          warning: null,
        },
      };

      render() {
        const { input, label, id, className, disabled, required, helpText, type, callout, placeholder, meta } = this.props;
        return (
          <FieldWrapper
            label={label}
            helpText={helpText}
            error={meta.error}
            disabled={disabled}
            required={required}
            callout={callout}
          >
            <TextInput
              {...input}
              {...meta}
              id={id}
              className={className}
              type={type}
              disabled={disabled}
              required={required}
              placeholder={placeholder}
            />
          </FieldWrapper>
        );
      }
    }

    TextField.usage = `
    # TextField

    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
    * \`callout\`: optional flyout to show on hover
    `;

    export default TextField;