All files / src/ProgressBar styles.ts

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

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      10x                           10x                       10x                                                       10x    
import { css, cssClass } from '../styled';
import { borderRadius, tint, palette, theme } from '../utils';
 
export const ProgressBar = styleProps => cssClass`
  border-radius: ${borderRadius('default')(styleProps)};
  overflow: hidden;
  width: 100%;
  height: 1rem;
  background-color: ${tint(0.9, palette(styleProps.color, styleProps.color)(styleProps))};
 
  ${getSizeAttributes(styleProps)};
 
  & {
    ${theme(styleProps.themeKey, `css.root`)(styleProps)};
  }
`;
 
export const ProgressBarIndicator = styleProps => cssClass`
  height: 100%;
  background-color: ${palette(styleProps.color, styleProps.color)(styleProps)};
  transition: width 300ms cubic-bezier(0.4, 0, 0.2, 1) 0ms;
  width: ${styleProps.value || '0'}%;
 
  & {
    ${theme(styleProps.themeKey, `css.root`)(styleProps)};
  }
`;
 
function getSizeAttributes(styleProps) {
  const sizeAttributes = {
    small: css`
      height: 0.6rem;
 
      & {
        ${theme(styleProps.themeKey, `css.sizes.small`)(styleProps)};
      }
    `,
    default: css`
      & {
        ${theme(styleProps.themeKey, `css.sizes.default`)(styleProps)};
      }
    `,
    medium: css`
      height: 1.5rem;
 
      & {
        ${theme(styleProps.themeKey, `css.sizes.medium`)(styleProps)};
      }
    `,
    large: css`
      height: 2rem;
 
      & {
        ${theme(styleProps.themeKey, `css.sizes.large`)(styleProps)};
      }
    `
  };
  return sizeAttributes[styleProps.size || 'default'];
}