Coder Social home page Coder Social logo

react-albus's Introduction

React Albus · Build Status Coverage Status npm version

“Let us <Step> into the night and pursue that flighty temptress, adventure.”

-- Albus Dumbledore

What is React Albus?

React Albus is a React component library used to build declarative multi-step journeys (also known as Wizards). You define your step content and ordering and React Albus will manage the journey-related state for you.

React Albus is otherwise unopinionated and allows you to compose functionality such as routing, animation, and analytics however you see fit.

Installation

npm install react-albus

Example

import React from 'react';
import { Wizard, Steps, Step } from 'react-albus';

const Example = () => (
  <Wizard>
    <Steps>
      <Step
        id="merlin"
        render={({ next }) => (
          <div>
            <h1>Merlin</h1>
            <button onClick={next}>Next</button>
          </div>
        )}
      />
      <Step
        id="gandalf"
        render={({ next, previous }) => (
          <div>
            <h1>Gandalf</h1>
            <button onClick={next}>Next</button>
            <button onClick={previous}>Previous</button>
          </div>
        )}
      />
      <Step
        id="dumbledore"
        render={({ previous }) => (
          <div>
            <h1>Dumbledore</h1>
            <button onClick={previous}>Previous</button>
          </div>
        )}
      />
    </Steps>
  </Wizard>
);

export default Example;

Demo

Check out the demo page!

API


<Wizard>

Props

onNext(wizard): function (optional)

A function that will be called by <Wizard> to determine the next step to proceed to.

Params

If you do not pass an onNext prop, <Wizard> will proceed directly to the next step.

render(wizard): function (optional)

A function that will be used as the render function of <Wizard>.

Params

<Steps>

Wraps all of the <Step> components in your journey. The only direct children of <Steps> should be <Step> components.

Props

step: object (optional)

An object describing the current step with the structure: { id: string }. Defining a step prop will make <Steps> a controlled component.


<Step>

Wraps all the content that will be conditionally shown when the step is active.

Props

id: string

Unique key for each step.

In addition to id, any additional props added to <Step> will be available on each step object. This can be used to add names, descriptions, or other metadata to each step.

<WithWizard> is an alias for <Step> that can be used to access context.wizard anywhere within the <Wizard> tree.


withWizard()

A higher order component that adds context.wizard as a wizard prop on the wrapped component.


context.wizard

<Wizard> provides an object on context with the following properties:

  • step (object): Describes the current step with structure: { id: string }.
  • steps (array): Array of step objects in the order they were declared within <Steps>.
  • history (object): The backing history object.
  • next() (function): Moves to the next step in order.
  • previous() (function): Moves to the previous step in order.
  • go(n) (function): Moves n steps in history.
  • push(id) (function): Pushes the step with corresponding id onto history.
  • replace(id) (function): Replaces the current step in history with the step with corresponding id.

Usage with React Router

Internally, React Albus uses history to maintain the ordering of steps. This makes integrating with React Router (or any other router) as easy as providing <Wizard> with history and basename props.

import React from 'react';
import { Route } from 'react-router-dom';
import { Wizard } from 'react-albus';

const RoutedWizard = ({ children }) =>
  <Route
    render={({ history, match: { url } }) =>
      <Wizard history={history} basename={url}>
        {children}
      </Wizard>}
  />;

export default RoutedWizard;

Contributing

We welcome Your interest in the American Express Open Source Community on Github. Any Contributor to any Open Source Project managed by the American Express Open Source Community must accept and sign an Agreement indicating agreement to the terms below. Except for the rights granted in this Agreement to American Express and to recipients of software distributed by American Express, You reserve all right, title, and interest, if any, in and to Your Contributions. Please fill out the Agreement.

License

Any contributions made under this project will be governed by the Apache License 2.0.

Code of Conduct

This project adheres to the American Express Community Guidelines. By participating, you are expected to honor these guidelines.

Analytics

react-albus's People

Contributors

jackjocross avatar tklever avatar nathanforce avatar prmichaelsen avatar wtgtybhertgeghgtwtg avatar gjlarsen avatar

Watchers

 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.