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

100% Statements 26/26
100% Branches 31/31
100% Functions 3/3
100% Lines 23/23

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
    1459x
    9x
    9x

    9x

    9x

    9x

    9x

    9x

    9x

    9x

    9x

    9x

    65x
    65x

    9x

    233x

    233x
    233x
    69x

    164x
    67x

    97x
    9x

     import styled, { css } from 'styled-components'
    import { colors } from '../_styles/colors'
    import { getGapOutlineFocus } from '../_styles/mixins'
    import { BaseAvatarProps } from './Avatar.types'

    interface StyledAvatarProps {
      $clickable: BaseAvatarProps['clickable']
      $disabled: BaseAvatarProps['disabled']
      $size: BaseAvatarProps['size']
    }

    const activeOverlayOpacity = 0.3

    const containerSize = { xl: 96, lg: 40, md: 32 } as const

    const fontSize = { xl: 40, lg: 14, md: 14 } as const

    const fontWeights = { xl: 700, lg: 600, md: 600 } as const

    const iconSize = { xl: 48, lg: 24, md: 16 } as const

    export const StyledAvatarOverlay = styled.div`
      width: 100%;
      height: 100%;
      position: absolute;
      top: 0;
      left: 0;
      border-radius: 100%;
      opacity: 0;
    `

    export const StyledIconContainer = styled.div`
      display: inline-flex;
    `

    export const StyledLabelContainer = styled.div`
      text-transform: uppercase;
    `

    export const StyledPortraitContainer = styled.div<{ $imageUrl: string }>`
      background-color: ${colors.white};
      background-position: center;
      background-repeat: no-repeat;
      background-size: cover;
      height: 100%;
      width: 100%;
      ${({ $imageUrl }) =>
        css`
          background-image: url(${$imageUrl});
        `}
    `

    export const StyledAvatarContainer = styled.div<StyledAvatarProps>`
      display: inline-flex;
      justify-content: center;
      align-items: center;
      border-radius: 100%;
      overflow: hidden;
      position: relative;
      cursor: default;
      color: ${colors.white};
      background-color: ${colors.gray30};
      text-decoration: none;

      a:has(> &) {
        text-decoration: none;
      }

      &:focus {
        ${getGapOutlineFocus}
      }
      // For safety, separate rule block with 'has' for supported browsers
      // this supports any anchor directly wrapping an Avatar.
      // 'outline' works better on display inline-block and inline-flex,
      // elements, unfortunately anchors and inline by default.
      a:focus:has(> &) {
        ${getGapOutlineFocus}
        border-radius: 100%;
      }

      ${({ $size = 'md' }) => css`
        font-size: ${fontSize[$size]}px;
        font-weight: ${fontWeights[$size]};
        height: ${containerSize[$size]}px;
        width: ${containerSize[$size]}px;
        min-height: ${containerSize[$size]}px;
        min-width: ${containerSize[$size]}px;

        ${StyledIconContainer} {
          svg {
            height: ${iconSize[$size]}px;
            width: ${iconSize[$size]}px;
          }
        }
      `}

      ${({ $disabled, $clickable }) => {
        if (!$disabled && $clickable) {
          return css`
            cursor: pointer;

            &:hover {
              ${StyledAvatarOverlay} {
                opacity: ${activeOverlayOpacity};
              }
            }

            ${StyledAvatarOverlay} {
              background-color: ${colors.black};
            }
          `
        }

        if ($disabled && !$clickable) {
          return css`
            background-color: ${colors.gray85};

            ${StyledAvatarOverlay} {
              background-color: ${colors.white};
              opacity: ${activeOverlayOpacity};
            }
          `
        }

        if ($disabled && $clickable) {
          return css`
            cursor: pointer;
            background-color: ${colors.gray85};

            &:hover {
              ${StyledAvatarOverlay} {
                background-color: ${colors.black};
                opacity: ${activeOverlayOpacity};
              }
            }

            ${StyledAvatarOverlay} {
              background-color: ${colors.white};
              opacity: ${activeOverlayOpacity};
            }
          `
        }
      }};
    `