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

100% Statements 20/20
87.5% Branches 21/24
100% Functions 3/3
100% Lines 18/18

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
    852x
    2x
    2x
    2x
    2x

    2x
    2x
    2x

    2x

    2x

    2x

    2x

    9x
    9x

    9x
    9x

    9x
    9x

     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'

    const trackHeight = 20
    const trackWidth = 36
    const toggleSize = 16

    export const StyledTrack = styled.div`
      background-color: ${colors.gray70};
      border-radius: ${trackHeight}px;
      height: ${trackHeight}px;
      width: ${trackWidth}px;
      position: relative;
      transition: 0.2s;
    `

    export const StyledToggle = styled.span`
      background-color: ${colors.white};
      border-radius: 50%;
      bottom: 2px;
      height: ${toggleSize}px;
      left: 2px;
      position: absolute;
      transition: all 0.2s;
      width: ${toggleSize}px;
    `

    export const StyledSwitchLabel = styled.span`
      ${getTypographyIntent('body')}
      padding-left: ${spacing.md}px;
      user-select: none;
    `

    export const StyledSwitchContainer = styled.label<{
      $disabled?: boolean
      $checked?: boolean
      $focused: boolean
    }>`
      cursor: pointer;
      display: grid;
      grid-template-columns: ${trackWidth}px 1fr;

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

      ${({ $checked }) => {
        return (
          $checked &&
          css`
            ${StyledTrack} {
              background-color: ${colors.blue50};

              ${StyledToggle} {
                transform: translateX(${spacing.lg}px);
              }
            }
          `
        )
      }}

      ${({ $focused }) => {
        return (
          $focused &&
          css`
            ${getFocus()}
            border-radius: 12px;
          `
        )
      }}

      ${({ $disabled = false, $checked }) =>
        $disabled &&
        css`
          cursor: default;

          ${StyledTrack} {
            background-color: ${$checked ? colors.blue85 : colors.gray85};
          }
        `}
    `