Skip to content

Commit 0792592

Browse files
authored
Merge pull request #5 from KeyValueSoftwareSystems/dev
Read me file updation and Label render logic change
2 parents 0cdf767 + 6777621 commit 0792592

File tree

8 files changed

+153
-151
lines changed

8 files changed

+153
-151
lines changed

.github/workflows/test-and-build.yml

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,7 @@
11
name: Test Suite
22

33
on:
4-
push:
5-
branches: [main]
64
pull_request:
7-
# The branches below must be a subset of the branches above
85
branches: [main]
96

107
jobs:
@@ -17,20 +14,20 @@ jobs:
1714
- name: Checkout code
1815
uses: actions/checkout@v2
1916
with:
20-
ref: ${{ if github.event_name == 'pull_request' }}${{ github.event.pull_request.head.sha }}${{ else }}${{ github.ref }}${{ endif }}
17+
ref: ${{ github.event.pull_request.head.sha }}
2118
fetch-depth: 0
2219

2320
- name: Use Node.js ${{ matrix.node-version }}
2421
uses: actions/setup-node@v2
2522
with:
2623
node-version: ${{ matrix.node-version }}
2724

28-
- name: Linting
29-
run: npm run eslint
30-
3125
- name: Install dependencies
3226
run: npm install
3327

28+
- name: Linting
29+
run: npm run eslint
30+
3431
- name: Run tests
3532
run: npm run test
3633

README.md

Lines changed: 74 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,17 @@
11

22
# React Vertical Stepper
3+
<a href="https://www.npmjs.com/package/react-vertical-stepper"><img src="https://badgen.net/npm/v/react-vertical-stepper?color=blue" alt="npm version"></a> <a href="https://www.npmjs.com/package/react-vertical-stepper" ><img src="https://img.shields.io/npm/dw/react-vertical-stepper?label=Downloads" /></a> <a href="https://github.com/KeyValueSoftwareSystems/react-vertical-stepper"><img src="https://github.com/KeyValueSoftwareSystems/react-vertical-stepper/actions/workflows/update-and-publish.yml/badge.svg" alt="" /></a>
34

4-
<!--
5-
<a href="https://www.npmjs.com/package/@hodgef/ts-library-boilerplate-basic"><img src="https://badgen.net/npm/v/@hodgef/ts-library-boilerplate-basic?color=blue" alt="npm version"></a> <a href="https://github.com/hodgef/ts-library-boilerplate"><img src="https://img.shields.io/github/last-commit/hodgef/ts-library-boilerplate" alt="latest commit"></a> <a href="https://github.com/hodgef/ts-library-boilerplate-basic/actions"><img alt="Build Status" src="https://github.com/hodgef/ts-library-boilerplate-basic/workflows/Build/badge.svg?color=green" /></a> <a href="https://github.com/hodgef/ts-library-boilerplate-basic/actions"> <img alt="Publish Status" src="https://github.com/hodgef/ts-library-boilerplate-basic/workflows/Publish/badge.svg?color=green" /></a> -->
5+
<div align="center">
6+
<img src="./src/assets/vertical-stepper-example.png" alt="" width="269" height="416"/>
7+
</div>
68

7-
>A fully customizable ready to use vertical stepper UI package.
9+
A fully customizable ready to use vertical stepper UI package for React.
10+
Try tweaking a vertical stepper using this codesandbox link <a href="https://codesandbox.io/s/vertical-stepper-demo-x24q7u" >here</a>
811

912
## Installation
1013

11-
```
14+
```bash
1215
npm install react-vertical-stepper
1316
```
1417

@@ -17,67 +20,56 @@ You’ll need to install React separately since it isn't included in the package
1720
## Usage
1821

1922
React Vertical Stepper can run in a very basic mode by just providing the `steps` and `currentStepIndex` props like this:
20-
```
23+
24+
```jsx
25+
import React, { useState } from 'react';
2126
import Stepper from 'react-vertical-stepper';
2227

23-
<Stepper
24-
steps={stepsArray}
25-
currentStepIndex={currentStepIndex}
26-
/>
28+
function App() {
29+
const [currentStepIndex, setCurrentStepIndex] = useState(0);
30+
31+
stepsArray = [{
32+
label: 'Step 1',
33+
description: 'This is Step 1',
34+
status: 'completed'
35+
},{
36+
label: 'Step 2',
37+
description: 'This is Step 2',
38+
status: 'visited'
39+
},{
40+
label: 'Step 3',
41+
description: 'This is Step 3',
42+
status: 'unvisited'
43+
}];
44+
45+
return (
46+
<Stepper
47+
steps={stepsArray}
48+
currentStepIndex={currentStepIndex}
49+
/>
50+
);
51+
}
52+
53+
export default App;
2754
```
28-
Here the steps array is an array of objects with basic keys like
55+
The `steps` array is an array of objects with basic keys like
2956

