Skip to content

Commit 9cfd3d4

Browse files
committed
Readme
1 parent ee4f209 commit 9cfd3d4

1 file changed

Lines changed: 35 additions & 57 deletions

File tree

README.md

Lines changed: 35 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,8 @@ _Unopinionated multi step interface builder._
44

55
## Overview
66

7-
React Step Builder allows you to combine states of multiple _step_ components in a single main state and navigate between components without losing the local states of the _steps_.
7+
React Step Builder allows you to combine states of multiple components in a single main state and navigate between components without losing the local states of individual step components.
88

9-
<br />
109
<br />
1110

1211
## Installation
@@ -16,7 +15,6 @@ Using [npm](https://www.npmjs.com/):
1615
$ npm install --save react-step-builder
1716

1817
<br />
19-
<br />
2018

2119
## Usage
2220

@@ -28,18 +26,16 @@ Using [npm](https://www.npmjs.com/):
2826
</Steps>
2927
```
3028

31-
<br />
3229
<br />
3330

3431
### `<Steps />`
3532

3633
This is the wrapper component. You must define every step component under `<Steps />` component. It takes `total` as a prop which must match the number of `Step` components inside.
3734

38-
| Properties | |
39-
| --------------------- | ------------------------------------------- |
40-
| **`total`** _integer_ | Define how many steps you will be creating. |
35+
#### `<Steps />` Properties
36+
37+
| `total` _integer_ - is the number of steps you want to create.
4138

42-
<br />
4339
<br />
4440

4541
### `<Step />`
@@ -52,92 +48,71 @@ This is the component you create for each `step` in your application. It takes `
5248
<Step persist component={PersistentComponent} />
5349
```
5450

55-
| Properties | |
56-
| --------------------- | ---------------------------------------------------------------------------------------------- |
57-
| **`order`** _integer_ | Defines the order of the Step component. Order numbers must start with `1` and be consecutive. |
51+
#### `<Step />` Properties
52+
53+
- `order` _integer_ - defines the order of the `Step`. Order numbers must start with `1` and be consecutive.
5854

59-
<br />
6055
<br />
6156

6257
## Composing Step Components
6358

64-
There are some props available to your components that you render in `Step` component.
59+
Following `props` available to your step components.
6560

6661
### `mainState` _(object)_
6762

68-
It gives you all the state pieces combined from your `Step` components. As your user move forward in steps, the forms they fill before all accumulate under this value. You can refer in any step component as `props.mainState`.
63+
It gives you all the state pieces combined from your `Step` components. As your user move forward in steps, the forms they fill before all accumulate under this value.
6964

7065
### `setMainState` _(function)_
7166

72-
_(Not recommended to be used by default)_ By this function, you can manipulate your `mainState` in any of your state components. You may consider using it if the data you would like to save in your `mainState` object is not coming from a form element (technically, if the data is coming from a source without a synthetic event.) You can refer in any step component as `props.setMainState`.
67+
_(Not recommended to be used by default)_ By this function, you can manipulate your `mainState` in any of your state components. You may consider using it if the data you would like to save in your `mainState` object is not coming from a form element (technically, if the data is coming from a source without a synthetic event.)
7368

7469
### `handleChange(event)` _(function)_
7570

76-
You may pass this function to any onChange event on any form element. One thing to always remember: Your form element must have name property, which eventually becomes its key in the `mainState` object. If your form element has `name="username"` then its value must be `{props.mainState.username}`.
77-
78-
In order to get rid of `uncontrolled/controlled component` error, simply put your value like this: `value={props.mainState.<inputName> || ''}`. Another way is, creating the `step` with `persist` keyword before ordered `step` components and define all your form value names inside that persistent step component's useEffect hook. Like this:
79-
80-
```js
81-
export const PersistentStep = props => {
82-
useEffect(() => {
83-
props.setMainState({
84-
name: props.mainState.name || "", //For Step 1
85-
age: props.mainState.age || "", // For Step 2
86-
email: props.mainState.email || "" // For Step 3
87-
});
88-
}, []);
89-
90-
return (
91-
//Your component design
92-
);
93-
};
94-
```
71+
You may pass this function to any onChange event on any form element. One thing to always remember: Your form element must have name property, which eventually becomes its key in the `mainState` object. If your form element has `name="username"` then its value would be `{props.mainState.username}`.
9572

9673
### `steps` _(object)_
9774

98-
This object has two values: `total` and `current`. You can refer as `props.steps.total` and `props.steps.current`. If you would like to build a navigation bar, previous/next buttons, % X completed bar etc. refer to this object.
75+
- `total` - Number of total steps.
76+
- `current` - Current step that user is on.
9977

10078
### `prevStep` _(function)_
10179

102-
This function moves to the previous step. Refer as `props.prevStep()`
80+
This function moves to the previous step.
10381

10482
### `nextStep` _(function)_
10583

106-
This function moves to the next step. Refer as `props.nextStep()`
84+
This function moves to the next step.
10785

10886
### `jumpToStep(step)` _(function)_
10987

110-
This function moves to the specified step. Refer as `props.jumpToStep(stepNumber)`
88+
This function moves to the specified step.
11189

112-
<br />
11390
<br />
11491

11592
## UI Components
11693

117-
React Step Builder is principally designed to minimally interfere with UI. However, creating the most basic next and previous buttons and navigation between steps might be time consuming for those who do not expect much from the design. Here are some components that comes in the box so that you can directly use in any **Step** component.
94+
React Step Builder is principally designed to minimally interfere with UI. However, creating the most basic next and previous buttons and navigation between steps might be time consuming for those who do not expect much from the design. Here are some components that comes in the box so that you can directly use in any **`Step`** component.
11895

119-
<br />
12096
<br />
12197

12298
### `<Button />`
12399

124100
It renders a button with either prev or next functionality.
125101

126-
Example usages:
102+
Example usage:
127103

128104
```js
129105
<Button next text="Next Step">
130106
<Button prev text="Previous Step">
131107
```
132108

133-
| Properties | --- |
134-
| -------------------- | ----------------------------------------------------------------------------------------------------- |
135-
| **`text`** _String_ | the text that will button render |
136-
| **`prev`** _Boolean_ | gives the button 'Go to Previous Step' functionality. Disabled in the first step. |
137-
| **`next`** _Boolean_ | gives the button 'Go to Next Step' functionality. Disabled in the last step. |
138-
| _any props_ | all the other props passed to the **Button** component will be passed any props to the button element |
109+
#### `<Button />` Properties
110+
111+
- `text` _String_ - is the text that will button render.
112+
- `prev` _Boolean_ - gives the button 'Go to Previous Step' functionality. Disabled in the first step.
113+
- `next` _Boolean_ - gives the button 'Go to Next Step' functionality. Disabled in the last step.
114+
- _any props_ - passed to the **Button** component will be passed to the button element on the DOM.
139115

140-
<br />
141116
<br />
142117

143118
### `<Navigation />`
@@ -147,13 +122,16 @@ It renders a button for each step with the default text of Step number. The butt
147122
Example usages:
148123

149124
```js
150-
<Navigation /> // if you have 3 steps, it renders 3 buttons, each has the text of [1, 2, 3] consecutively
151-
<Navigation text="*" /> // if you have 3 steps, it renders 3 buttons, each has the text of * (asterix)
152-
<Navigation before="HEY " after=" HI" /> // if you have 3 steps, it renders 3 buttons, each step number has 'HEY' before and 'HI' after (HEY 1 HI, HEY 2 HI, HEY 3 HI)
125+
<Navigation /> // if you have 3 steps, it renders 3 buttons, each of which has the text of [1, 2, 3] consecutively
126+
<Navigation text="*" /> // if you have 3 steps, it renders 3 buttons, each of which has the text of * (asterix)
127+
<Navigation before="HEY " after=" HI" /> // if you have 3 steps, it renders 3 buttons, each of which has 'HEY' before and 'HI' after the step number (HEY 1 HI, HEY 2 HI, HEY 3 HI)
128+
<Navigation active="active-class-name" visited="visited-class-name" />
153129
```
154130

155-
| Properties | --- |
156-
| --------------------- | ------------------------------------------------------------------------- |
157-
| **`text`** _String_ | the text that each button will show, disables `before` and `after` props. |
158-
| **`before`** _String_ | the text that goes before the step number in the button. |
159-
| **`after`** _String_ | the text that goes after the step number in the button. |
131+
#### `<Navigation />` Properties
132+
133+
- `text` _String_ - is the text that each button will show, disables `before` and `after` props.
134+
- `before` _String_ - is the text that goes before the step number in the button.
135+
- `after` _String_ - is the text that goes after the step number in the button.
136+
- `active` _String_ - passes a class name to the navigation button element of the current step.
137+
- `visited` _String_ - passes a class name to the navigation button element of the steps that comes before the current step.

0 commit comments

Comments
 (0)