Coder Social home page Coder Social logo

alan2207 / react-multistep-wizard Goto Github PK

View Code? Open in Web Editor NEW
11.0 3.0 2.0 768 KB

๐Ÿง™ React wizard component

HTML 5.91% JavaScript 34.54% CSS 0.81% TypeScript 58.75%
react multistep wizard-component wizard render-props compound-components context-api

react-multistep-wizard's Introduction

react-multistep-wizard

React wizard component

NPM JavaScript Style Guide

Install

npm install --save react-multistep-wizard

Usage

import React from 'react';

import { Wizard, Steps, Step } from 'react-multistep-wizard';

// simple example:
class Example extends React.Component {
  render() {
    return (
      <Wizard>
        <Steps>
          <Step>
            {ctx => (
              <div>
                Step 1: <button onClick={ctx.next}>Next Step</button>
              </div>
            )}
          </Step>
          <Step>
            {ctx => (
              <div>
                Step 2: <button onClick={ctx.next}>Next Step</button>
              </div>
            )}
          </Step>
        </Steps>
      </Wizard>
    );
  }
}

Live Demo

API

Exports:

Components:

Wizard

Component that controls the entire state of the component.

props:
  • safe - keeps the app from breaking on attempts to go to non existing steps.
  • onChange - function triggered on change.
  • startStep - choose from which step to start the wizard. Defaults to 1.
  • externalOverrides - use it for the external control of the component, for example if you want the wizard component to be controlled from an external source.
<Wizard
  safe={false}
  onChange={console.log}
  startStep={1}
  externalOverrides={{
    currentStep: externalCurrentStep,
    next: externalNextFn,
    previous: externalPreviousFn,
    jump: externalJumpFn
  }}
>{...}</Wizard>

Steps

Component that controls the rendering of the current step. Doesn't accept any props, and must have the Step components as children.

useWizard

Hook that exposes the entire Wizard component state to consumer components.

Step

Component that describes the actual step. By using render prop function, it can pass the wizard's context to the UI in order to allow user to control it from within it.

Render prop options from WizardContext:

  • currentStep
  • totalSteps
  • previous
  • next
  • jump
  • init

WithWizard

Component similar to Step. The only difference is that it should not be rendered from the Steps component, that way making sure it is always rendered regardless of the current step. Convenient for progress indicators.

TypeScript Types:

WizardProps

WizardContextState

For more info check out the example folder or the live demo.

License

MIT ยฉ alan2207

react-multistep-wizard's People

Contributors

alan2207 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

react-multistep-wizard's Issues

Hook Google Analytics?

I'd like to know if you have any approach if I want to use react-ga to send a page view or event to GA on each wizard step change without the need to control the whole wizard myself.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.