Skip to content

feat: Add custom styles for current step and completed steps #37

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Apr 15, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,16 @@ Props that can be passed to the component are listed below:
</td>
<td><code>undefined</code></td>
</tr>
<tr>
<td><code><b>completedNodeStyle?:</b> object</code></td>
<td>Custom styles for completed nodes</td>
<td><code>undefined</code></td>
</tr>
<tr>
<td><code><b>currentNodeStyle?:</b> object</code></td>
<td>Custom styles for current nodes</td>
<td><code>undefined</code></td>
</tr>
</tbody>
</table>

Expand All @@ -159,7 +169,8 @@ function App() {
}),
CompletedNode: () => ({
backgroundColor: "#028A0F",
};
})
};

return (
<Stepper
Expand Down
28 changes: 14 additions & 14 deletions src/node/node.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React, { FC } from "react";
import type { INodeProps } from "./types";
import { Elements } from "../constants";

Check warning on line 3 in src/node/node.tsx

View workflow job for this annotation

GitHub Actions / test-and-build (16.x)

'Elements' is defined but never used
import whiteTick from "../assets/white-tick.svg";
import styles from "./styles.module.scss";

Expand All @@ -19,38 +19,38 @@
currentStepIndex,
handleStepClick,
showCursor,
getStyles
getStyles,

Check warning on line 22 in src/node/node.tsx

View workflow job for this annotation

GitHub Actions / test-and-build (16.x)

'getStyles' is assigned a value but never used
nodeStyle
} = props;

const isCompleted = step.completed;
const isActive = index === currentStepIndex;

return (
<div
className={`${styles.eachNode}
${showCursor && styles.cursorPointer}
${index === currentStepIndex && styles.activeStepNode}
${!step.completed && currentStepIndex !== index && styles.inactiveStepNode}
${step.completed && currentStepIndex !== index && styles.completedStepNode}
${isActive && styles.activeStepNode}
${!isCompleted && !isActive && styles.inactiveStepNode}
${isCompleted && !isActive && styles.completedStepNode}
`}
style={{
...((getStyles(Elements.Node)) || {}),
...((index === currentStepIndex && getStyles(Elements.ActiveNode)) || {}),
...((step.completed && getStyles(Elements.CompletedNode)) || {}),
...((!step.completed && currentStepIndex !== index
&& getStyles(Elements.InActiveNode)) || {})
}}
style={nodeStyle}
onClick={(): void | null => handleStepClick && handleStepClick()}
role="presentation"
id="stepper-node"
>
{(renderNode && renderNode(step, index))
|| (
<>
{step?.completed && (
{isCompleted ? (
<img
src={whiteTick}
className={styles.whiteTickImg}
alt=""
/>)
|| index + 1}
/>
) : (
index + 1
)}
</>
)}
</div>
Expand Down
17 changes: 9 additions & 8 deletions src/node/types.d.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
import { ReactElement } from "react";
import { IStep } from "../stepper/types";
import { ReactElement, CSSProperties } from "react";
import { Elements } from "../constants";
import type { IStep } from "../stepper/types";

export type INodeProps = {
export interface INodeProps {
step: IStep;
renderNode?(step: IStep, index: number): ReactElement;
index: number;
currentStepIndex?: number;
handleStepClick(): void;
currentStepIndex: number;
handleStepClick?: () => void;
showCursor: boolean;
getStyles(element: Elements): object;
};
renderNode?: (step: IStep, stepIndex: number) => ReactElement;
getStyles: (element: Elements) => object;
nodeStyle?: CSSProperties;
}
64 changes: 27 additions & 37 deletions src/stepper/step.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React, { useRef, useEffect, useState } from "react";
import "./styles.scss";
import type { IStepProps } from "../stepper/types";
import type { IStepProps } from "./types";
import { LABEL_POSITION, ORIENTATION } from "../constants";
import StepContent from "./stepContent";
import StepInfo from "./stepInfo";
Expand All @@ -26,7 +26,9 @@ const Step: (props: IStepProps) => JSX.Element = ({
showDescriptionsForAllSteps = false,
stepContent,
onStepClick,
renderNode
renderNode,
completedNodeStyle,
currentNodeStyle
} = stepperProps;
const [nodeWidth, setNodeWidth] = useState(0);

Expand Down Expand Up @@ -68,51 +70,39 @@ const Step: (props: IStepProps) => JSX.Element = ({
currentStepIndex > index ? "activeConnector" : ""
} ${index === steps.length - 1 ? "hiddenConnector" : ""}`;

const stepInfoProps = {
orientation,
labelPosition,
isVertical,
isInlineLabelsAndSteps,
index,
currentStepIndex,
step,
showDescriptionsForAllSteps,
onStepClick,
renderNode,
styles,
nodeRef,
prevConnectorClassName,
nextConnectorClassName,
steps,
completedNodeStyle,
currentNodeStyle
};

return orientation !== ORIENTATION.VERTICAL &&
labelPosition === LABEL_POSITION.TOP ? (
<StepInfo
orientation={orientation}
labelPosition={labelPosition}
isVertical={isVertical}
isInlineLabelsAndSteps={isInlineLabelsAndSteps}
index={index}
currentStepIndex={currentStepIndex}
step={step}
showDescriptionsForAllSteps={showDescriptionsForAllSteps}
onStepClick={onStepClick}
renderNode={renderNode}
styles={styles}
nodeRef={nodeRef}
prevConnectorClassName={prevConnectorClassName}
nextConnectorClassName={nextConnectorClassName}
steps={steps}
/>
<StepInfo {...stepInfoProps} />
) : (
<div
className={
orientation === ORIENTATION.VERTICAL &&
labelPosition === LABEL_POSITION.LEFT
labelPosition === LABEL_POSITION.LEFT
? "verticalTextLeftContainer"
: ""
}
>
<StepInfo
orientation={orientation}
labelPosition={labelPosition}
isVertical={isVertical}
isInlineLabelsAndSteps={isInlineLabelsAndSteps}
index={index}
currentStepIndex={currentStepIndex}
step={step}
showDescriptionsForAllSteps={showDescriptionsForAllSteps}
onStepClick={onStepClick}
renderNode={renderNode}
styles={styles}
nodeRef={nodeRef}
prevConnectorClassName={prevConnectorClassName}
nextConnectorClassName={nextConnectorClassName}
steps={steps}
/>
<StepInfo {...stepInfoProps} />
<StepContent
labelPosition={labelPosition}
isVertical={isVertical}
Expand Down
Loading