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.
<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>
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} />
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>
)
Feel free to dive in! Open an issue or submit PRs.
React Wizard follows the Contributor Covenant Code of Conduct.
Thanks goes to these wonderful people (emoji key):
pahosler 💡 🤔 |
Jody LeCompte |
---|
This project follows the all-contributors specification. Contributions of any kind welcome!