11import React , { useState , useEffect , ReactElement , FC } from 'react' ;
2- import styles from './styles.module.scss' ;
2+ import classes from './styles.module.scss' ;
33import { IStep , IStepperProps } from './types' ;
44import Bubble from '../bubble' ;
55import { LABEL_POSITION } from '../constants' ;
66
77const Stepper : FC < IStepperProps > = ( props ) => {
88 const {
99 steps,
10- currentActiveStepIndex,
11- enableStepClick = false ,
10+ currentStepIndex,
1211 onStepClick,
13- renderAdornment ,
14- stylesOverride = { } ,
12+ renderBubble ,
13+ styles = { } ,
1514 labelPosition = LABEL_POSITION . RIGHT
1615 } = props ;
1716
@@ -25,80 +24,66 @@ const Stepper: FC<IStepperProps> = (props) => {
2524 getBubbleStyles,
2625 getActiveBubbleStyles,
2726 getInActiveBubbleStyles
28- } = stylesOverride ;
29-
30- const [ currentActiveStepIndexVal , setCurrentActiveStepIndexVal ] = useState < number > ( 0 ) ;
31-
32- useEffect ( ( ) => {
33- setCurrentActiveStepIndexVal ( ( currentActiveStepIndex ?? 0 ) as number ) ;
34- } , [ currentActiveStepIndex ] ) ;
35-
36- const handleStepClick = ( stepIndex : number ) : void => {
37- if ( enableStepClick ) {
38- if ( onStepClick ) onStepClick ( stepIndex ) ;
39- else setCurrentActiveStepIndexVal ( stepIndex ) ;
40- }
41- }
27+ } = styles ;
4228
4329 return (
44- < div className = { styles . stepperContainer } >
45- { steps ?. map ( ( step : IStep , index : number ) : ReactElement => (
46- < div key = { index } className = { styles . eachStep } data-testId = "stepper-steps" >
47- < div className = { styles . bubbleLineWrapper } >
30+ < div className = { classes . stepperContainer } >
31+ { steps ?. map ( ( step : IStep , stepIndex : number ) : ReactElement => (
32+ < div key = { stepIndex } className = { classes . eachStep } data-testId = "stepper-steps" >
33+ < div className = { classes . bubbleLineWrapper } >
4834 < Bubble
4935 step = { step }
50- index = { index }
51- enableStepClick = { enableStepClick }
52- currentActiveStepIndexVal = { currentActiveStepIndexVal }
53- handleStepClick = { handleStepClick }
54- renderAdornment = { renderAdornment }
36+ index = { stepIndex }
37+ currentStepIndex = { currentStepIndex }
38+ handleStepClick = { ( ) : void => onStepClick && onStepClick ( step , stepIndex ) }
39+ renderAdornment = { renderBubble }
5540 getBubbleStyles = { getBubbleStyles }
5641 getActiveBubbleStyles = { getActiveBubbleStyles }
5742 getInActiveBubbleStyles = { getInActiveBubbleStyles }
5843 />
59- < div className = { `${ styles . labelContainer } ${ styles [ `labelContainer__${ labelPosition || LABEL_POSITION . RIGHT } ` ] } ` } >
44+ < div className = { `${ classes . labelContainer } ${ classes [ `labelContainer__${ labelPosition || LABEL_POSITION . RIGHT } ` ] } ` } >
6045 { step ?. label && (
6146 < span
62- className = { `${ styles . labelTitle }
63- ${ enableStepClick && styles . cursorPointer }
64- ${ index === currentActiveStepIndexVal && styles . activeLabelTitle } ` }
47+ className = { `${ classes . labelTitle }
48+ ${ onStepClick && classes . cursorPointer }
49+ ${ stepIndex === currentStepIndex && classes . activeLabelTitle } ` }
6550 style = { {
66- ...( ( getLabelTitleStyles && getLabelTitleStyles ( step , index ) ) || { } ) ,
67- ...( ( index === currentActiveStepIndexVal && getActiveLabelTitleStyles && getActiveLabelTitleStyles ( step , index ) ) || { } )
51+ ...( ( getLabelTitleStyles && getLabelTitleStyles ( step , stepIndex ) ) || { } ) ,
52+ ...( ( stepIndex === currentStepIndex && getActiveLabelTitleStyles && getActiveLabelTitleStyles ( step , stepIndex ) ) || { } )
6853 } }
69- onClick = { ( ) : void => handleStepClick ( index ) }
54+ onClick = { ( ) : void => onStepClick && onStepClick ( step , stepIndex ) }
7055 role = "presentation"
71- data-testId = { `stepper-label-${ index } ` }
56+ data-testId = { `stepper-label-${ stepIndex } ` }
7257 >
7358 { step . label }
7459 </ span >
7560 ) }
7661 { step ?. description && (
7762 < span
78- className = { `${ styles . labelDescription }
79- ${ enableStepClick && styles . cursorPointer }
80- ${ index === currentActiveStepIndexVal && styles . activeLabelDescription } ` }
63+ className = { `${ classes . labelDescription }
64+ ${ onStepClick && classes . cursorPointer }
65+ ${ stepIndex === currentStepIndex && classes . activeLabelDescription } ` }
8166 style = { {
82- ...( ( getLabelDescriptionStyles && getLabelDescriptionStyles ( step , index ) ) || { } ) ,
83- ...( ( index === currentActiveStepIndexVal &&
84- getActiveLabelDescriptionStyles && getActiveLabelDescriptionStyles ( step , index ) ) || { } )
67+ ...( ( getLabelDescriptionStyles && getLabelDescriptionStyles ( step , stepIndex ) ) || { } ) ,
68+ ...( ( stepIndex === currentStepIndex &&
69+ getActiveLabelDescriptionStyles && getActiveLabelDescriptionStyles ( step , stepIndex ) ) || { } )
8570 } }
86- onClick = { ( ) : void => handleStepClick ( index ) }
71+ onClick = { ( ) : void => onStepClick && onStepClick ( step , stepIndex ) }
8772 role = "presentation"
88- data-testId = { `stepper-desc-${ index } ` }
73+ data-testId = { `stepper-desc-${ stepIndex } ` }
8974 >
9075 { step . description }
9176 </ span >
9277 ) }
9378 </ div >
94- { index < steps ?. length - 1 && (
79+ { stepIndex < steps ?. length - 1 && (
9580 < div
96- className = { `${ styles . lineSeparator }
97- ${ index > currentActiveStepIndexVal - 1 && styles . inactiveStepLineSeparator } ` }
81+ className = { `${ classes . lineSeparator }
82+ ${ currentStepIndex && stepIndex > currentStepIndex - 1 && classes . inactiveStepLineSeparator } ` }
9883 style = { {
99- ...( ( getLineSeparatorStyles && getLineSeparatorStyles ( step , index ) ) || { } ) ,
100- ...( ( index > currentActiveStepIndexVal - 1
101- && getInactiveLineSeparatorStyles && getInactiveLineSeparatorStyles ( step , index ) ) || { } )
84+ ...( ( getLineSeparatorStyles && getLineSeparatorStyles ( step , stepIndex ) ) || { } ) ,
85+ ...( ( currentStepIndex && stepIndex > currentStepIndex - 1
86+ && getInactiveLineSeparatorStyles && getInactiveLineSeparatorStyles ( step , stepIndex ) ) || { } )
10287 } }
10388 />
10489 ) }
0 commit comments