|
1 | 1 | import React, { useState, useEffect, ReactElement } from 'react'; |
2 | 2 | import styles from './styles'; |
3 | | -import { Istep, IstepperProps } from './types'; |
4 | | -import whiteTick from '../assets/white-tick.svg'; |
5 | | -import { STEP_STATUSES } from './constants'; |
| 3 | +import { IStep, IStepperProps } from './types'; |
| 4 | +import Bubble from '../bubble'; |
6 | 5 |
|
7 | | -const Stepper = (props: IstepperProps): ReactElement => { |
8 | | - const { steps, currentActiveStepIndex, onStepClick, enableStepClick = false } = props; |
| 6 | +const Stepper = (props: IStepperProps): ReactElement => { |
| 7 | + const { steps, currentActiveStepIndex, onStepClick, enableStepClick = false, renderAdornment } = props; |
9 | 8 |
|
10 | | - const [currentActiveStepIndexVal, setCurrentActiveStepIndexVal] = useState<number>() |
| 9 | + const [currentActiveStepIndexVal, setCurrentActiveStepIndexVal] = useState<number>(); |
11 | 10 |
|
12 | 11 | useEffect(() => { |
13 | 12 | setCurrentActiveStepIndexVal(currentActiveStepIndex ?? 0); |
14 | 13 | }, [currentActiveStepIndex]); |
15 | 14 |
|
16 | 15 | const handleStepClick = (stepIndex: number): void => { |
17 | 16 | if (enableStepClick) { |
18 | | - if (onStepClick !== undefined ) onStepClick(stepIndex); |
| 17 | + if (onStepClick) onStepClick(stepIndex); |
19 | 18 | else setCurrentActiveStepIndexVal(stepIndex); |
20 | 19 | } |
21 | 20 | } |
22 | 21 |
|
23 | 22 | return ( |
24 | 23 | <div style={styles.stepperContainer}> |
25 | | - {steps?.map((step: Istep, index: number): ReactElement => ( |
| 24 | + {steps?.map((step: IStep, index: number): ReactElement => ( |
26 | 25 | <div key={index} style={styles.eachStep}> |
27 | 26 | <div style={styles.bubbleLineWrapper}> |
28 | | - <div |
29 | | - style={{...styles.eachBubble, |
30 | | - ...((enableStepClick && styles.cursorPointer) || {}), |
31 | | - ...((index === currentActiveStepIndexVal) && styles.activeStepBubble || {}), |
32 | | - ...((step.status === STEP_STATUSES.UNVISITED && currentActiveStepIndexVal !== index) && styles.inactiveStepBubble || {}) |
33 | | - }} |
34 | | - onClick={(): void => handleStepClick(index)} |
35 | | - role="presentation" |
36 | | - > |
37 | | - {step?.status === STEP_STATUSES.COMPLETED && ( |
38 | | - <img |
39 | | - src={whiteTick} |
40 | | - style={styles.whiteTickImg} |
41 | | - alt="" |
42 | | - /> |
43 | | - ) |
44 | | - || index + 1} |
45 | | - </div> |
| 27 | + <Bubble |
| 28 | + step={step} |
| 29 | + index={index} |
| 30 | + enableStepClick={enableStepClick} |
| 31 | + currentActiveStepIndexVal= {currentActiveStepIndexVal} |
| 32 | + handleStepClick={handleStepClick} |
| 33 | + renderAdornment={renderAdornment} |
| 34 | + /> |
46 | 35 | <div style={styles.eachLabel}> |
47 | 36 | {step?.label && ( |
48 | 37 | <span |
|
0 commit comments