# All files / layouts/Form ButtonField.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
    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

    5x

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

    /**
     * DEPRECATED
     *
     * @class ButtonField
     * @extends {React.Component}
     */
    class ButtonField extends React.Component {
      static propTypes = {
        /**
         * Contents of the button.
         */
        children: PropTypes.node.isRequired,
        /**
         * Handler for a click event on the button.
         */
        onClick: PropTypes.func,
        /**
         * Indicates whether the user can interact with this field.
         */
        disabled: PropTypes.bool,
        /**
         * Content of the label above the button.
         */
        label: PropTypes.string,
        /**
         * Adds an id to the button element.
         */
        id: PropTypes.string,
        /**
         * Adds a class name to the button element.
         */
        className: PropTypes.string,
        /**
         * Sets the type of the button.
         */
        type: PropTypes.string,
        /**
         * Contents of the help text below the button.
         */
        helpText: PropTypes.string,
        /**
         * Glyph name for the icon that pops in from the left of the button on hover.
         */
        leftIcon: PropTypes.string,
        /**
         * Glyph name for the icon that pops in from the right of the button on hover.
         */
        rightIcon: PropTypes.string,
      };

      static defaultProps = {
        disabled: false,
        label: null,
        id: null,
        className: null,
        type: 'text',
        helpText: null,
        onClick: () => null,
        leftIcon: null,
        rightIcon: null,
      };

      render() {
        const {
          children,
          onClick,
          label,
          id,
          disabled,
          helpText,
          type,
          leftIcon,
          rightIcon,
          callout,
          className
        } = this.props;
        return (
          <FieldWrapper label={label} helpText={helpText} callout={callout}>
            <Button
              onClick={onClick}
              id={id}
              className={className}
              type={type}
              disabled={disabled}
              leftIcon={leftIcon}
              rightIcon={rightIcon}
            >
              {children}
            </Button>
          </FieldWrapper>
        );
      }
    }

    ButtonField.usage = `
    # ButtonField

    Kind of like a Button, but with a label above and help text below. Add them with \`label\` and \`helpText\` properties. This makes it more at home in a form. It's highly recommended to use ButtonField in a form, even if you don't use label or help text, since it lays out better.
    `;

    export default ButtonField;