1- /* eslint-disable @typescript-eslint/no-var-requires */
2- import React , { useState , useEffect } from 'react' ;
1+ import React , { useState , useEffect , ReactElement } from 'react' ;
32import './styles.css' ;
43import { Istep , IstepperProps } from './types' ;
54import whiteTick from '../assets/white-tick.svg' ;
5+ import { STEP_STATUSES } from './constants' ;
66
7- const Stepper = ( props : IstepperProps ) : any => {
8- const { steps, currentActiveStepIndex } = props ;
7+ const Stepper = ( props : IstepperProps ) : ReactElement => {
8+ const { steps, currentActiveStepIndex, onStepClick , enableStepClick = false } = props ;
99
10- // const whiteTick = require('../assets/white-tick.svg') as string;
11- const [ stepsVal , setSteps ] = useState < Istep [ ] > ( [ ] ) ;
1210 const [ currentActiveStepIndexVal , setCurrentActiveStepIndexVal ] = useState < number > ( )
1311
14- useEffect ( ( ) => {
15- setSteps ( steps ) ;
16- } , [ steps ] ) ;
17-
1812 useEffect ( ( ) => {
1913 setCurrentActiveStepIndexVal ( currentActiveStepIndex ?? 0 ) ;
2014 } , [ currentActiveStepIndex ] ) ;
2115
16+ const handleStepClick = ( stepIndex : number ) : void => {
17+ if ( enableStepClick ) {
18+ if ( onStepClick !== undefined ) onStepClick ( stepIndex ) ;
19+ else setCurrentActiveStepIndexVal ( stepIndex ) ;
20+ }
21+ }
22+
2223 return (
2324 < div className = "stepperContainer" >
24- { stepsVal ?. map ( ( step : Istep , index : number ) => (
25+ { steps ?. map ( ( step : Istep , index : number ) : ReactElement => (
2526 < div key = { index } className = "eachStep" >
2627 < div className = 'bubbleLineWrapper' >
2728 < div
2829 className = { `eachBubble
30+ ${ enableStepClick && 'cursorPointer' }
2931 ${ index === currentActiveStepIndexVal && 'activeStepBubble' }
30- ${ index > currentActiveStepIndexVal && 'inactiveStepBubble' } ` }
32+ ${ ( step . status === STEP_STATUSES . UNVISITED && currentActiveStepIndexVal !== index ) && 'inactiveStepBubble' } ` }
33+ onClick = { ( ) : void => handleStepClick ( index ) }
3134 >
32- { currentActiveStepIndexVal > index && (
35+ { step ?. status === STEP_STATUSES . COMPLETED && (
3336 < img
3437 src = { whiteTick }
3538 className = "whiteTickImg"
@@ -40,17 +43,17 @@ const Stepper = (props: IstepperProps): any => {
4043 </ div >
4144 < div className = 'eachLabel' >
4245 { step . label && (
43- < span className = ' labelTitle' >
46+ < span className = { ` labelTitle ${ index === currentActiveStepIndexVal && 'activeLabelTitle' } ` } >
4447 { step ?. label }
4548 </ span >
4649 ) }
4750 { step ?. description && (
48- < span className = ' labelDescription' >
51+ < span className = { ` labelDescription ${ index === currentActiveStepIndexVal && 'activeLabelDescription' } ` } >
4952 { step ?. description }
5053 </ span >
5154 ) }
5255 </ div >
53- { index < stepsVal ?. length - 1 && (
56+ { index < steps ?. length - 1 && (
5457 < div className = { `lineSeparator ${ ( index > currentActiveStepIndexVal - 1 ) && 'activeStepLineSeparator' } ` } />
5558 ) }
5659 </ div >
0 commit comments