Introduction
A render-props
component to write wizards in React.
Prior Art
Getting Started
Install
yarn add react-merlin
Create A Step Component
react-merlin
gives you the capability to design your own steps
or to mix it with other designs without duplicating the logic.
Here is an example of a step component:
; const Step = <ReactFragment> children <button onClick= { nextIndex = isLast ? 0 : stepIndex+1; ; }>next</button> </ReactFragment>
Setup Wizard Data Structure
If you have a simple flow probably Array
will be good.
Otherwise, Tree or Hash (Object
or Array
of Object
s) will work for you.
; const WizardSteps = { return <Step setStep=setStep stepIndex=0 isLast=false>Step 1</Step> <Step setStep=setStep stepIndex=1 isLast=false>Step 2</Step> <Step setStep=setStep stepIndex=2 isLast=true>Step 3</Step> ;}
Note: stepIndex
starts at 0
like in Array
.
Put Everything Together
;;; const App = <Merlin> index </Merlin>
License
MIT.