# All files / components/Button Button.js

80% Statements 8/10
100% Branches 0/0
0% Functions 0/2
80% Lines 8/10

    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
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161

    4x

    4x

    4x

    4x

    4x

    4x

    4x

    4x

     import React from 'react';
    import PropTypes from 'prop-types';
    import styled from 'styled-components';
    import icons from '../Icon/icons';
    import SubmitButton from './SubmitButton';
    import get from 'extensions/themeGet';

    const Button = styled.button`
      font-size: 0.8em;
      text-decoration: none;
      font-weight: 700;
      font-family: ${get('fonts.brand')};
      text-transform: uppercase;

      border-width: ${get('thicknesses.normal')};
      border-style: solid;
      border-radius: 3em;
      border-color: ${get('colors.primary.default')};

      color: ${get('colors.text.inverted')};
      background: ${get('colors.primary.default')};

      /* 2px less than design system values since we always render a 1px border */
      padding: 11px 38px;
      display: inline-block;
      position: relative;
      overflow: hidden;
      line-height: normal;
      white-space: nowrap;

      vertical-align: middle;
      text-align: center;

      cursor: pointer;
      -webkit-user-drag: none;
      /* should get auto-prefixed */
      user-select: none;

      box-sizing: border-box;

      transition: all 0.25s ease;

      outline: none;

      &:hover:not(:disabled),
      &:focus:not(:disabled) {
        background: ${get('colors.primary.dark')};
        border-color: ${get('colors.primary.dark')};
        box-shadow: ${get('shadows.short')};
      }

      &:disabled {
        background: ${get('colors.background.disabled')};
        color: ${get('colors.text.disabled')};
        border-color: ${get('colors.background.disabled')};
        cursor: default;
        opacity: 0.5;
      }

      &::before, &::after {
        position: absolute;
        height: 100%;
        color: inherit;
        transition: all 0.3s;
        speak: none;
        font-family: ${get('fonts.icon')};
      }

      &::before {
        content: '${({ leftIcon, iconHelper }) => iconHelper(leftIcon)}';
        left: -200px;
      }

      &::after {
        content: '${({ rightIcon, iconHelper }) => iconHelper(rightIcon)}';
        right: -200px;
      }

      &:hover:not(:disabled)::before {
        left: 10px;
      }

      &:hover:not(:disabled)::after {
        right: 10px;
      }
    `;

    Button.propTypes = {
      /**
       * An icon name for an icon to pop in from the left side of the button on hover.
       */
      leftIcon: PropTypes.string,
      /**
       * An icon name for an icon to pop in from the right side of the button on hover.
       */
      rightIcon: PropTypes.string,
      /**
       * Use this to override the icon provider function (advanced). An icon provider function takes an icon name and
       * provides a unicode character to render.
       */
      iconHelper: PropTypes.func,
      /**
       * A class name to add to the button element.
       */
      className: PropTypes.string,
      /**
       * An id to add to the button element.
       */
      id: PropTypes.string,
    };

    Button.defaultProps = {
      leftIcon: null,
      rightIcon: null,
      iconHelper: icons,
      className: null,
      id: null,
    };

    Button.Submit = SubmitButton;

    Button.Secondary = Button.extend`
      color: ${get('colors.primary.dark')};
      border-color: ${get('colors.primary.dark')};
      background: transparent;

      &:hover:not(:disabled),
      &:focus:not(:disabled) {
        color: ${get('colors.text.inverted')};
        background: ${get('colors.primary.dark')};
        border-color: ${get('colors.primary.dark')};
      }
    `;

    Button.Small = Button.extend`
      padding: 9px 28px;
      font-size: 0.6em;
    `;

    Button.Large = Button.extend`
      padding: 13px 58px;
      font-size: 0.9em;
    `;

    Button.Danger = Button.extend`
      border-color: ${get('colors.negative.default')};
      background: ${get('colors.negative.default')};

      &:hover:not(:disabled),
      &:focus:not(:disabled) {
        background: ${get('colors.negative.dark')};
        border-color: ${get('colors.negative.dark')};
      }
    `;

    /**
     * @component
     */
    export default Button;