0.1.2 • Published 6 months ago

simple-react-multistep v0.1.2

Weekly downloads
-
License
MIT
Repository
github
Last release
6 months ago

Responsive React multistep form component

Take it for a spin

List of contributors (:raised_hands:)

Instructions

To use this module in your app run:

npm install react-multistep

next, import it inside of your app:

import MultiStep from 'react-multistep'

and then, in your application, you add your custom components/forms this way:

<MultiStep activeStep={0} prevButton={prevButton} nextButton={nextButton}>
    <StepOne title='Step 1'/>
    <StepTwo title='Step 2'/>
</MultiStep>

MultiStep component accepts following props (all optional, except Steps array):

PROPERTYDESCRIPTIONTYPEDEFAULTisRequired
showNavigationcontrols if the navigation buttons are visiblebooleantruefalse
showTitlescontrol either the steps title are visible or notbooleantruefalse
prevButtonconfigure the prev navigation buttonNavButtonnullfalse
nextButtonconfigure the next the navigation buttonNavButtonnullfalse
stepCustomStylecontrol style of stepCSSPropertiesnullfalse
directioncontrol the steps nav directioncolumnrowfalse
activeStepit takes a number representing representing starting stepnumber0false
stepsit takes an array of objects representing individual stepsStepnullfalse

🚀 NEW! you can also use style props for the navigation buttons and change how they look with two props 'prevButton' & 'nextButton'

PROPERTYDESCRIPTIONTYPEDEFAULTisRequired
titleThe display string value of the navigation buttonstringPrev / Nextfalse
styleThe css style of the navigation buttonCSSPropertiesnullfalse

There are two ways to configure Multistep component, preferred way is with Inlined child components. Using this approach, enables the new feature that allows controlling the navigation based on the current step's form validation

    <MultiStep  title: 'Order Workflow'} 
                activeStep={2} 
                prevButton={{title: 'Back','style:{ background: 'red' }}
                nextButton={{title: 'Forward','style:{ background: 'green' }}
    >
    <StepOne title='StepOne'/>
    <StepTwo title='StepTwo'/>
    <StepThree title='StepThree'/>
    <StepFour title='StepFour'/>
</MultiStep>

The old way via Steps, a prop in the form of an array of components, is still supported for backwards compatibility. But, (:warning:) this way has being deprecated, and it will be removed in the future

const steps = [
              {title: 'StepOne', component: <StepOne/>},
              {title: 'StepTwo', component: <StepTwo/>},
              {title: 'StepThree', component: <StepThree/>},
              {title: 'StepFour', component: <StepFour/>}
            ];
...       
...

<MultiStep activeStep={1} showNavigation={true} steps={steps}/>

When configured this way, each component (Step) of the array can have following two properties:

PROPERTYDESCRIPTIONTYPEDEFAULTisRequired
componentthe step representing componentJSX.Elementnulltrue
titlethe step title, present above the steps navtextstep indexfalse

🚀 NEW! Feature: Controlling navigation to the next step with form validation

To enable this feature, when the child form component needs to control 'Next' navigational button, based on it's local validation, MultiStep dynamically adds a new prop function to child components that should be used to signal validation status. MultiStep will disable /enable Next button accordingly. This function has follwing signature:

signalParent(valid: boolean)

By default the state is false and child components invokes it based on current outcome of the validation. In the example app, a simple checkbox is used to simulate valid/not valid.

This can be seen in the example app, but here are the relevant parts, required inside of the form child component:

Instructions for local development

If you would like to explore further, contribute a PR or just try the included code example

Start by cloning the repo locally:

git clone https://github.com/srdjan/react-multistep.git

then:

cd react-multistep            // (1) navigate to the project folder
npm install                   // (2) install dependencies
npm run build                 // (3) build the component

On a successful build, try the example app:

cd ../example                 // (1) navigate to the example folder
npm install                   // (2) install dependencies
npm run build                 // (3) build the example
npm start                     // (4) start the local server

Now, you can open the example in your favorite browser...

0.1.2

6 months ago

0.1.1

6 months ago

0.1.0

6 months ago

0.0.9

6 months ago

0.0.8

6 months ago

0.0.7

6 months ago

0.0.6

6 months ago

0.0.5

6 months ago

0.0.4

6 months ago

0.0.3

6 months ago

0.0.2

6 months ago

0.0.1

6 months ago