3.0.6 ā€¢ Published 2 years ago

react-step-builder v3.0.6

Weekly downloads
1,003
License
-
Repository
github
Last release
2 years ago

React Step Builder npm (tag) Total NPM Download

React Step Builder is a headless, unopinionated, multi-step interface builder.

Version 3 introduces some breaking changes. If you are upgrading from earlier versions, please read the documentation carefully.

Global state management methods are removed from the library. React Step Builder will only focus on building step-by-step interfaces starting from version 3. You may use a state management tool of your choice. If this is bad news for you, I am sorry šŸ™‡ā€ā™‚ļø

Installation

Using npm:

npm install react-step-builder

Usage

Example:

import { Steps, StepsProvider, useSteps } from "react-step-builder";

const App = () => {
  return (
    <StepsProvider>
      <MySteps />
    </StepsProvider>
  );
};

const MySteps = () => {
  const { next, prev } = useSteps();

  return (
    <Steps>
      <div>
        <h1>Step 1</h1>
      </div>
      <div>
        <h1>Step 2</h1>
      </div>
      <div>
        <h1>Step 3</h1>
      </div>
    </Steps>
  );
};

export default App;

Documentation

<Steps />

A component whose each direct sibling is treated as a step. Do not add anything else inside Steps component as they will be treated as a separate step.

āŒ Incorrect:

<Steps>
  <Step1 />
  <Step2 />
  <NotAStep />
</Steps>

āœ… Correct:

<Steps>
  <Step1 />
  <Step2>
    <NotAStep />
  </Step2>
</Steps>

This reason for this method is due to React's composition over inheritance principle. It also allows you to manage your state easily in the parent component.

PropertyTypeDescription
onStepChange() => voidRuns on every step change. Does not run on initial render.

useSteps

A special hook that accesses the state of <Steps /> component and exposes methods to move between steps.

const stepsState = useSteps();

These are the properties inside stepsState object.

PropertyTypeDescription
totalnumberTotal number of steps
currentnumberCurrent step number
progressnumberProgress of the current step, value between 0 and 1
next() => voidFunction to move to the next step
prev() => voidFunction to move to the previous step
jump(step: number) => voidFunction to jump to the given step
isFirstbooleanIf the step is the first
isLastbooleanIf the step is the last
hasPrevbooleanIf the step has any previous step
hasNextbooleanIf the step has any next step

<StepsProvider />

The component that renders <Steps /> should be wrapped with StepsProvider component. useSteps can only be called in a component that is rendered in the DOM tree under StepsProvider.

PropertyTypeDescription
startsFromnumberThe default step number to be rendered.

Step numbers start from 1 and goes up to the count of direct siblings given to the Steps component. If the number is out of range, first step is rendered by default.

3.0.4

2 years ago

3.0.6

2 years ago

3.0.5

2 years ago

3.0.3

2 years ago

3.0.2

2 years ago

3.0.1

2 years ago

3.0.0

2 years ago

2.0.11

3 years ago

2.0.10

3 years ago

2.0.9

3 years ago

2.0.8

3 years ago

2.0.7

3 years ago

2.0.6

3 years ago

2.0.5

3 years ago

2.0.4

3 years ago

2.0.3

3 years ago

2.0.2

4 years ago

2.0.1

4 years ago

2.0.0

4 years ago

1.1.15

4 years ago

1.1.14

4 years ago

1.1.13

4 years ago

1.1.12

4 years ago

1.1.11

4 years ago

1.1.10

4 years ago

1.1.9

4 years ago

1.1.8

4 years ago

1.1.7

4 years ago

1.1.6

4 years ago

1.1.5

4 years ago

1.1.4

4 years ago

1.1.1

4 years ago

1.1.3

4 years ago

1.1.2

4 years ago

1.1.0

4 years ago

1.0.34

4 years ago

1.0.33

4 years ago

1.0.32

4 years ago

1.0.31

4 years ago

1.0.30

4 years ago

1.0.29

4 years ago

1.0.28

4 years ago

1.0.27

4 years ago

1.0.26

4 years ago

1.0.25

4 years ago

1.0.24

4 years ago

1.0.23

4 years ago

1.0.22

4 years ago

1.0.21

4 years ago

1.0.20

4 years ago

1.0.19

4 years ago

1.0.18

4 years ago

1.0.17

4 years ago

1.0.16

4 years ago

1.0.15

4 years ago

1.0.14

4 years ago

1.0.13

4 years ago

1.0.12

4 years ago

1.0.11

4 years ago

1.0.10

4 years ago

1.0.8

4 years ago

1.0.7

4 years ago

1.0.6

4 years ago

1.0.5

4 years ago

1.0.4

4 years ago

1.0.3

4 years ago

1.0.2

4 years ago

1.0.1

4 years ago

1.0.0

4 years ago