1+ /* eslint-disable @typescript-eslint/no-var-requires */
12import React , { useState , useEffect } from 'react' ;
23import './styles.css' ;
3- import { stepTypes } from './types' ;
4+ import { Istep , IstepperProps } from './types' ;
5+ import whiteTick from '../assets/white-tick.svg' ;
46
5- const Stepper = ( props : { steps : stepTypes [ ] } ) : any => {
6- const { steps } = props ;
7+ const Stepper = ( props : IstepperProps ) : any => {
8+ const { steps, currentActiveStepIndex } = props ;
79
8- const [ stepVal , setSteps ] = useState ( [ ] ) ;
10+ // const whiteTick = require('../assets/white-tick.svg') as string;
11+ const [ stepsVal , setSteps ] = useState < Istep [ ] > ( [ ] ) ;
12+ const [ currentActiveStepIndexVal , setCurrentActiveStepIndexVal ] = useState < number > ( )
913
10- useEffect ( ( ) => {
14+ useEffect ( ( ) => {
1115 setSteps ( steps ) ;
1216 } , [ steps ] ) ;
17+
18+ useEffect ( ( ) => {
19+ setCurrentActiveStepIndexVal ( currentActiveStepIndex ?? 0 ) ;
20+ } , [ currentActiveStepIndex ] ) ;
21+
1322 return (
1423 < div className = "stepperContainer" >
15- { stepVal ?. map ( ( step , index ) => ( index < stepVal ?. length - 1 ) && (
24+ { stepsVal ?. map ( ( step : Istep , index : number ) => (
1625 < div key = { index } className = "eachStep" >
1726 < div className = 'bubbleLineWrapper' >
18- < div className = 'eachBubble' > { index + 1 } </ div >
27+ < div
28+ className = { `eachBubble
29+ ${ index === currentActiveStepIndexVal && 'activeStepBubble' }
30+ ${ index > currentActiveStepIndexVal && 'inactiveStepBubble' } ` }
31+ >
32+ { currentActiveStepIndexVal > index && (
33+ < img
34+ src = { whiteTick }
35+ className = "whiteTickImg"
36+ alt = ""
37+ />
38+ )
39+ || index + 1 }
40+ </ div >
1941 < div className = 'eachLabel' >
2042 { step . label && (
2143 < span className = 'labelTitle' >
@@ -28,29 +50,12 @@ const Stepper = (props: { steps: stepTypes[]}): any => {
2850 </ span >
2951 ) }
3052 </ div >
31- < div className = 'lineSeparator' />
32- </ div >
33- </ div >
34- ) ) }
35- < div className = "eachStep" >
36- < div className = 'bubbleLineWrapper' >
37- < div className = 'eachBubble' >
38- { stepVal ?. length }
39- </ div >
40- < div className = 'eachLabel' >
41- { stepVal [ stepVal ?. length - 1 ] ?. label && (
42- < span className = 'labelTitle' >
43- { stepVal [ stepVal ?. length - 1 ] ?. label }
44- </ span >
45- ) }
46- { stepVal [ stepVal ?. length - 1 ] ?. description && (
47- < span className = 'labelDescription' >
48- { stepVal [ stepVal ?. length - 1 ] ?. description }
49- </ span >
53+ { index < stepsVal ?. length - 1 && (
54+ < div className = { `lineSeparator ${ ( index > currentActiveStepIndexVal - 1 ) && 'activeStepLineSeparator' } ` } />
5055 ) }
5156 </ div >
5257 </ div >
53- </ div >
58+ ) ) }
5459 </ div >
5560 ) ;
5661} ;
0 commit comments