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

100% Statements 31/31
97.14% Branches 34/35
100% Functions 4/4
100% Lines 27/27

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
    196
    197
    198
    199
    200
    201
    202
    203
    204
    2053x
    3x
    3x
    3x

    3x
    3x
    3x

    3x

    3x

    3x

    3x

    3x

    3x

    2040x
    2040x

    2040x
    125x

    1915x

    3x

    3x

    3x

    3x

    3x
    142x

    142x

    142x
    142x

     import styled, { css } from 'styled-components'
    import { Card } from '../Card/Card'
    import { getUnstyledButton } from '../Semantic/Semantic.styles'
    import {
      getTypographyIntent,
      typographyWeights,
    } from '../Typography/Typography.styles'
    import { colors } from '../_styles/colors'
    import { focusable } from '../_styles/mixins'
    import { spacing } from '../_styles/spacing'

    const tabGap = spacing.md

    const hiddenTab = css`
      pointer-events: none;
      position: absolute;
      visibility: hidden;
    `

    const visible = css`
      pointer-events: all;
      position: relative;
      visibility: visible;
    `

    export const StyledLink = styled.span`
      align-items: center;
      border-bottom-style: solid;
      border-bottom-color: transparent;
      border-bottom-width: 2px;
      display: inline-flex;
      height: 26px; // TODO one-off
      justify-content: center;
    `

    export const StyledTab = styled.div`
      align-items: center;
      cursor: pointer;
      display: inline-flex;
      flex: 0 0 auto;
      justify-content: center;
      padding: 0 ${tabGap}px;
      position: relative;
      white-space: nowrap;

      a& {
        text-decoration: none;
      }

      button& {
        background-color: transparent;
        border: none;
        font-family: inherit;
      }

      &:first-child {
        padding-left: 0;
      }

      &:last-child {
        padding-right: 0;
      }

      &:not(:last-child) {
        &:focus {
          outline: none;

          ${StyledLink} {
            box-shadow: inset 0 0 0 1px ${colors.blue40};
          }
        }
      }
    `

    export const StyledTabInner = styled.div<{ active?: boolean; dark?: boolean }>`
      ${getTypographyIntent('body')}

      > a {
        text-decoration: none;
        ${focusable}
      }

      ${({ active, dark }) => {
        const textColors = dark
          ? {
              active: colors.white,
              default: colors.gray70,
              hover: colors.white,
            }
          : {
              active: colors.gray15,
              default: colors.gray45,
              hover: colors.gray15,
            }

        if (active) {
          return css`
            &,
            > a {
              color: ${textColors.active};
              cursor: default;
            }

            ${StyledLink} {
              border-bottom-color: ${colors.blue50};
            }
          `
        }

        return css`
          &,
          > a {
            color: ${textColors.default};
            cursor: pointer;
          }
          &:hover,
          &.hover,
          > a:hover {
            color: ${textColors.hover};
          }
        `
      }}
    `

    export const StyledDropdownTab = styled(StyledTab)`
      cursor: pointer;
      ${getUnstyledButton}
      ${focusable}

      ${hiddenTab}

      margin-left: ${tabGap}px;

      ${StyledLink} {
        margin-right: ${spacing.xs}px;
      }
    `

    export const StyledDropdownTabInner = styled(StyledTabInner)`
      align-items: center;
      cursor: pointer;
      display: inline-flex;
    `

    export const StyledOverlay = styled(Card)`
      max-height: 40vh;

      ${StyledTabInner} {
        color: ${colors.gray45};
      }
      ${StyledTab} {
        // onClick events are attached to the Tab which are put inside of <Menu.Item>
        // components with padding. Negative margin trick allows the cloned tab
        // to cover the full area of the menu item
        margin: -${spacing.sm}px -${spacing.lg}px;
        padding: ${spacing.sm}px ${spacing.lg}px;
      }

      // hacky way to style items that were cloned into the menu
      // can probably clean this up once we convert menu to jss
      // by using the inverse ancestor selector
      [data-selected='true'] {
        ${StyledTabInner},
        ${StyledTabInner} > a {
          color: ${colors.blue50};
          font-weight: ${typographyWeights.semibold};
        }
      }

      ${StyledLink} {
        border: 0;
        height: auto;
      }
    `

    export const StyledTabList = styled.div`
      display: flex;
      width: 100%;
    `

    export const StyledTabs = styled.nav<{ dark?: boolean; index?: number }>`
      background-color: ${({ dark }) => dark && colors.gray15};
      display: flex;
      overflow: hidden;
      width: 100%;

      ${StyledTab} {
        // we want to hide all tabs after overflow index
        &:nth-child(1n + ${({ index }) => index}) {
          // but not the "More" dropdown tab
          &:not(${StyledDropdownTab}) {
            ${hiddenTab}
          }
        }
      }

      ${({ index = -1 }) =>
        index >= 0 &&
        css`
          ${StyledDropdownTab} {
            ${visible}
          }
        `}
    `