Skip to content

Commit 3bda0ad

Browse files
committed
integrated basic logic for stepper
1 parent cefabd8 commit 3bda0ad

7 files changed

Lines changed: 66 additions & 32 deletions

File tree

global.d.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
declare module '*.scss' {
2-
const content: {[className: string]: string};
3-
export = content;
1+
declare module "*.svg" {
2+
const content: string;
3+
export default content;
44
}

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
"engines": {
2020
"node": ">=10"
2121
},
22+
"appRoot": "src",
2223
"repository": {
2324
"type": "github",
2425
"url": "https://github.com/aarathyKeyvalue/vertical-stepper"

src/assets/white-tick.svg

Lines changed: 3 additions & 0 deletions
Loading

src/stepper-component/stepperComponent.tsx

Lines changed: 32 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,43 @@
1+
/* eslint-disable @typescript-eslint/no-var-requires */
12
import React, { useState, useEffect } from 'react';
23
import './styles.css';
3-
import { stepTypes } from './types';
4+
import { Istep, IstepperProps } from './types';
5+
import whiteTick from '../assets/white-tick.svg';
46

5-
const Stepper = (props: { steps: stepTypes[]}): any => {
6-
const { steps } = props;
7+
const Stepper = (props: IstepperProps): any => {
8+
const { steps, currentActiveStepIndex } = props;
79

8-
const [stepVal, setSteps] = useState([]);
10+
// const whiteTick = require('../assets/white-tick.svg') as string;
11+
const [stepsVal, setSteps] = useState<Istep[]>([]);
12+
const [currentActiveStepIndexVal, setCurrentActiveStepIndexVal] = useState<number>()
913

10-
useEffect(() => {
14+
useEffect(() => {
1115
setSteps(steps);
1216
}, [steps]);
17+
18+
useEffect(() => {
19+
setCurrentActiveStepIndexVal(currentActiveStepIndex ?? 0);
20+
}, [currentActiveStepIndex]);
21+
1322
return (
1423
<div className="stepperContainer">
15-
{stepVal?.map((step, index) => (index < stepVal?.length - 1) && (
24+
{stepsVal?.map((step: Istep, index: number) => (
1625
<div key={index} className="eachStep">
1726
<div className='bubbleLineWrapper'>
18-
<div className='eachBubble'>{index + 1}</div>
27+
<div
28+
className={`eachBubble
29+
${index === currentActiveStepIndexVal && 'activeStepBubble'}
30+
${index > currentActiveStepIndexVal && 'inactiveStepBubble'}`}
31+
>
32+
{currentActiveStepIndexVal > index && (
33+
<img
34+
src={whiteTick}
35+
className="whiteTickImg"
36+
alt=""
37+
/>
38+
)
39+
|| index + 1}
40+
</div>
1941
<div className='eachLabel'>
2042
{step.label && (
2143
<span className='labelTitle'>
@@ -28,29 +50,12 @@ const Stepper = (props: { steps: stepTypes[]}): any => {
2850
</span>
2951
)}
3052
</div>
31-
<div className='lineSeparator' />
32-
</div>
33-
</div>
34-
))}
35-
<div className="eachStep">
36-
<div className='bubbleLineWrapper'>
37-
<div className='eachBubble'>
38-
{stepVal?.length}
39-
</div>
40-
<div className='eachLabel'>
41-
{stepVal[stepVal?.length - 1]?.label && (
42-
<span className='labelTitle'>
43-
{stepVal[stepVal?.length - 1]?.label}
44-
</span>
45-
)}
46-
{stepVal[stepVal?.length - 1]?.description && (
47-
<span className='labelDescription'>
48-
{stepVal[stepVal?.length - 1]?.description}
49-
</span>
53+
{index < stepsVal?.length - 1 && (
54+
<div className={`lineSeparator ${(index > currentActiveStepIndexVal - 1) && 'activeStepLineSeparator'}`} />
5055
)}
5156
</div>
5257
</div>
53-
</div>
58+
))}
5459
</div>
5560
);
5661
};

src/stepper-component/styles.css

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,21 @@
2020
align-items: center;
2121
justify-content: center;
2222
overflow: visible;
23+
font-weight: 400;
24+
font-size: 12px;
25+
line-height: 16px;
26+
border: 7px solid;
27+
}
28+
.activeStepBubble {
29+
border: 7px solid #CBCBEF
30+
}
31+
.inactiveStepBubble {
32+
opacity: 0.4;
33+
}
34+
.whiteTickImg {
35+
object-fit: cover;
36+
width: 10px;
37+
height: 8px;
2338
}
2439

2540
.eachStep {
@@ -59,3 +74,6 @@
5974
border-right: 2px solid #dfdff2;
6075
margin: 4px 0;
6176
}
77+
.activeStepLineSeparator {
78+
border-right: 2px dashed #dfdff2;
79+
}

src/stepper-component/types.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1-
export interface stepTypes {
2-
label: string
1+
export interface Istep {
2+
label: string,
3+
description?: string
4+
}
5+
6+
export interface IstepperProps {
7+
steps: Istep[],
8+
currentActiveStepIndex: number
39
}

src/stories/StepperComponent.stories.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,4 +32,5 @@ LoggedIn.args = {
3232
label: 'Step 4',
3333
description: 'The quick brown fox jumps over the lazy dog'
3434
}],
35+
currentActiveStepIndex: 2
3536
};

0 commit comments

Comments
 (0)