JSPM

  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 1
  • Score
    100M100P100Q26183F
  • License MIT

@rahsheen/react-wizard React component

Package Exports

  • @rahsheen/react-wizard

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (@rahsheen/react-wizard) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

@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!