# All files / layouts/Form ActionFields.js

30.77% Statements 4/13
0% Branches 0/4
0% Functions 0/5
30.77% Lines 4/13

    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

    5x

    5x

    5x

    5x

     import PropTypes from 'prop-types';
    import styled, { css } from 'styled-components';
    import { Container as FieldWrapperContainer } from './FieldWrapper';

    /**
     * DEPRECATED
     */
    const ActionFields = styled.div`
      display: flex;
      flex-direction: row;
      ${({ align }) => {
        switch(align) {
          case 'right':
            return 'justify-content: flex-end;';
          case 'left':
            return 'justify-content: flex-end; flex-direction: row-reverse;';
          case 'center':
            return 'justify-content: center;';
          case 'outside':
            return 'justify-content: space-between;';
        }
      }};
      margin-top: ${({ theme }) => theme.form.elementVerticalSpacing / 2}px;
      margin-bottom: ${({ theme }) => theme.form.elementVerticalSpacing / 2}px;
      flex: 1 0 100%;

      & > ${FieldWrapperContainer} {
        margin: auto ${({ theme }) => theme.form.elementHorizontalSpacing / 2}px;
      }
      & > ${FieldWrapperContainer}:last-child {
        margin-${({ align }) => align}: 0;
      }
    `;

    ActionFields.propTypes = {
      /**
       * Indicates how the fields should align.
       */
      align: PropTypes.oneOf(['right', 'left', 'center', 'outside']),
      /**
       * Adds a class name to the element.
       */
      className: PropTypes.string,
      /**
       * Adds an id to the element.
       */
      id: PropTypes.string,
    }

    ActionFields.defaultProps = {
      align: 'right',
      className: null,
      id: null,
    };

    ActionFields.usage = `
    # ActionFields

    ActionFields is a layout container for that last row of buttons and links in a form. You know the one. They're all aligned in a particular way. You could achieve this with some fiddling and a FieldGroup, but why not just include a more convenient component for it?

    You can pass \`left|right|center|outside\` to the \`'align'\` prop to switch the alignment.

    Alignment \`'left'\` will reverse the order of elements, so you can switch easily between left and right.

    \`\`\`
    <Form>
      <Field component={TextField} label="name" />
      <ActionFields>
        <LinkField>Cancel</LinkField>
        <ButtonField type="submit">Save</ButtonField>
      </ActionFields>
    </Form>
    \`\`\`
    `;

    export default ActionFields;