GithubHelp home page GithubHelp logo

brock-noah / react-whatever-wizard Goto Github PK

View Code? Open in Web Editor NEW
3.0 2.0 0.0 48 KB

declarative, component based, multistep manager

HTML 3.11% CSS 0.98% JavaScript 95.91%
react javascript ui declarative

react-whatever-wizard's Introduction

react-whatever-wizard

Declarative component based wizard

Provides:

  • Wizard props in your view components
  • Manages which page to show and roles to change the page
  • Functions for before and after page change
  • BEM like classes for CSS, scoped by ww
  • Declare buttons inside steps like html
  • Keeps elements on page, adds display: none style

Doesn't Provide:

  • Does not manage saving form fields
  • No configs or step arrays with complex objects

Example

RealWizardary.jsx

import { WhateverWizard, Step, StepButton } from './WhateverWizard';
import MyStep from './';

<WhateverWizard>
  <Step componentClass={MyStep} componentProps={{color: 'goldenrod'}}>
    <StepButton role="next">Next</StepButton>
  </Step>
  <Step componentClass={MyStep}>
    <StepButton role="back" componentProps={{title: 'Go Back'}}>Back</StepButton>
    <StepButton
      preRole={() => confirm('Submit?')}
      role={() => alert('Thank you')}
    >Done</StepButton>
  </Step>
</WhateverWizard>

MyStep.jsx

const MyStep = (props) =>
  <div style={{color: props.color || 'black'}}>
    <h1>Step {props.wizard.number} of {props.wizard.total}</h1>
    (props.wizard.isLast) &&
      <button onClick={props.wizard.actions.first}>Restart</button>
  </div>;

Docs

Components

WhateverWizard

Props

scopeKey: string Default: wizard

Key to nest wizard specific props for the layoutComponent and componentClass components.

layoutComponent: class, React.createComponent, function

The layout that renders with each step. Where buttons should be placed, progress bar, step number, etc. Not effected by scopeKey.

layoutProps: object

Props to pass to the layoutComponent. Not effected by scopeKey.

Step

Props

componentClass: class, React.createComponent, function

The component to render for that step. This component will receive wizard props under the scopeKey.

componentProps: object

The props for componentClass. Not effected by scopeKey.

layoutProps: object

Props to pass to the layoutComponent. Step specific layoutProps will override the parent WhateverWizard layoutProps. Not effected by scopeKey.

StepButton

Currently, there is no onClick for StepButton, not through the Component itself nor componentProps. Instead you have preRole, role, and postRole functions. Role is the default click function available. To change the active step state, you will use the role prop.

Props

role

next, back, first, last: string
function(actions: object, postRole: function)

Either a string for predefined navagation, or a function. If role is a function, you have to call your postRole callback. Actions are the predefined navagation options.

preRole

function(): boolean

Function fired before role. A conformation or validate function. If return a falsey value besides undefined, role and postRole will not fire.

postRole

function()

A callback after the state (React.Component.setState) has upated. If role is a function, you will have to call this function. It is provided as the second argument to role.

The component class for Step will receive the following extra props under the WhateverWizard prop scopeKey:

  • number Type: number (1 based step number system)
  • total Type: number
  • isFirst Type: boolean
  • isLast Type: boolean
  • actions.{first, back, next, last} Type: object (how to change the page)

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.