Skip to content

sametweb/react-step-builder

Repository files navigation

React Step Builder

Build Status Coverage Status Test Coverage Maintainability

React Step Builder is a UI-agnostic multi step interface builder.


Overview

React Step Builder allows you to combine states of multiple components in one place and navigate between step components without losing the state from other step components.

It only provides wrapper components and methods to be able to render your step components without being forced to use certain UI features in your step structure.


Installation

Using npm:

$ npm install --save react-step-builder 

Usage

<Steps> <Step title="My First Step" component={Step1} /> <Step title="My Second Step" component={Step2} /> <Step title="My Third Step" component={Step3} /> </Steps>

Documentation

Component Description
<Steps /> Wrapper component for Step components. Step components must be wrapped in <Steps /> component.
<Step /> This is the component you create for each step in your application. The title prop takes a title for the step, which is provided back in props in the step component. The component prop takes the component that you would like to show in that step.

Following props are available to your step components.


props.current

number

The current step's order number


props.next

function()

Moves to the next step if it exists.


props.prev

function()

Moves to the previous step if it exists.


props.jump

function(<order>)

Jumps to the step with the provided step order if it exists.


props.state

object

Contains all the state pieces combined from your Step components. The user data that was entered accross the steps accumulate under this value.


props.getState

function(<key>)

Returns the state value for the provided key. If the key does not exist, returns empty string.


props.setState

function(<key, value>)

Manipulates your state directly. You must provide key and value to be stored in your state.
NOTE: If your data is coming from a synthetic React event (via onChange), use props.handleChange instead.


props.handleChange

function(<event>)

You may pass this function to onChange events in your form elements. Your form element must have a name property, which eventually becomes its key in the state object. If your form element has name="username", then it is stored in state as {props.state.username}.


props.step

object <StepNode>

This object provides information about current step and methods to move between steps. Available properties and methods:

Properties

  • props.step.order - Order number of the props.step.
  • props.step.title - Title of the step (you provided when creating <Step /> component)
  • props.step.nextStep - Order number of the next step, null if it's not available
  • props.step.prevStep - Order number of the previous step, null if it's not available

Methods

  • props.step.isFirst() - Returns true if it's the first step, otherwise false
  • props.step.isLast() - Returns true if it's the last step, otherwise false
  • props.step.hasNext() - Returns true if there is a next step available, otherwise false
  • props.step.hasPrev() - Returns true if there is a previous step available, otherwise false

About

React Step Builder allows you to create step-by-step interfaces easily.

Topics

Resources

License

Contributing

Stars

Watchers

Forks

Packages

No packages published

Contributors 4

  •  
  •  
  •  
  •