All files / elements/Progress/utils props.js

100% Statements 10/10
100% Branches 8/8
100% Functions 1/1
100% Lines 10/10

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      17x                               1219x 1219x 1x   1218x 1x   1217x                             17x                                                 17x                                                 17x        
import PropTypes from 'prop-types';
import { getAnimationIterationCount } from './styledHelpers';
 
export const getProgressProps = props => {
  const {
    animation,
    animationDelay,
    animationDirection,
    animationDuration,
    animationFillMode,
    animationName,
    animationPlayState,
    animationTimingFunction,
    circumference,
    isDeterminate,
    loop,
    progressType,
    total,
    value,
  } = props;
  if (progressType === 'linear' && value >= 0) {
    return { width: value / total };
  }
  if (progressType === 'circular' && value >= 0) {
    return { strokeDashoffset: `${circumference - ((value / total) * circumference)}px` };
  }
  return {
    animation,
    animationDelay,
    animationDirection,
    animationDuration,
    animationFillMode,
    animationIterationCount: getAnimationIterationCount(props),
    animationName,
    animationPlayState,
    animationTimingFunction,
    isDeterminate,
    loop,
  };
};
 
export const progressBasePropTypes = {
  animation: PropTypes.any,
  animationDelay: PropTypes.any,
  animationDirection: PropTypes.any,
  animationDuration: PropTypes.any,
  animationFillMode: PropTypes.any,
  animationIterationCount: PropTypes.any,
  animationName: PropTypes.any,
  animationPlayState: PropTypes.any,
  animationTimingFunction: PropTypes.any,
  containerProps: PropTypes.object,
  hideTrack: PropTypes.bool,
  indicatorColor: PropTypes.string,
  indicatorProps: PropTypes.object,
  indicatorPropsToTrim: PropTypes.arrayOf(PropTypes.string),
  isDeterminate: PropTypes.bool,
  isHidden: PropTypes.bool,
  loop: PropTypes.bool,
  total: PropTypes.number,
  trackColor: PropTypes.string,
  trackProps: PropTypes.object,
  trackPropsToTrim: PropTypes.arrayOf(PropTypes.string),
  value: PropTypes.number,
};
 
export const progressBaseDefaultProps = {
  animation: '',
  animationDelay: '0s',
  animationDirection: 'normal',
  animationDuration: '1.5s',
  animationFillMode: 'none',
  animationIterationCount: '',
  animationName: '',
  animationPlayState: 'running',
  animationTimingFunction: 'linear',
  containerProps: {},
  hideTrack: false,
  indicatorColor: 'brandPrimary.light',
  indicatorProps: {},
  indicatorPropsToTrim: [],
  isDeterminate: false,
  isHidden: false,
  loop: true,
  total: 100,
  trackColor: 'gray.light',
  trackProps: {},
  trackPropsToTrim: [],
  value: -1,
};
 
export const defaultProgressPropsToTrim = [
  ...Object.keys(progressBaseDefaultProps),
  'strokeColor',
];