Skip to content

Commit 641b1b5

Browse files
authored
feat: Add custom styles for current step and completed steps
* feat: Add custom styles for current step and completed steps
1 parent 71d2eb9 commit 641b1b5

File tree

6 files changed

+214
-160
lines changed

6 files changed

+214
-160
lines changed

README.md

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,20 @@ Props that can be passed to the component are listed below:
141141
Prop that allows for dynamic content display when the step is active
142142
</td>
143143
<td><code>undefined</code></td>
144+
</tr>
145+
<tr>
146+
<td><code><b>completedNodeStyle?</b></td>
147+
<td>
148+
Prop that allows for dynamic styling of completed nodes
149+
</td>
150+
<td><code>undefined</code></td>
151+
</tr>
152+
<tr>
153+
<td><code><b>currentNodeStyle?</b></td>
154+
<td>
155+
Prop that allows for dynamic styling of current active node
156+
</td>
157+
<td><code>undefined</code></td>
144158
</tr>
145159
<tr>
146160
<td><code><b>styles?:</b> object</code></td>
@@ -172,7 +186,8 @@ function App() {
172186
}),
173187
CompletedNode: () => ({
174188
backgroundColor: "#028A0F",
175-
};
189+
})
190+
};
176191

177192
return (
178193
<Stepper

src/node/node.tsx

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -12,38 +12,38 @@ const Node: FC<INodeProps> = (props) => {
1212
currentStepIndex,
1313
handleStepClick,
1414
showCursor,
15-
getStyles
15+
getStyles,
16+
nodeStyle
1617
} = props;
1718

19+
const isCompleted = step.completed;
20+
const isActive = index === currentStepIndex;
21+
1822
return (
1923
<div
2024
className={`${styles.eachNode}
2125
${showCursor && styles.cursorPointer}
22-
${index === currentStepIndex && styles.activeStepNode}
23-
${!step.completed && currentStepIndex !== index && styles.inactiveStepNode}
24-
${step.completed && currentStepIndex !== index && styles.completedStepNode}
26+
${isActive && styles.activeStepNode}
27+
${!isCompleted && !isActive && styles.inactiveStepNode}
28+
${isCompleted && !isActive && styles.completedStepNode}
2529
`}
26-
style={{
27-
...((getStyles(Elements.Node)) || {}),
28-
...((index === currentStepIndex && getStyles(Elements.ActiveNode)) || {}),
29-
...((step.completed && getStyles(Elements.CompletedNode)) || {}),
30-
...((!step.completed && currentStepIndex !== index
31-
&& getStyles(Elements.InActiveNode)) || {})
32-
}}
30+
style={nodeStyle}
3331
onClick={(): void | null => handleStepClick && handleStepClick()}
3432
role="presentation"
3533
id="stepper-node"
3634
>
3735
{(renderNode && renderNode(step, index))
3836
|| (
3937
<>
40-
{step?.completed && (
38+
{isCompleted ? (
4139
<img
4240
src={whiteTick}
4341
className={styles.whiteTickImg}
4442
alt=""
45-
/>)
46-
|| index + 1}
43+
/>
44+
) : (
45+
index + 1
46+
)}
4747
</>
4848
)}
4949
</div>

src/node/types.d.ts

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
1-
import { ReactElement } from "react";
2-
import { IStep } from "../stepper/types";
1+
import { ReactElement, CSSProperties } from "react";
32
import { Elements } from "../constants";
3+
import type { IStep } from "../stepper/types";
44

5-
export type INodeProps = {
5+
export interface INodeProps {
66
step: IStep;
7-
renderNode?(step: IStep, index: number): ReactElement;
87
index: number;
9-
currentStepIndex?: number;
10-
handleStepClick(): void;
8+
currentStepIndex: number;
9+
handleStepClick?: () => void;
1110
showCursor: boolean;
12-
getStyles(element: Elements): object;
13-
};
11+
renderNode?: (step: IStep, stepIndex: number) => ReactElement;
12+
getStyles: (element: Elements) => object;
13+
nodeStyle?: CSSProperties;
14+
}

src/stepper/step.tsx

Lines changed: 27 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import React, { useRef, useEffect, useState } from "react";
22
import "./styles.scss";
3-
import type { IStepProps } from "../stepper/types";
3+
import type { IStepProps } from "./types";
44
import { LABEL_POSITION, ORIENTATION } from "../constants";
55
import StepContent from "./stepContent";
66
import StepInfo from "./stepInfo";
@@ -20,7 +20,9 @@ const Step: (props: IStepProps) => JSX.Element = ({
2020
showDescriptionsForAllSteps = false,
2121
stepContent,
2222
onStepClick,
23-
renderNode
23+
renderNode,
24+
completedNodeStyle,
25+
currentNodeStyle
2426
} = stepperProps;
2527
const [nodeWidth, setNodeWidth] = useState(0);
2628

@@ -62,51 +64,39 @@ const Step: (props: IStepProps) => JSX.Element = ({
6264
currentStepIndex > index ? "activeConnector" : ""
6365
} ${index === steps.length - 1 ? "hiddenConnector" : ""}`;
6466

67+
const stepInfoProps = {
68+
orientation,
69+
labelPosition,
70+
isVertical,
71+
isInlineLabelsAndSteps,
72+
index,
73+
currentStepIndex,
74+
step,
75+
showDescriptionsForAllSteps,
76+
onStepClick,
77+
renderNode,
78+
styles,
79+
nodeRef,
80+
prevConnectorClassName,
81+
nextConnectorClassName,
82+
steps,
83+
completedNodeStyle,
84+
currentNodeStyle
85+
};
86+
6587
return orientation !== ORIENTATION.VERTICAL &&
6688
labelPosition === LABEL_POSITION.TOP ? (
67-
<StepInfo
68-
orientation={orientation}
69-
labelPosition={labelPosition}
70-
isVertical={isVertical}
71-
isInlineLabelsAndSteps={isInlineLabelsAndSteps}
72-
index={index}
73-
currentStepIndex={currentStepIndex}
74-
step={step}
75-
showDescriptionsForAllSteps={showDescriptionsForAllSteps}
76-
onStepClick={onStepClick}
77-
renderNode={renderNode}
78-
styles={styles}
79-
nodeRef={nodeRef}
80-
prevConnectorClassName={prevConnectorClassName}
81-
nextConnectorClassName={nextConnectorClassName}
82-
steps={steps}
83-
/>
89+
<StepInfo {...stepInfoProps} />
8490
) : (
8591
<div
8692
className={
8793
orientation === ORIENTATION.VERTICAL &&
88-
labelPosition === LABEL_POSITION.LEFT
94+
labelPosition === LABEL_POSITION.LEFT
8995
? "verticalTextLeftContainer"
9096
: ""
9197
}
9298
>
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-
/>
99+
<StepInfo {...stepInfoProps} />
110100
<StepContent
111101
labelPosition={labelPosition}
112102
isVertical={isVertical}

0 commit comments

Comments
 (0)