3057
- `label` - a string that can be shown as step label title to your step indicator
3158
- `description` - a string that can be show as step description below the step label
3259
- `status` - can be provided with any of `visited`, `unvisited`, `completed`. Will be required if you are using default styles.
3360

34-
> You can also add other keys to the step object and other statuses like `skipped` for different customizations as per requirements
35-
36-
An example for steps array is shown below:
61+
>Note: You can also add any other keys to the step object and other statuses like `skipped` for different customizations as per requirements
3762
38-
```
39-
stepsArray = [
40-
{
41-
label: 'Step 1',
42-
description: 'This is Step 1',
43-
status: 'visited'
44-
},
45-
{
46-
label: 'Step 2',
47-
description: 'This is Step 2',
48-
status: 'unvisited'
49-
},
50-
{
51-
label: 'Step 3',
52-
description: 'This is Step 3',
53-
status: 'completed'
54-
}
55-
];
56-
```
57-
You can use `onStepClick` event handler which fires each time you click on a step or its label or description
58-
```
59-
const [activeStepIndex, setActiveStepIndex] = useState(0);
60-
61-
const handleStepClick = (step, stepIndex) => {
62-
setActiveStepIndex(stepIndex);
63-
};
63+
You can customize the step indicator bubble with your own DOM element using the `renderBubble` prop
6464

65-
<Stepper
66-
steps={stepsArray}
67-
currentStepIndex={activeStepIndex}
68-
onStepClick={handleStepClick}
69-
/>
70-
```
71-
You can also customize the step indicator bubble with your own DOM element using the `renderBubble` prop
72-
```
65+
```jsx
7366
<Stepper
7467
steps={stepsArray}
7568
currentStepIndex={currentStepIndex}
7669
renderBubble={(step, stepIndex) => (<div key={stepIndex}>{step.label}</div>)}
7770
/>
7871
```
79-
80-
>Note: The `step` param provided by the `renderBubble` callback is the same object you pass as array item in `steps` prop.
72+
The `step` param provided by the `renderBubble` callback is the same object you pass as array item in `steps` prop.
8173

8274
## Props
8375

@@ -94,17 +86,13 @@ Props that can be passed to the component are listed below:
9486
<tbody>
9587
<tr>
9688
<td><code><b>steps:</b> object[]</code></td>
97-
<td>
98-
An array of step objects to render.
99-
</td>
89+
<td>An array of step objects to render.</td>
10090
<td><code>undefined</code></td>
10191
</tr>
10292
<tr>
10393
<td><code><b>currentIndex:</b> number</code></td>
104-
<td>
105-
The index of current active step.
106-
</td>
107-
<td>0</td>
94+
<td>The index of current active step.</td>
95+
<td><code>0</code></td>
10896
</tr>
10997
<tr>
11098
<td><code><b>onStepClick?:</b> (step: object, stepIndex: number): void</code></td>
@@ -139,26 +127,38 @@ Props that can be passed to the component are listed below:
139127

140128
## Style Customizations
141129

142-
All the default styles provided by this package are overridable using the `style` prop.
130+
All the default styles provided by this package are overridable using the `style` prop
143131
the below code shows all the overridable styles:
144-
```
145-
<Stepper
146-
steps={stepsArray}
147-
currentStepIndex={currentStepIndex}
148-
styles={{
149-
LabelTitle: (step, stepIndex) => ({...styles}),
150-
ActiveLabelTitle: (step, stepIndex) => ({...styles}),
151-
LabelDescription: (step, stepIndex) => ({...styles}),
152-
ActiveLabelDescription: (step, stepIndex) => ({...styles}),
153-
LineSeparator: (step, stepIndex) => ({...styles}),
154-
InactiveLineSeparator: (step, stepIndex) => ({...styles}),
155-
Bubble: (step, stepIndex) => ({...styles}),
156-
ActiveBubble: (step, stepIndex) => ({...styles}),
157-
InActiveBubble: (step, stepIndex) => ({...styles}),
158-
}}
159-
/>
160-
```
161132

133+
```jsx
134+
import React from 'react';
135+
import Stepper from 'react-vertical-stepper';
136+
137+
function App() {
138+
139+
const stylesOverrride = {
140+
LabelTitle: (step, stepIndex) => ({...styles}),
141+
ActiveLabelTitle: (step, stepIndex) => ({...styles}),
142+
LabelDescription: (step, stepIndex) => ({...styles}),
143+
ActiveLabelDescription: (step, stepIndex) => ({...styles}),
144+
LineSeparator: (step, stepIndex) => ({...styles}),
145+
InactiveLineSeparator: (step, stepIndex) => ({...styles}),
146+
Bubble: (step, stepIndex) => ({...styles}),
147+
ActiveBubble: (step, stepIndex) => ({...styles}),
148+
InActiveBubble: (step, stepIndex) => ({...styles}),
149+
};
150+
return (
151+
<Stepper
152+
steps={stepsArray}
153+
currentStepIndex={currentStepIndex}
154+
styles={stylesOverrride}
155+
/>
156+
);
157+
}
158+
159+
export default App;
160+
```
161+
162162
- `LabelTitle` - overrides the step label style
163163
- `ActiveLabelTitle` - overrides the step label style of current active step
164164
- `LabelDescription` - overrides the step description style
17.1 KB
Loading

src/bubble/bubble.tsx

Lines changed: 38 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import React, { FC } from "react";
22
import type { IBubbleProps } from "./types";
33
import { Elements } from "../constants";
44
import whiteTick from '../assets/white-tick.svg';
5-
import { STEP_STATUSES } from '../constants';
5+
import { STEP_STATUSES, LABEL_POSITION } from '../constants';
66
import styles from './styles.module.scss';
77

88
const Bubble: FC<IBubbleProps> = (props) => {
@@ -13,7 +13,8 @@ const Bubble: FC<IBubbleProps> = (props) => {
1313
currentStepIndex,
1414
handleStepClick = null,
1515
showCursor,
16-
getStyles
16+
getStyles,
17+
labelPosition
1718
} = props;
1819

1920
return (
@@ -45,6 +46,41 @@ const Bubble: FC<IBubbleProps> = (props) => {
4546
|| index + 1}
4647
</>
4748
)}
49+
<div className={`${styles.labelContainer} ${styles[`labelContainer__${labelPosition || LABEL_POSITION.RIGHT}`]}`}>
50+
{step?.label && (
51+
<span
52+
className={`${styles.labelTitle}
53+
${showCursor && styles.cursorPointer}
54+
${index === currentStepIndex && styles.activeLabelTitle}`}
55+
style={{
56+
...((getStyles(Elements.LabelTitle)) || {}),
57+
...((index === currentStepIndex && getStyles(Elements.ActiveLabelTitle)) || {})
58+
}}
59+
onClick={(): void | null => handleStepClick && handleStepClick()}
60+
role="presentation"
61+
id={`stepper-label-${index}`}
62+
>
63+
{step.label}
64+
</span>
65+
)}
66+
{step?.description && (
67+
<span
68+
className={`${styles.labelDescription}
69+
${handleStepClick && styles.cursorPointer}
70+
${index === currentStepIndex && styles.activeLabelDescription}`}
71+
style={{
72+
...((getStyles(Elements.LabelDescription)) || {}),
73+
...((index === currentStepIndex &&
74+
getStyles(Elements.ActiveLabelDescription)) || {})
75+
}}
76+
onClick={(): void | null => handleStepClick && handleStepClick()}
77+
role="presentation"
78+
id={`stepper-desc-${index}`}
79+
>
80+
{step.description}
81+
</span>
82+
)}
83+
</div>
4884
</div>
4985
);
5086
};

src/bubble/styles.module.scss

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,12 @@
1111
font-weight: 400;
1212
font-size: 12px;
1313
line-height: 16px;
14-
border: 7px solid;
14+
margin: 7px;
15+
position: relative;
1516
}
1617
.activeStepBubble {
1718
border: 7px solid #CBCBEF;
19+
margin: 0;
1820
}
1921
.inactiveStepBubble {
2022
opacity: 0.4;
@@ -26,4 +28,35 @@
2628
}
2729
.cursorPointer {
2830
cursor: pointer;
31+
}
32+
33+
.labelContainer {
34+
position: absolute;
35+
width: max-content;
36+
height: 100%;
37+
display: flex;
38+
flex-direction: column;
39+
justify-content: center;
40+
&__right {
41+
left: 44px;
42+
}
43+
&__left {
44+
right: 44px;
45+
align-items: end;
46+
}
47+
.labelTitle {
48+
color: #4F4F4F;
49+
}
50+
.activeLabelTitle {
51+
font-weight: 700;
52+
}
53+
.labelDescription {
54+
font-weight: 400;
55+
font-size: 12px;
56+
line-height: 21px;
57+
color: #929292;
58+
}
59+
.activeLabelDescription {
60+
color: #676767;
61+
}
2962
}

src/bubble/types.d.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,6 @@ export type IBubbleProps = {
99
currentStepIndex?: number,
1010
handleStepClick(): void,
1111
showCursor: boolean,
12-
getStyles(element: Elements): object
12+
getStyles(element: Elements): object,
13+
labelPosition: 'left' | 'right'
1314
}

0 commit comments

Comments
 (0)