Code Monkey home page Code Monkey logo

megawizard's Introduction

MegaWizard

React Wizard Component

MegaWizard is a React component for easily making step-by-step wizards without having to configure ten thousand seperate props..

Features

  • Super flexibile configuration via a step definition object.
    • Easily embed React components or HTML elements.
    • Optional step validators to prevent advancement until your conditions are met.
    • Optional visibility flag for dynamically hiding/display steps.
    • Execution hooks for entering and leaving steps
  • Step display summary and completed step indications.
  • Super fast rendering that works on both client and server.
  • Only renders markup for currently displayed steps.
  • Best name ever for a wizard.

Limitations

  • Relies on Bootstrap for styling and layout
  • No way to customize step summary

If you are interested in helping with any of this, I would gladly take pull requests.

Using it

To use MegaWizard:

  • Install the component through NPM
  • Require it
  • Create step definition object and pass it to MegaWizard

Component props

MegaWizard has the following component props:

Required:

steps - step definition object

Optional

onStepChanged(currentStep) - function to call after a step is changed. Argument is the current step. Called before onEnter and onExit hooks.

onStepWillChange(currentStep) - function to call before a step is changed. Argument is the current step.

onComplete() - function to call when complete button is clicked on last step. No arguments. Called before onExit hook.

prevButtonText - global text override to display for previous button. Default is "Previous".

nextButtonText - global text override to display for next button. Default is "Next".

completeButtonText - global text override to display for complete button. Default is "Done".

prevButtonClasses - global class override for previous button. If using, you must handle horizontal positioning yourself.

nextButtonClasses - global class override for next button. If using, you must handle horizontal positioning yourself.

completeButtonClasses - global class override for complete button. If using, you must handle horizontal positioning yourself.

Step definition options

Steps definitions are a flexible way to get some fairly complex behaviors into the wizard. Since each step is defined indepentently, you can drive wizard behavior by using state/props from outisde the wizard. Step definitions may have any combination of the following options:

Required:

name - unique indentifier for step

text - display name (shown on sidebar and header)

Optional

onEnter - function to call when entering this step (fires when entering steps via next or previous movement). No arguments.

onExit - function to call when exiting this step (fires when leaving steps via next or previous movement). No arguments.

visible - entire step is hidden if this is defined and false. May truthy, falsy, or bool.

nextValidator - next button is disabled if this is defined and false. May truthy, falsy, or bool.

prevValidator - previous button is disabled if this is defined and false. May truthy, falsy, or bool.

prevButtonText - text to display for previous button. Default is "Previous".

nextButtonText - text to display for next button. Default is "Next".

completeButtonText - text to display for complete button. Default is "Done".

prevButtonClasses - class overrides for previous button. If using, you must handle horizontal positioning yourself.

nextButtonClasses - class overrides for next button. If using, you must handle horizontal positioning yourself.

completeButtonClasses - class overrides for complete button. If using, you must handle horizontal positioning yourself.

display - React element to display when step is active.

Contrived Example:

render() {
  let stepDef = Immutable.fromJS([
    {
      name: 'enterName',
      text: `Enter a name for widget ${this.state.widgetId}`,
      onEnter: this.props.hideWidgetList,
      nextValidator: this.state.nameInputText,
      display: () => {
        return (
          <div>
            <input type='text' value={this.state.nameText} onChange={this.handleInputChange} />
          </div>
        );
      },
    },
    {
      name: 'enterDescription',
      text: 'Enter a description',
      visible: this.state.descriptionRequired,
      nextValidator: this.state.descriptionText,
      display: () => {
        return (
          <DescriptionForm description={this.state.descriptionText}
            onChange={this.handleDescriptionChange} />
        );
      }
    },
    {
      name: 'confirm',
      text: 'Confirm',
      onExit: this.showWidgetList,
      display: () => {
        return (
          <div>
            Are you sure you want to use <strong>{this.state.nameText} - {this.state.descriptionText}</strong> for your widget?
          </div>
        );
      },
    },
  ]);

  return (
    <MegaWizard steps={stepDef} onStepChanged={this.handleStepChanged} onComplete={this.handleWizardComplete} />
  );
}

Contributing

First, setup your local environment:

git clone [email protected]:ZeroarcSoftware/megawizard.git
cd megawizard
npm install

Next, build the project (for use in a npm link scenario):

npm run build

To watch for changes:

npm run watch

Issues

Issues are tracked in Github Issues.

Changes

Changes are tracked as Github Releases.

megawizard's People

Contributors

jslatts avatar

Watchers

James Cloos avatar Steve Byerly avatar

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.