# All files / src/RadioButton RadioButton.styles.ts

100% Statements 14/14
78.57% Branches 11/14
100% Functions 2/2
100% Lines 14/14

Press n or j to go to the next uncovered block, b, p or k for the previous block.

    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
    1036x
    6x
    6x
    6x
    6x

    6x

    6x

    6x

    8x
    8x

    8x
    8x

    6x

    6x

     import styled, { css } from 'styled-components'
    import { getTypographyIntent } from '../Typography/Typography.styles'
    import { colors } from '../_styles/colors'
    import { getFocus } from '../_styles/mixins'
    import { spacing } from '../_styles/spacing'

    export const dataQa = {
      focused: 'core-radio-focused',
    }

    const radioButtonSize = 20

    export const StyledRadioButton = styled.label<{
      $children?: React.ReactNode
      $error?: boolean
    }>`
      color: ${colors.gray15};
      display: flex;
      position: relative;
      vertical-align: middle;

      & + & {
        margin-top: ${spacing.md}px;
      }

      ${({ $error }) =>
        $error &&
        css`
          ${StyledRadioButtonLabel}:before,
          ${StyledRadioButtonInput}:checked:not(:disabled) + ${StyledRadioButtonLabel}:before {
            border-color: ${colors.red50};
          }

          ${StyledRadioButtonInput}:checked:disabled + ${StyledRadioButtonLabel}:before {
            border-color: ${colors.gray85};
          }
        `}

      ${({ $children }) =>
        $children &&
        css`
          ${StyledRadioButtonLabel} {
            &:before {
              margin-right: ${spacing.md}px;
            }
          }
        `}
    `

    export const StyledRadioButtonLabel = styled.span`
      ${getTypographyIntent('body')};

      cursor: default;
      display: flex;

      &:before {
        background: ${colors.white};
        border-radius: 100%;
        border: 2px solid ${colors.gray70};
        content: '';
        display: inline-block;
        flex: 0;
        height: ${radioButtonSize}px;
        min-width: ${radioButtonSize}px;
        width: ${radioButtonSize}px;
      }
    `

    export const StyledRadioButtonInput = styled.input`
      left: 0;
      margin: 0;
      opacity: 0;
      padding: 0;
      position: absolute;
      top: 0;

      &:focus:not(:checked),
      &[data-qa=${dataQa.focused}]:not(:checked) {
        &:not(:disabled) + ${StyledRadioButtonLabel}:before {
          ${getFocus()}
        }
      }

      &:focus:checked:not(:disabled),
      &[data-qa=${dataQa.focused}]:checked:not(:disabled) {
        + ${StyledRadioButtonLabel}:before {
          box-shadow: 0 0 0 2px ${colors.blue40};
        }
      }

      &:checked + ${StyledRadioButtonLabel}:before {
        border: 6px solid ${colors.blue50};
      }

      &:disabled + ${StyledRadioButtonLabel}:before {
        border-color: ${colors.gray85};
      }

      &:disabled:checked + ${StyledRadioButtonLabel}:before {
        border-color: ${colors.blue85};
      }
    `