Skip to content
A flexible wizard component for react and react-native
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
.vscode
__tests__
demo2
examples/src
src
.all-contributorsrc
.babelrc
.gitignore
.npmignore
.travis.yml
CONTRIBUTING.md
LICENSE
README.md
package-lock.json
package.json
tsconfig.json
webpack.config.js

README.md

@rahsheen/react-wizard

Build Status npm (scoped) Coverage Status semantic-release All Contributors

React Wizard is a flexible wizard / multi-step form component which can be used with React or React-Native.

Making use of render props (and hooks internally), React Wizard allows you to control exactly how each step is rendered. The ultimate goal will be to not only provide the tools to build a custom wizard, but also provide simpler API's for more specific use-cases.

Examples

Basic Usage

<Wizard>
  <Wizard.Step>
    {({ nextStep, prevStep, currentIndex }) => {
      return (
        <div>
          <h2>Step {currentIndex}</h2>
          <button onClick={prevStep}>Back</button>
          <button onClick={nextStep}>Next</button>
        </div>
      )
    }}
  </Wizard.Step>
  <div>
    <Wizard.Step>
      {({ nextStep, prevStep, currentIndex, onChangeValue }) => (
        <div>
          <h2>Enter Your Username</h2>
          <p>Step {currentIndex}</p>
          <input
            type="text"
            onChange={e => onChangeValue("username", e.target.value)}
          />
          <button onClick={prevStep}>Back</button>
          <button onClick={nextStep}>Next</button>
        </div>
      )}
    </Wizard.Step>
  </div>
  <Wizard.Step disabled>
    {" "}
    // This step will not be rendered
    {({ nextStep, prevStep, currentIndex }) => (
      <div>
        <h2>Step {currentIndex}</h2>
        <button onClick={prevStep}>Back</button>
        <button onClick={nextStep}>Next</button>
      </div>
    )}
  </Wizard.Step>
  <Wizard.Step>
    {({ nextStep, prevStep, currentIndex, onSubmit }) => (
      <div>
        <h2>Baz {currentIndex}</h2>
        <button onClick={prevStep}>Back</button>
        <button onClick={onSubmit}>Submit</button>
      </div>
    )}
  </Wizard.Step>
</Wizard>

Usage with an Array of Components

const steps = [1, 2, 3].map(index => (
  <Wizard.Step>
    {({ nextStep, prevStep, onSubmit }) => (
      <div>
        <h2>Step {index}</h2>
        <button onClick={prevStep}>prev</button>
        <button onClick={nextStep}>next</button>
      </div>
    )}
  </Wizard.Step>
))

return <Wizard steps={steps} />

Combining Both

In this case, the array of Wizard.Step components is rendered before those specified as children of the Wizard component.

const steps = [1, 2, 3].map(index => (
  <Wizard.Step>
    {({ nextStep, prevStep, onSubmit }) => (
      <div>
        <h2>Step {index}</h2>
        <button onClick={prevStep}>prev</button>
        <button onClick={nextStep}>next</button>
      </div>
    )}
  </Wizard.Step>
))

return (
  <Wizard steps={steps}>
    <Wizard.Step>
      {({ nextStep, prevStep, currentIndex, onSubmit }) => (
        <div>
          <h2>Baz {currentIndex}</h2>
          <button onClick={prevStep}>Back</button>
          <button onClick={onSubmit}>Submit</button>
        </div>
      )}
    </Wizard.Step>
  </Wizard>
)

Contributing

Feel free to dive in! Open an issue or submit PRs.

React Wizard follows the Contributor Covenant Code of Conduct.

Contributors

Thanks goes to these wonderful people (emoji key):

pahosler
pahosler

💡 🤔
Jody LeCompte
Jody LeCompte

⚠️ 🤔

This project follows the all-contributors specification. Contributions of any kind welcome!

You can’t perform that action at this time.