0.0.14 • Published 26 days ago

react-formdata-wizard v0.0.14

Weekly downloads
13
License
GPL-3.0-or-later
Repository
github
Last release
26 days ago

UclusionWizard

react-formdata-wizard

React wizard that maintains step state and form data for you. Form data is automagically saved to the local storage of the browser, so you don't have to worry about reloads or any other ram-state destroying event.

NPM JavaScript Style Guide

Install

npm install --save react-formdata-wizard

Usage

import React, { Component } from 'react'

import FormdataWizard from 'react-formdata-wizard'
import 'react-formdata-wizard/dist/index.css'

class Example extends Component {
  render() {
    return (
      <FormdataWizard>
        <Step0/>
        <Step1/>
        ...
      </FormdataWizard>
  )
  }
}

General Ethos

This package does NOT render any UI by itself. It doesn't have any buttons, nor does it specify fancy transitions. What it will do is maintain the current step progress and any form data you give to it. The form data passed in is persisted into the browsers local storage until the form is either started over or reset.

Child internal state

The actual step rendered is a clone of the child representing the current step. For this reason children cannot maintain their own state, and should use the form data instead of useState or useReducer

Props accepted by the Wizard

Property NameProperty DescriptionRequired
namethe 'name' of the wizard. Should be unique as it will determine the local storage key usedY
onStartOverfunction called with zero arguments that is called when the form is started over without completingN
onFinishfunction called with either the form data or a specific return value that is called when the form finishes normallyN
resetSetterfunction that will be called with a variable containing a function that can reset the wizard. This allows higher level components to cause a reset for their own reasons.N
defaultFormDatadefault form data to apply on creation if nothing is stored locally.N
useLocalStoragewhether to back the wizard with local storage or notY
startStepthe step to start the wizard from. Used if some steps are no longer neededN

Props provided to All Children

Property NameProperty Description
currentStepthe 0-indexed step number we're on
totalStepsthe number of steps we have
formDatathe current form data accumulated so far
updateFormDatafunction that takes an update object and merges the existing formdata with the update object
clearFormDatafunction that resets the form data to the empty object
nextStepfunction that advances the wizard by increment steps where increment defaults to one
previousStepfunction that regresses teh wizzard to the previous step
startOverfunction that calls onStartOver and then resets the wizard to the initial state
activeboolean that tells the step if it is the currently active step
finishfunction taking one optional argument that calls the provided onFinish with that argument, or if not provided the current form state, then resets the wizard to the initial state

License

GPLv3 © Uclusion Inc, 2020 BFUculsion

0.0.14

26 days ago

0.0.10

6 months ago

0.0.11

6 months ago

0.0.12

6 months ago

0.0.13

6 months ago

0.0.9

1 year ago

0.0.8

1 year ago

0.0.7

1 year ago

0.0.6

1 year ago

0.0.5

2 years ago

0.0.3

3 years ago

0.0.4

3 years ago

0.0.2

4 years ago

0.0.1

4 years ago