# All files / components/Label Label.js

0% Statements 0/21
0% Branches 0/8
0% Functions 0/4
0% Lines 0/12

    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

     import React from 'react';
    import PropTypes from 'prop-types';
    import styled, { css } from 'styled-components';
    import get from 'extensions/themeGet';
    import userTextSpacing from 'extensions/userTextSpacing';

    const Label = styled.label.withConfig({ displayName: 'Label' }).attrs({
      spacing: userTextSpacing,
    })`
      font-size: 1em;
      letter-spacing: 0.02em;
      font-weight: 700;
      font-family: ${get('fonts.brand')};
      color: ${get('colors.text.default')};
      background: transparent;
      line-height: 1.5;
      display: block;
      margin: ${props => props.spacing};
      ${({ disabled }) =>
        disabled &&
        css`
          color: ${get('colors.text.disabled')};
        `};

      ${({ required }) =>
        required
          ? css`
              &::after {
                content: '*';
                color: ${get('colors.negative.default')};
                padding-left: 0.3em;
              }
            `
          : ''};
    `;

    Label.propTypes = {
      /**
       * Styles the label to indicate that the associated field is disabled.
       */
      disabled: PropTypes.bool,
      /**
       * Adds a class name to the element.
       */
      className: PropTypes.string,
      /**
       * Adds an id to the element.
       */
      id: PropTypes.string,
      /**
       * Adds a red star at the end of the label.
       */
      required: PropTypes.bool,
      /**
       * Specify a CSS value or an object { top, right, bottom, left } or { vertical, horizontal } to
       * control the spacing around the heading. Defaults to a large space below the element.
       */
      spacing: PropTypes.oneOfType([PropTypes.string, PropTypes.object]),
    };

    Label.defaultProps = {
      disabled: false,
      className: null,
      id: null,
      required: false,
    };

    /**
     * @component
     */
    export default Label;