1+ require ( './ProgressBar.scss' )
2+
3+ import React from 'react'
4+ import classNames from 'classnames'
5+
6+ const ProgressBar = ( { completionPercentage, checkPoints} ) => {
7+ function getCheckPointPositionStyle ( percentage ) {
8+ const style = {
9+ left :percentage + '%'
10+ }
11+ return style
12+ }
13+
14+ function getCheckPointPositionScaledStyle ( percentage ) {
15+ percentage = Number . parseInt ( percentage ) * 0.8
16+ const style = {
17+ left :percentage + '%'
18+ }
19+ return style
20+ }
21+
22+ function getLengthScaledStyle ( percentage ) {
23+ const style = {
24+ width :percentage + '%'
25+ }
26+ return style
27+ }
28+
29+ function checkPointStyle ( checkPointPercentage ) {
30+ checkPointPercentage = Number . parseInt ( checkPointPercentage )
31+ completionPercentage = Number . parseInt ( completionPercentage )
32+ const checkPointClass = classNames (
33+ 'circle' , { completed : ( checkPointPercentage <= completionPercentage ) }
34+ )
35+ return checkPointClass
36+ }
37+
38+ return (
39+ < div className = "ProgressBar" >
40+ < div className = "progress-box" >
41+ < div className = "checkpoint-line" >
42+ { checkPoints . map ( ( checkPoint , index ) => {
43+ return < div className = "checkpoint-text" style = { getCheckPointPositionScaledStyle ( checkPoint . completionPercentage ) } key = { index } > { checkPoint . name } </ div >
44+ } ) }
45+ </ div >
46+ < div className = "progress-ui" >
47+ < div className = "progress-line" >
48+ </ div >
49+ < div className = "completion-line" style = { getLengthScaledStyle ( completionPercentage ) } >
50+ </ div >
51+ < div className = "progress-circles" >
52+ < div className = "circle" />
53+ { checkPoints . map ( ( checkPoint , index ) => {
54+ return < div className = { checkPointStyle ( checkPoint . completionPercentage ) } style = { getCheckPointPositionStyle ( checkPoint . completionPercentage ) } key = { index } />
55+ } ) }
56+ </ div >
57+ </ div >
58+ < div className = "time-line" >
59+ { checkPoints . map ( ( checkPoint , index ) => {
60+ return < div className = "time-line-text" style = { getCheckPointPositionScaledStyle ( checkPoint . completionPercentage ) } key = { index } > { checkPoint . timeline } </ div >
61+ } ) }
62+ </ div >
63+ </ div >
64+ </ div >
65+ )
66+ }
67+
68+ ProgressBar . propTypes = {
69+ completionPercentage : React . PropTypes . string ,
70+ checkPoints : React . PropTypes . array
71+ }
72+
73+ export default ProgressBar
0 commit comments