Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

react-step-wizard

jcmcneal140.7kMIT5.3.11TypeScript support: included

A modern flexible step wizard component built for React

react, step, multistep, wizard, es6

readme

React Step Wizard

A flexible multistep wizard built for React

npm version

What You Can Build

Try It Out!

Click here to see a live example! See example source code: </>

Showcasing

If you've made something you're proud of with react-step-wizard and want to show it off to the world, send me a message with a link to your project and I'll add it to the README!

Install

npm install react-step-wizard

Import Component

import StepWizard from "react-step-wizard";

JSX Syntax

Simply create a wrapper with <StepWizard></StepWizard> and each child component will be treated as an individual step.

<StepWizard>
  <Step1 />
  <Step2 />
  ...
  <Step5 />
  <WhateverComponentName />
</StepWizard>

Props

I wanted this step wizard to be as flexible as possible so each child has access to the StepWizard functions via this.props

For example:

<div>
  <!-- Variables -->
  <h2>Step {this.props.currentStep}</h2>
  <p>Total Steps: {this.props.totalSteps}</p>
  <p>Is Active: {this.props.isActive}</p>
  <!-- Functions -->
  <p><button onClick={this.props.previousStep}>Previous Step</button></p>
  <p><button onClick={this.props.nextStep}>Next Step</button></p>
  <p><button onClick={()=>this.props.goToStep(2)}>Step 2</button></p>
  <p><button onClick={this.props.firstStep}>First Step</button></p>
  <p><button onClick={this.props.lastStep}>Last Step</button></p>
</div>

User-Defined Props

Prop Data Type Default Description
hashKey string step{n} Prop on child component to use when updating URL hash. Corresponds with isHashEnabled.
initialStep integer 1
instance function | Provides an instance of StepWizard to control from anywhere in your app
isHashEnabled bool false Persists the current step in the URL (hash)
isLazyMount boolean false Only mounts the child component when isActive is true
nav node | Create a custom navigation component to include in the wizard
onStepChange function | Callback for step change
transitions object | CSS classes for transitioning between steps

Props Accessible On Each Child (Step) Component

Prop Data Type Parameters
isActive boolean
currentStep integer
totalSteps integer
firstStep function
lastStep function
nextStep function
previousStep function
goToStep function integer : goToStep(3)
goToStep function string : goToStep('step3')
goToNamedStep function string : goToNamedStep('contact')

If you wish to include a navigation in your wizard you have the flexibility to create one however you want. All the props available to the steps will also be provided to your nav component.

Position: By default the nav will be added to the top. If you want it on the bottom I suggest adding a class to the StepWizard component with flex-direction: column-reverse. That's just one solution.

Be sure to pass your component in JSX syntax like this:

import CoolNav from "./CoolNav";

<StepWizard nav={<CoolNav />}>...</StepWizard>;

Transitions

The default transitions are using CSS taken from animate.css. You can override the transitions by passing in custom CSS classes to the transitions prop in <StepWizard>.

let custom = {
  enterRight: 'your custom css transition classes',
  enterLeft : 'your custom css transition classes',
  exitRight : 'your custom css transition classes',
  exitLeft  : 'your custom css transition classes',
  intro     : 'your custom css transition classes'
}
<StepWizard transitions={custom}>...</StepWizard>

Initial Step

The order of your steps in JSX will be loaded in the same order in the browser. However, you may specify which step to start on page load by using the initialStep prop. It accepts a numeric value corresponding to the step order.

<StepWizard initialStep={3}>...</StepWizard>

Persist Step In URL

An example of how isHashEnabled and hashKey work together:

<StepWizard isHashEnabled={true}>
  <BasicInfo hashKey={"basic"} /> // https://domain.com/#basic
  <ContactInfo hashKey={"contact"} /> // https://domain.com/#contact
  <TermsConditions /> // https://domain.com/#step3
</StepWizard>

As you can see, the hashKey corresponds with the url hash and will be updated when the step becomes active. The hashKey defaults to step{n}. If isHashEnabled is false then the url hash, or hashKey, will not be used.

When isHashEnabled is true, goToStep accepts a hashKey as an argument

Use named steps

If we don't need to use hash keys and just simply want to switch steps by their names we can use use stepName.

<StepWizard>
  <BasicInfo stepName={"basic"} />
  <ContactInfo stepName={"contact"} />
  <TermsConditions /> // step3
</StepWizard>

Now we can use goToNamedStep and set stepName as an argument

changelog

Changelog

All notable changes to this project will be documented in this file.

[5.3.11]

• Add missing transition type - intro - Thanks bundit

[5.3.10]

• Fallback to step1 when no hash is found. • Only show console.error message in non production environments.

Thanks sharpdressedcodes!

[5.3.8]

• Added support for named steps - Wojciech-Florczak

Dev Changes • Updated dev dependencies to address vulnerabilities

[5.3.7]

• Update Step TS - LucasCostaAtCyberSaint

[5.3.6]

• Support hash as argument to goToStep - GabrielFerrarini

[5.3.5]

• Fill for null children - resolritter

[5.3.4]

• Automate publishing to NPM • Support for TypeScript - Thanks resolritter!

[5.3.1]

• Support conditional steps

[5.3.0]

• Adds instance feature to control the step wizard from anywhere in your app! • Update to isReactComponent to support memo components • Support for className prop on StepWizard

[5.2.2]

• Fix for SSR - Thanks mathvaleriano! • Added CONTRIBUTING.md

[5.2.0]

• Fixed pointer events on inactive steps • Allow for non-react components as steps (remember they won't have access to props)

Dev Changes • Added more unit tests (86% coverage)

[5.1.0]

• Fixed exit transitions

[5.0.0]

• Switched build process to rollup - Now 2.36kb gzipped!

[4.4.0]

• Added navigation feature! 🎉

Dev Changes • Added Jest for unit/snapshot testing • Upgraded to Babel 7

[4.3.1]

• Updated component to change step onhashchange when using browser back/forward buttons - (applicable only when isHashEnabled is true)

[4.3.0]

• Added hashKey for persisting step in URL • Removed active prop for child components - use initialStep instead

[4.2.0]

• Added onStepChange callback for when step changes

[4.1.2]

• Fix for IE support

[4.1.1]

Dev Changes • Added PropTypes for development

[4.1.0]

• Added isLazyMount prop for dynamically mounting steps

Dev Changes • Added webpack-dev-server to example for convenience

[4.0.0] *Breaking Changes*

• Removed Step component. It wasn't necessary • Made StepWizard the default export

Dev Changes • Updated eslint rules

[3.0.1]

Dev Changes • clean up dev dependencies • Update to example demo

[3.0.0] *Potentially Breaking Changes*

• Added isActive prop and initialStep • Remove example/ from npm

Dev Changes • Updated webpack configs • Added airbnb eslint rules. • Updated components for eslint and es6 standards

[2.0.0]

• Use style-loader to handle CSS