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

100% Statements 28/28
88.46% Branches 23/26
100% Functions 13/13
100% Lines 28/28

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
    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
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
    178
    179
    180
    181
    182
    183
    184
    185
    186
    187
    188
    189
    190
    191
    192
    193
    194
    195
    1963x
    3x
    3x

    3x
    3x

    3x

    3x

    27x

    3x

    27x

    3x
    27x

    3x
    27x

    3x

    3x

    9x

    3x

    9x

    9x

    9x

    9x

    9x

    9x

    9x

    3x

    3x

    3x

     import styled, { css } from 'styled-components'
    import { Typography } from '../Typography/Typography'
    import { colors } from '../_styles/colors'

    const TRACK_HEIGHT = 4
    const THUMB_HEIGHT = 14

    function applyStylesOnlyToFF(styles: string) {
      return css`
        @supports (-moz-appearance: none) {
          ${styles}
        }
      `
    }

    const getThumbStyles = css<{ isDragging: boolean }>`
      box-shadow: 0px 1px 4px rgba(40, 40, 40, 0.2), 0px 0px 3px rgba(0, 0, 0, 0.14),
        0px 2px 3px rgba(0, 0, 0, 0.12);
      height: ${THUMB_HEIGHT}px;
      width: ${THUMB_HEIGHT}px;
      border-radius: 15px;
      background: ${colors.white};
      border: 2px solid ${colors.blue50};
      z-index: 3;
      ${(props) => (props.isDragging ? `cursor: grabbing` : `cursor: pointer`)};
    `

    const getTrackStyles = css<{ isDragging: boolean }>`
      width: 100%;
      height: ${TRACK_HEIGHT}px;
      animate: 0.2s;
      border-radius: 1px;
      border: 0px solid ${colors.black};
      z-index: 1;
      ${(props) => (props.isDragging ? `cursor: grabbing` : `cursor: pointer`)};
    `

    const getTrackBackground = (percent: number): string =>
      `background: linear-gradient(to right, ${colors.blue50} 0%, ${colors.blue50} ${percent}%, ${colors.gray70} ${percent}%, ${colors.gray70} 100%);`

    const getTrackBackgroundDisabled = (percent: number): string =>
      `background: linear-gradient(to right, ${colors.blue85} 0%, ${colors.blue85} ${percent}%, ${colors.gray90} ${percent}%, ${colors.gray90} 100%);`

    const getThumbDisabledStyles = css`
      cursor: not-allowed;
      border: 2px solid ${colors.blue85};
    `

    export const StyledContainer = styled.div<{ showLabel?: boolean }>`
      position: relative;
      ${(props) => props.showLabel && 'padding-bottom: 10px'};
    `

    export const StyledSlider = styled.input<{
      $percent: number
      ref: any
      isDragging: boolean
    }>`
      -webkit-appearance: none;
      margin: 0;
      padding-top: 5px;
      padding-bottom: 5px;
      width: 100%;
      border: 1px solid transparent;
      background-color: transparent;
      font-size: 12px;

      &:focus {
        outline: none;
        ${(props) =>
          props.isDragging
            ? `border: 1px solid transparent`
            : `border: 1px solid ${colors.blue40}`};
        padding-top: 5px;
        padding-bottom: 5px;
        border-radius: 2px;
      }

      &::-webkit-slider-runnable-track {
        ${getTrackStyles}
        ${(props) => getTrackBackground(props.$percent)}
      }
      &:disabled::-webkit-slider-runnable-track {
        cursor: not-allowed;
        ${(props) => getTrackBackgroundDisabled(props.$percent)}
      }

      &::-webkit-slider-thumb {
        ${getThumbStyles}
        -webkit-appearance: none;
        margin-top: -5px;
      }
      &:disabled::-webkit-slider-thumb {
        ${getThumbDisabledStyles}
      }

      &::-moz-range-track {
        ${getTrackStyles}
        ${(props) => getTrackBackground(props.$percent)}
      }
      &:disabled::-moz-range-track {
        cursor: not-allowed;
        ${(props) => getTrackBackgroundDisabled(props.$percent)}
      }

      &::-moz-range-thumb {
        ${getThumbStyles}
        height: 12px;
        width: 12px;
      }
      &:disabled::-moz-range-thumb {
        ${getThumbDisabledStyles}
      }

      &::-ms-track {
        ${getTrackStyles}
        height: ${THUMB_HEIGHT + 2}px;
        color: transparent;
        ${(props) => getTrackBackground(props.$percent)}
      }
      &:disabled::-ms-track {
        cursor: not-allowed;
        ${(props) => getTrackBackgroundDisabled(props.$percent)}
      }

      &::-ms-fill-lower {
        background: ${colors.blue50};
        border: 0px solid ${colors.black};
        border-radius: 2px;
        box-shadow: 1px 1px 1px ${colors.black};
      }

      &::-ms-fill-upper {
        background: ${colors.gray70};
        border: 0px solid ${colors.black};
        border-radius: 2px;
        box-shadow: 1px 1px 1px ${colors.black};
      }

      &::-ms-thumb {
        ${getThumbStyles}
      }
      &:disabled::-ms-thumb {
        ${getThumbDisabledStyles}
      }

      &:focus::-ms-fill-lower {
        background: ${colors.blue50};
      }

      &:focus::-ms-fill-upper {
        background: ${colors.gray70};
      }
    `

    export const StyledIncrementOverlay = styled.div`
      position: relative;
      width: 0;
      &::before {
        content: '';
        height: ${TRACK_HEIGHT}px;
        width: 2px;
        background-color: white;
        display: block;
      }
      z-index: 2;
    `

    export const StyledIncrementContainer = styled.div`
      position: absolute;
      display: flex;
      justify-content: space-between;
      top: 6px;
      ${applyStylesOnlyToFF(`
        top: 12px;
      `)}
      left: 5px;
      right: 5px;

      > :first-child {
        visibility: hidden;
      }

      > :last-child {
        visibility: hidden;
      }
    `

    export const StyledLabel = styled(Typography)`
      visibility: visible;
      position: absolute;
      left: 50%;
      transform: translateX(-50%);
      margin-top: 8px;
    `