All files / UI_Component ProgressCircle.js

100% Statements 17/17
100% Branches 4/4
100% Functions 7/7
100% Lines 17/17
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            1x           1x           1x                                     1x           1x                             1x                     2x     2x 1x   1x     2x       2x 2x           2x                           2x                     1x                 1x                  
import React, { Component } from 'react';
import PropTypes from 'prop-types';
import { is, Map, fromJS } from 'immutable';
import { IMAGE_SIZE, FONT_SIZE } from './common/CommonDefine';
 
 
export const PROGRESS_CIRCLE_THEME = {
    BLACK: 'BLACK',
    WHITE: 'WHITE',
    HIGHCONTRAST: 'HIGHCONTRAST',
};
 
export const PROGRESS_CIRCLE_SIZE = {
    LARGE: 'L',
    MEDIUM: 'M',
    SMALL: 'S',
};
 
const ResourceMap = {
    BLACK: {
        L: 'images/progresscircle/circle_progress_black_l/',
        M: 'images/progresscircle/circle_progress_black_m/',
        S: 'images/progresscircle/circle_progress_black_s/',
    },
    WHITE: {
        L: 'images/progresscircle/circle_progress_l/',
        M: 'images/progresscircle/circle_progress_m/',
        S: 'images/progresscircle/circle_progress_s/',
    },
    HIGHCONTRAST: {
        L: 'images/progresscircle/highcontrast_circle_progress_l/',
        M: 'images/progresscircle/highcontrast_circle_progress_m/',
        S: 'images/progresscircle/highcontrast_circle_progress_s/',
    },
};
 
 
const SizeMap = {
    L: IMAGE_SIZE.LARGE,
    M: IMAGE_SIZE.MEDIUM,
    S: IMAGE_SIZE.SMALL,
};
 
const FontSizeMap = {
    L: FONT_SIZE.LARGE,
    M: FONT_SIZE.MEDIUM,
    S: FONT_SIZE.SMALL,
};
 
export default class ProgressCircle extends React.Component {
 
    componentDidMount() {
    }
 
    componentWillReceiveProps(nextProps) {
    }
 
    shouldComponentUpdate(nextProps, nextState) {
        return (JSON.stringify(nextProps) !== JSON.stringify(this.props));
    }
 
    componentDidUpdate(prevProps, prevState) {
        // console.error('componentDidUpdate');
    }
 
    componentWillUnmount() {
    }
 
    getImage() {
        const { theme, size, progress } = this.props;
 
        let strProgress;
        if (progress < 10) {
            strProgress = `0${progress}`;
        } else {
            strProgress = progress.toString();
        }
 
        return `${ResourceMap[theme][size]}circle_progress_${theme.toLowerCase()}${size.toLowerCase()}_${strProgress}.png`;
    }
 
    render() {
        const { size, progress, text, fontFamily, fontColor, enlarge } = this.props;
        const Style = {
            position: 'relative',
            width: SizeMap[size],
            height: SizeMap[size],
        };
 
        const TextStyle = {
            position: 'absolute',
            lineHeight: `${SizeMap[size]}px`,
            fontSize: `${enlarge ? (FontSizeMap[size] * 1.2) : FontSizeMap[size]}px`,
            fontFamily,
            color: fontColor,
            opacity: 1,
            textAlign: 'center',
            top: 0,
            left: 0,
            width: SizeMap[size],
            height: SizeMap[size],
        };
 
        return (
          <div style={Style} >
            <img src={this.getImage()} />
            <p style={TextStyle}>
              {text}
            </p>
          </div>
        );
    }
}
 
ProgressCircle.defaultProps = {
    theme: PROGRESS_CIRCLE_THEME.WHITE,
    size: PROGRESS_CIRCLE_SIZE.LARGE,
    fontFamily: 'SamsungOneGui_400',
    fontColor: '#111111',
    text: null,
    enlarge: false,
};
 
ProgressCircle.propTypes = {
    theme: PropTypes.string,
    size: PropTypes.string,
    fontFamily: PropTypes.string,
    fontColor: PropTypes.string,
    enlarge: PropTypes.bool,
    progress: PropTypes.number.isRequired,
};