1
1
2
2
# 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 >
3
4
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 >
6
8
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 >
8
11
9
12
## Installation
10
13
11
- ```
14
+ ``` bash
12
15
npm install react-vertical-stepper
13
16
```
14
17
@@ -17,67 +20,56 @@ You’ll need to install React separately since it isn't included in the package
17
20
## Usage
18
21
19
22
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' ;
21
26
import Stepper from ' react-vertical-stepper' ;
22
27
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 ;
27
54
```
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
29
56
30
57
- ` label ` - a string that can be shown as step label title to your step indicator
31
58
- ` description ` - a string that can be show as step description below the step label
32
59
- ` status ` - can be provided with any of ` visited ` , ` unvisited ` , ` completed ` . Will be required if you are using default styles.
33
60
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
37
62
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
64
64
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
73
66
< Stepper
74
67
steps= {stepsArray}
75
68
currentStepIndex= {currentStepIndex}
76
69
renderBubble= {(step , stepIndex ) => (< div key= {stepIndex}> {step .label }< / div> )}
77
70
/ >
78
71
```
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.
81
73
82
74
## Props
83
75
@@ -94,17 +86,13 @@ Props that can be passed to the component are listed below:
94
86
<tbody >
95
87
<tr>
96
88
<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>
100
90
<td><code>undefined</code></td>
101
91
</tr>
102
92
<tr>
103
93
<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>
108
96
</tr>
109
97
<tr>
110
98
<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:
139
127
140
128
## Style Customizations
141
129
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
143
131
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
- ```
161
132
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
+
162
162
- ` LabelTitle ` - overrides the step label style
163
163
- ` ActiveLabelTitle ` - overrides the step label style of current active step
164
164
- ` LabelDescription ` - overrides the step description style
0 commit comments