Skip to content
This repository has been archived by the owner on Apr 6, 2022. It is now read-only.

flywirecorp/react-wizr

Repository files navigation

react-wizr

React library for building declarative wizards

Example

Uncontrolled component

const App = () => (
  <Wizard
    onStepChanged={({ activeStepIndex }) =>
      console.log(`Step changed: ${activeStepIndex}`)
    }
  >
    <Steps>
      <Step id="first">
        <section>
          Minions ipsum tulaliloo la bodaaa tatata bala tu la bodaaa. Aaaaaah
          para tú aaaaaah hahaha ti aamoo! Bappleees belloo! Tatata bala tu
          bappleees. Uuuhhh para tú underweaaar poopayee hahaha chasy me want
          bananaaa! Potatoooo ti aamoo! Baboiii.
        </section>
      </Step>
      <Step id="second">
        <section>
          Belloo! tatata bala tu chasy poopayee ti aamoo! Para tú bee do bee do
          bee do belloo! Tatata bala tu hahaha bappleees me want bananaaa!
          Belloo! Hana dul sae belloo! Tatata bala tu gelatooo. Chasy tank yuuu!
          Underweaaar belloo! Gelatooo.
        </section>
      </Step>
      <Step id="third">
        <section>
          Poopayee poulet tikka masala potatoooo aaaaaah pepete gelatooo baboiii
          daa. Bananaaaa potatoooo poulet tikka masala hana dul sae uuuhhh
          tulaliloo. Poopayee jiji tank yuuu! Jiji potatoooo bappleees belloo!
          Uuuhhh bappleees chasy.
        </section>
      </Step>
    </Steps>
    <Navigation
      render={({ activeStepIndex, goToNextStep, goToPrevStep, totalSteps }) => (
        <div>
          {activeStepIndex > 0 && <button onClick={goToPrevStep}>Back</button>}
          {activeStepIndex < totalSteps - 1 && (
            <button onClick={goToNextStep}>Next</button>
          )}
        </div>
      )}
    />
  </Wizard>
);

Edit on CodeSandbox

Controlled component

class App extends Component {
  state = {
    activeStepIndex: 0
  };

  render() {
    return (
      <Wizard
        activeStepIndex={this.state.activeStepIndex}
        onStepChanged={({ activeStepIndex }) => {
          this.setState({ activeStepIndex });
          console.log(`Step changed: ${activeStepIndex}`);
        }}
      >
        <Steps>
          <Step id="first">
            <section>
              Minions ipsum tulaliloo la bodaaa tatata bala tu la bodaaa.
              Aaaaaah para tú aaaaaah hahaha ti aamoo! Bappleees belloo! Tatata
              bala tu bappleees. Uuuhhh para tú underweaaar poopayee hahaha
              chasy me want bananaaa! Potatoooo ti aamoo! Baboiii.
            </section>
          </Step>
          <Step id="second">
            <section>
              Belloo! tatata bala tu chasy poopayee ti aamoo! Para tú bee do bee
              do bee do belloo! Tatata bala tu hahaha bappleees me want
              bananaaa! Belloo! Hana dul sae belloo! Tatata bala tu gelatooo.
              Chasy tank yuuu! Underweaaar belloo! Gelatooo.
            </section>
          </Step>
          <Step id="third">
            <section>
              Poopayee poulet tikka masala potatoooo aaaaaah pepete gelatooo
              baboiii daa. Bananaaaa potatoooo poulet tikka masala hana dul sae
              uuuhhh tulaliloo. Poopayee jiji tank yuuu! Jiji potatoooo
              bappleees belloo! Uuuhhh bappleees chasy.
            </section>
          </Step>
        </Steps>
        <Navigation
          render={({
            activeStepIndex,
            goToNextStep,
            goToPrevStep,
            totalSteps
          }) => (
            <div>
              {activeStepIndex > 0 && (
                <button onClick={goToPrevStep}>Back</button>
              )}
              {activeStepIndex < totalSteps - 1 && (
                <button onClick={goToNextStep}>Next</button>
              )}
            </div>
          )}
        />
      </Wizard>
    );
  }
}

Edit react-wizr controlled

Routed

const App = () => (
  <Router>
    <Switch>
      <Route
        path="/steps"
        render={({ history, match: { url } }) => (
          <Wizard
            history={history}
            baseUrl={url}
            onStepChanged={({ activeStepIndex }) =>
              console.log(`Step changed: ${activeStepIndex}`)
            }
          >
            <Steps>
              <Step id="first">
                <section>
                  Minions ipsum tulaliloo la bodaaa tatata bala tu la bodaaa.
                  Aaaaaah para tú aaaaaah hahaha ti aamoo! Bappleees belloo!
                  Tatata bala tu bappleees. Uuuhhh para tú underweaaar poopayee
                  hahaha chasy me want bananaaa! Potatoooo ti aamoo! Baboiii.
                </section>
              </Step>
              <Step id="second">
                <section>
                  Belloo! tatata bala tu chasy poopayee ti aamoo! Para tú bee do
                  bee do bee do belloo! Tatata bala tu hahaha bappleees me want
                  bananaaa! Belloo! Hana dul sae belloo! Tatata bala tu
                  gelatooo. Chasy tank yuuu! Underweaaar belloo! Gelatooo.{' '}
                </section>
              </Step>
              <Step id="third">
                <section>
                  Poopayee poulet tikka masala potatoooo aaaaaah pepete gelatooo
                  baboiii daa. Bananaaaa potatoooo poulet tikka masala hana dul
                  sae uuuhhh tulaliloo. Poopayee jiji tank yuuu! Jiji potatoooo
                  bappleees belloo! Uuuhhh bappleees chasy.
                </section>
              </Step>
            </Steps>
            <Navigation
              render={({
                activeStepIndex,
                goToNextStep,
                goToPrevStep,
                totalSteps
              }) => (
                <div>
                  {activeStepIndex > 0 && (
                    <button onClick={goToPrevStep}>Back</button>
                  )}
                  {activeStepIndex < totalSteps - 1 && (
                    <button onClick={goToNextStep}>Next</button>
                  )}
                </div>
              )}
            />
          </Wizard>
        )}
      />
      <Redirect from="/" to="/steps" />
    </Switch>
  </Router>
);

Edit on CodeSandbox

Built With

Authors

  • Vicent Gozalbes - Initial work - vigosan

License

This project is licensed under the MIT License - see the LICENSE.md file for details

About

React library for building declarative wizards

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published