# All files / layouts/Form FileField.js

25% Statements 1/4
100% Branches 0/0
0% Functions 0/2
25% Lines 1/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

    5x

     import React from 'react';
    import PropTypes from 'prop-types';
    import FieldWrapper from './FieldWrapper';
    import FileInput from '../../components/FileLoader';
    import warning from 'warning';

    class FileField extends React.Component {
      static propTypes = {
        /**
         * A collection of input properties. Passed to input.
         */
        input: PropTypes.shape({
          value: PropTypes.instanceOf(FileList),
        }).isRequired,
        /**
         * Content of the label above the field.
         */
        label: PropTypes.string,
        /**
         * Content of the help text below the field.
         */
        helpText: PropTypes.string,
        /**
         * Indicates that this field is required for form submission.
         */
        required: PropTypes.bool,
        /**
         * Indicates whether the user can change this field.
         */
        disabled: PropTypes.bool,
        /**
         * Adds a callout when the user hovers the field.
         */
        callout: PropTypes.node,
        /**
         * Adds an id to the input element.
         */
        id: PropTypes.string,
        /**
         * Adds a class name to the input element.
         */
        className: PropTypes.string,
      };

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

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

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

    FileField.usage = `
    # FileField

    A file input component (meant to be used with Redux Form) which accepts drag-and-drop.
    `;

    export default FileField;