-
Notifications
You must be signed in to change notification settings - Fork 256
/
WizardProgressBar.tsx
71 lines (58 loc) · 1.83 KB
/
WizardProgressBar.tsx
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
// Libraries
import React, {PureComponent} from 'react'
// Components
import ProgressConnector from 'src/reusable_ui/components/wizard/ProgressConnector'
// Types
import {Step} from 'src/types/wizard'
import {ConnectorState, StepStatus} from 'src/reusable_ui/constants/wizard'
import {ErrorHandling} from 'src/shared/decorators/errors'
interface Props {
steps: Step[]
currentStepIndex: number
handleJump: (jumpIndex: number) => () => void
}
@ErrorHandling
class WizardProgressBar extends PureComponent<Props> {
public render() {
return <div className="wizard-progress-bar">{this.WizardProgress}</div>
}
private get WizardProgress(): JSX.Element {
const {steps, currentStepIndex, handleJump} = this.props
const progressBar = steps.reduce((acc, step, i) => {
const {stepStatus} = step
let currentStep = ''
// STEP STATUS
if (i === currentStepIndex) {
currentStep = 'circle-thick current'
}
const stepEle = (
<div
key={`stepEle${i}`}
className="wizard-progress-button"
onClick={handleJump(i)}
>
<div className="wizard-progress-title">{step.title}</div>
<span className={`icon ${currentStep || stepStatus}`} />
</div>
)
// PROGRESS BAR CONNECTOR
let connectorStatus
if (i > 0 && steps[i - 1].stepStatus === StepStatus.Complete) {
connectorStatus = ConnectorState.Some
if (stepStatus === StepStatus.Complete) {
connectorStatus = ConnectorState.Full
}
}
const connectorEle =
i === 0 ? null : (
<ProgressConnector
key={`connectorEle${i}`}
status={connectorStatus}
/>
)
return [...acc, connectorEle, stepEle]
}, [])
return <>{progressBar}</>
}
}
export default WizardProgressBar