All files / rating styled-components.js

62.5% Statements 10/16
33.33% Branches 3/9
66.67% Functions 2/3
62.5% Lines 10/16

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                                        2x 1x                               2x     5x 5x   5x 2x     5x                                                 5x       2x                                                                                        
/*
Copyright (c) 2018-2019 Uber Technologies, Inc.
 
This source code is licensed under the MIT license found in the
LICENSE file in the root directory of this source tree.
*/
 
// @flow
 
import {styled} from '../styles/index.js';
import type {StyledRootPropsT, StyledRatingItemPropsT} from './types.js';
import {
  starSVG,
  angryRatingSVG,
  sadRatingSVG,
  neutralRatingSVG,
  happyRatingSVG,
  veryHappyRatingSVG,
} from './svg-icons.js';
 
export const StyledRoot = styled<StyledRootPropsT>('ul', ({$theme}) => {
  return {
    marginLeft: 0,
    marginRight: 0,
    marginTop: 0,
    marginBottom: 0,
    paddingLeft: 0,
    paddingRight: 0,
    paddingTop: 0,
    paddingBottom: 0,
    display: 'inline-block',
    ':focus': {
      outline: 'none',
    },
  };
});
 
export const StyledStar = styled<StyledRatingItemPropsT>(
  'li',
  ({$theme, $isActive, $isSelected}) => {
    let starStroke = $theme.colors.mono500;
    let starFill = $theme.colors.mono300;
 
    if ($isActive) {
      starStroke = starFill = $theme.colors.rating400;
    }
 
    const styles = {
      paddingLeft: 0,
      paddingTop: 0,
      paddingBottom: 0,
      paddingRight: 0,
      display: 'inline-block',
      transition: `all ${$theme.animation.timing400}`,
      cursor: 'pointer',
      marginLeft: 0,
      marginTop: 0,
      marginBottom: 0,
      marginRight: $theme.sizing.scale300,
      width: '22px',
      height: '20px',
      transform: $isSelected ? 'scale(1.35)' : '',
      ':focus': {
        outline: 'none',
      },
      ':after': {
        transition: `all ${$theme.animation.timing400}`,
        content:
          `url('data:image/svg+xml,` + starSVG(starFill, starStroke) + `')`,
      },
    };
 
    return styles;
  },
);
 
export const StyledEmoticon = styled<StyledRatingItemPropsT>(
  'li',
  ({$theme, $isActive, $isSelected, $index = 1}) => {
    let emoticonFill = $theme.colors.mono500;
 
    if ($isActive) {
      emoticonFill = $theme.colors.rating400;
    }
 
    const ratingIcons = [
      angryRatingSVG(emoticonFill),
      sadRatingSVG(emoticonFill),
      neutralRatingSVG(emoticonFill),
      happyRatingSVG(emoticonFill),
      veryHappyRatingSVG(emoticonFill),
    ];
 
    const styles = {
      paddingLeft: 0,
      paddingTop: 0,
      paddingRight: 0,
      paddingBottom: 0,
      display: 'inline-block',
      transition: `all ${$theme.animation.timing400}`,
      cursor: 'pointer',
      marginLeft: 0,
      marginTop: 0,
      marginBottom: 0,
      marginRight: $theme.sizing.scale300,
      width: '44px',
      height: '44px',
      transform: $isSelected ? 'scale(1.1)' : '',
      ':focus': {
        outline: 'none',
      },
      ':after': {
        transition: `all ${$theme.animation.timing400}`,
        content: `url('data:image/svg+xml,` + ratingIcons[$index - 1] + `')`,
      },
    };
 
    return styles;
  },
);