11import React , { useState , useEffect , ReactElement , FC } from 'react' ;
2- import styles from './styles' ;
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,68 @@ 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 style = { styles . stepperContainer } >
45- { steps ?. map ( ( step : IStep , index : number ) : ReactElement => (
46- < div key = { index } style = { styles . eachStep } data-testId = "stepper-steps" >
47- < div style = { 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
60- style = { {
61- ...styles . labelContainer ,
62- ...styles [ `labelContainer__${ labelPosition } ` ] ?? { }
63- } }
64- >
44+ < div className = { `${ classes . labelContainer } ${ classes [ `labelContainer__${ labelPosition || LABEL_POSITION . RIGHT } ` ] } ` } >
6545 { step ?. label && (
6646 < span
67- style = { { ...styles . labelTitle ,
68- ...( ( enableStepClick && styles . cursorPointer ) || { } ) ,
69- ...( ( getLabelTitleStyles && getLabelTitleStyles ( step , index ) ) || { } ) ,
70- ...( ( index === currentActiveStepIndexVal && styles . activeLabelTitle ) || { } ) ,
71- ...( ( index === currentActiveStepIndexVal && getActiveLabelTitleStyles && getActiveLabelTitleStyles ( step , index ) ) || { } )
47+ className = { `${ classes . labelTitle }
48+ ${ onStepClick && classes . cursorPointer }
49+ ${ stepIndex === currentStepIndex && classes . activeLabelTitle } ` }
50+ style = { {
51+ ...( ( getLabelTitleStyles && getLabelTitleStyles ( step , stepIndex ) ) || { } ) ,
52+ ...( ( stepIndex === currentStepIndex && getActiveLabelTitleStyles && getActiveLabelTitleStyles ( step , stepIndex ) ) || { } )
7253 } }
73- onClick = { ( ) : void => handleStepClick ( index ) }
54+ onClick = { ( ) : void => onStepClick && onStepClick ( step , stepIndex ) }
7455 role = "presentation"
75- data-testId = { `stepper-label-${ index } ` }
56+ data-testId = { `stepper-label-${ stepIndex } ` }
7657 >
7758 { step . label }
7859 </ span >
7960 ) }
8061 { step ?. description && (
81- < span style = { { ...styles . labelDescription ,
82- ...( ( enableStepClick && styles . cursorPointer ) || { } ) ,
83- ...( ( getLabelDescriptionStyles && getLabelDescriptionStyles ( step , index ) ) || { } ) ,
84- ...( ( index === currentActiveStepIndexVal ) && styles . activeLabelDescription || { } ) ,
85- ...( ( index === currentActiveStepIndexVal && getActiveLabelDescriptionStyles && getActiveLabelDescriptionStyles ( step , index ) ) || { } )
86- } }
87- onClick = { ( ) : void => handleStepClick ( index ) }
88- role = "presentation"
89- data-testId = { `stepper-desc-${ index } ` }
62+ < span
63+ className = { `${ classes . labelDescription }
64+ ${ onStepClick && classes . cursorPointer }
65+ ${ stepIndex === currentStepIndex && classes . activeLabelDescription } ` }
66+ style = { {
67+ ...( ( getLabelDescriptionStyles && getLabelDescriptionStyles ( step , stepIndex ) ) || { } ) ,
68+ ...( ( stepIndex === currentStepIndex &&
69+ getActiveLabelDescriptionStyles && getActiveLabelDescriptionStyles ( step , stepIndex ) ) || { } )
70+ } }
71+ onClick = { ( ) : void => onStepClick && onStepClick ( step , stepIndex ) }
72+ role = "presentation"
73+ data-testId = { `stepper-desc-${ stepIndex } ` }
9074 >
9175 { step . description }
9276 </ span >
9377 ) }
9478 </ div >
95- { index < steps ?. length - 1 && (
96- < div style = { { ...styles . lineSeparator ,
97- ...( ( getLineSeparatorStyles && getLineSeparatorStyles ( step , index ) ) || { } ) ,
98- ...( ( index > currentActiveStepIndexVal - 1 ) && styles . inactiveStepLineSeparator || { } ) ,
99- ...( ( index > currentActiveStepIndexVal - 1
100- && getInactiveLineSeparatorStyles && getInactiveLineSeparatorStyles ( step , index ) ) || { } )
101- } } />
79+ { stepIndex < steps ?. length - 1 && (
80+ < div
81+ className = { `${ classes . lineSeparator }
82+ ${ currentStepIndex && stepIndex > currentStepIndex - 1 && classes . inactiveStepLineSeparator } ` }
83+ style = { {
84+ ...( ( getLineSeparatorStyles && getLineSeparatorStyles ( step , stepIndex ) ) || { } ) ,
85+ ...( ( currentStepIndex && stepIndex > currentStepIndex - 1
86+ && getInactiveLineSeparatorStyles && getInactiveLineSeparatorStyles ( step , stepIndex ) ) || { } )
87+ } }
88+ />
10289 ) }
10390 </ div >
10491 </ div >
0 commit comments