All files / src/Badge styles.ts

100% Statements 4/4
100% Branches 6/6
100% Functions 2/2
100% Lines 3/3

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      26x                                                                               26x                                     26x    
import { css, cssClass } from '../styled';
import { fontSize, fontWeight, palette, theme } from '../utils';
 
export const Badge = styleProps => cssClass`
  align-items: center;
  border-radius: 1rem;
  display: inline-flex;
  justify-content: center;
  background-color: ${palette(styleProps.palette)(styleProps)};
  box-sizing: content-box;
  padding: 0 0.4em;
  color: ${palette(`${styleProps.palette}Inverted`)(styleProps)};
  fill: ${palette(`${styleProps.palette}Inverted`)(styleProps)};
  font-size: ${fontSize('100')(styleProps)}rem;
  font-weight: ${fontWeight('semibold')(styleProps)};
  height: 1.2em;
 
  ${!styleProps.children &&
    css`
      height: 1em;
      width: 1em;
      padding: 0px;
    `}
 
  ${styleProps.isAttached &&
    css`
      position: absolute;
      top: -0.5em;
      right: -0.5em;
 
      & {
        ${theme(styleProps.themeKey, `css.attached`)(styleProps)};
      }
    `}
 
  ${getSizeAttributes(styleProps)}
 
  & {
    ${theme(styleProps.themeKey, `css.root`)(styleProps)};
  }
`;
 
function getSizeAttributes(styleProps) {
  const sizeAttributes = {
    default: css`
      & {
        ${theme(styleProps.themeKey, `css.sizes.default`)(styleProps)};
      }
    `,
    medium: css`
      & {
        font-size: ${fontSize('200')(styleProps)}rem;
        ${theme(styleProps.themeKey, `css.sizes.medium`)(styleProps)};
      }
    `,
    large: css`
      & {
        font-size: ${fontSize('300')(styleProps)}rem;
        ${theme(styleProps.themeKey, `css.sizes.large`)(styleProps)};
      }
    `
  };
  return sizeAttributes[styleProps.size || 'default'];
}