1- import React , { useRef , useEffect , useState } from " react" ;
2- import " ./styles.scss" ;
3- import type { IStepProps } from " ../stepper/types" ;
4- import { LABEL_POSITION , ORIENTATION } from " ../constants" ;
5- import StepContent from " ./stepContent" ;
6- import StepInfo from " ./stepInfo" ;
1+ import React , { useRef , useEffect , useState , FC } from ' react' ;
2+ import ' ./styles.scss' ;
3+ import type { IStepProps } from ' ../stepper/types' ;
4+ import { LABEL_POSITION , ORIENTATION } from ' ../constants' ;
5+ import StepContent from ' ./stepContent' ;
6+ import StepInfo from ' ./stepInfo' ;
77
8- // Each step consists of a node, a label, and connectors to the previous and next steps.
8+ /**
9+ * Represents each step.
10+ * Consist of node, label and connectors to previous and next step
11+ * @function
12+ * @param {IStepProps } props
13+ * @returns {FC }
14+ */
915const Step : ( props : IStepProps ) => JSX . Element = ( {
1016 stepperProps,
1117 step,
12- index
18+ index,
1319} : IStepProps ) => {
1420 const {
1521 steps,
@@ -20,7 +26,7 @@ const Step: (props: IStepProps) => JSX.Element = ({
2026 showDescriptionsForAllSteps = false ,
2127 stepContent,
2228 onStepClick,
23- renderNode
29+ renderNode,
2430 } = stepperProps ;
2531 const [ nodeWidth , setNodeWidth ] = useState ( 0 ) ;
2632
@@ -46,24 +52,50 @@ const Step: (props: IStepProps) => JSX.Element = ({
4652
4753 // prevConnector represents the connector line from the current step's node (nth node) to the preceding step's node (n-1 th node).
4854 const prevConnectorClassName = `stepConnector leftConnector ${
49- steps [ index - 1 ] ?. completed ? " activeConnector" : ""
50- } ${ index === 0 ? " hiddenConnector" : "" } `;
55+ steps [ index - 1 ] ?. completed ? ' activeConnector' : ''
56+ } ${ index === 0 ? ' hiddenConnector' : '' } `;
5157
5258 // nextConnector represents the connector line from the current step's node (nth node) to the preceding step's node (n-1 th node).
5359
5460 const nextConnectorClassName = `stepConnector rightConnector ${
55- steps [ index ] ?. completed ? " activeConnector" : ""
56- } ${ index === steps . length - 1 ? " hiddenConnector" : "" } `;
61+ steps [ index ] ?. completed ? ' activeConnector' : ''
62+ } ${ index === steps . length - 1 ? ' hiddenConnector' : '' } `;
5763
5864 /* middleConnector connects the current step nextConnector to (n+1th) step prevConnector,
5965 allowing the display of descriptions or content between the two steps when necessary. */
6066
6167 const middleConnectorClassName = `middleStepConnector ${
62- currentStepIndex > index ? " activeConnector" : ""
63- } ${ index === steps . length - 1 ? " hiddenConnector" : "" } `;
68+ currentStepIndex > index ? ' activeConnector' : ''
69+ } ${ index === steps . length - 1 ? ' hiddenConnector' : '' } `;
6470
6571 return orientation !== ORIENTATION . VERTICAL &&
6672 labelPosition === LABEL_POSITION . TOP ? (
73+ < StepInfo
74+ orientation = { orientation }
75+ labelPosition = { labelPosition }
76+ isVertical = { isVertical }
77+ isInlineLabelsAndSteps = { isInlineLabelsAndSteps }
78+ index = { index }
79+ currentStepIndex = { currentStepIndex }
80+ step = { step }
81+ showDescriptionsForAllSteps = { showDescriptionsForAllSteps }
82+ onStepClick = { onStepClick }
83+ renderNode = { renderNode }
84+ styles = { styles }
85+ nodeRef = { nodeRef }
86+ prevConnectorClassName = { prevConnectorClassName }
87+ nextConnectorClassName = { nextConnectorClassName }
88+ steps = { steps }
89+ />
90+ ) : (
91+ < div
92+ className = {
93+ orientation === ORIENTATION . VERTICAL &&
94+ labelPosition === LABEL_POSITION . LEFT
95+ ? 'verticalTextLeftContainer'
96+ : ''
97+ }
98+ >
6799 < StepInfo
68100 orientation = { orientation }
69101 labelPosition = { labelPosition }
@@ -81,46 +113,20 @@ const Step: (props: IStepProps) => JSX.Element = ({
81113 nextConnectorClassName = { nextConnectorClassName }
82114 steps = { steps }
83115 />
84- ) : (
85- < div
86- className = {
87- orientation === ORIENTATION . VERTICAL &&
88- labelPosition === LABEL_POSITION . LEFT
89- ? "verticalTextLeftContainer"
90- : ""
91- }
92- >
93- < StepInfo
94- orientation = { orientation }
95- labelPosition = { labelPosition }
96- isVertical = { isVertical }
97- isInlineLabelsAndSteps = { isInlineLabelsAndSteps }
98- index = { index }
99- currentStepIndex = { currentStepIndex }
100- step = { step }
101- showDescriptionsForAllSteps = { showDescriptionsForAllSteps }
102- onStepClick = { onStepClick }
103- renderNode = { renderNode }
104- styles = { styles }
105- nodeRef = { nodeRef }
106- prevConnectorClassName = { prevConnectorClassName }
107- nextConnectorClassName = { nextConnectorClassName }
108- steps = { steps }
109- />
110- < StepContent
111- labelPosition = { labelPosition }
112- isVertical = { isVertical }
113- currentStepIndex = { currentStepIndex }
114- index = { index }
115- styles = { styles }
116- step = { step }
117- showDescriptionsForAllSteps = { showDescriptionsForAllSteps }
118- middleConnectorClassName = { middleConnectorClassName }
119- stepContent = { stepContent }
120- nodeWidth = { nodeWidth }
121- />
122- </ div >
123- ) ;
116+ < StepContent
117+ labelPosition = { labelPosition }
118+ isVertical = { isVertical }
119+ currentStepIndex = { currentStepIndex }
120+ index = { index }
121+ styles = { styles }
122+ step = { step }
123+ showDescriptionsForAllSteps = { showDescriptionsForAllSteps }
124+ middleConnectorClassName = { middleConnectorClassName }
125+ stepContent = { stepContent }
126+ nodeWidth = { nodeWidth }
127+ />
128+ </ div >
129+ ) ;
124130} ;
125131
126132export default Step ;
0 commit comments