Code Monkey home page Code Monkey logo

react-multistep's Introduction

Responsive React multistep form component



Take it for a SPIN! ๐Ÿ’ซ





List of contributors ๐Ÿ™Œ

AWESOME CONTRIBUTORS


Previous MultiStep major version, v5.4.0

Version 5.x.x is in a maintenance mode, the new development is ongoing on v6.x.x. Version (v5.x.x) bug fixes will still be available on NPM, if you would like to open a PR for a fix or make a fork, git checkout branch v5.x.x. The new version, v6.0.0 has a multiple improvements (see below) and is not backwards compatible.

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):

PROPERTY DESCRIPTION TYPE DEFAULT isRequired
showTopNav controls if the navigation buttons are visible boolean true false
prevButton configure the prev navigation button NavButtonProp null false
nextButton configure the next the navigation button NavButtonProp null false
stepCustomStyle control style of step CSSProperties null false
direction control the steps nav direction column row false
activeStep it takes a number representing representing starting step number 0 false

๐Ÿš€ NEW! you can also use style props for the navigation buttons and change how they look with two props 'prevButton' & 'nextButton':

PROPERTY DESCRIPTION TYPE DEFAULT isRequired
title The display string value of the navigation button string Prev / Next false
style The css style of the navigation button CSSProperties null false

To configure Multistep component, we inline child components:

    <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>

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

PROPERTY DESCRIPTION TYPE DEFAULT isRequired
component the step representing component JSX.Element null true
title the step title, present above the steps nav text step index false

๐Ÿš€ 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:

child-step-component-changes

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...

react-multistep's People

Contributors

adamtaylor13 avatar alkaly02 avatar bondos avatar davidgruebl avatar daweimau avatar dependabot[bot] avatar dreamerchandra avatar jaimeagudo avatar kaadash avatar mattparrilla avatar mike1011 avatar ofirelarat avatar saffameer avatar salomao-rodrigues avatar shoyayeb avatar srdjan avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

react-multistep's Issues

Not compatible with create-react-app:

Support for the experimental syntax 'classProperties' isn't currently enabled. Doesn't work even when you have npm run eject and modified babelrc as required.

Passing props to steps

I am incorporating your library in a project I'm doing. In this project I am converting a one-pager for into a multi-step form. The <MultiStep /> component is rendered by another component which should pass props to the slides. I tried to pass it through <MultiStep steps={steps} user={user} /> but user didn't pass to the steps.
I couldn't find a documentation that explains how to do it.

Would appreciate your help on this subject :)

ERROR in ./node_modules/react-multistep/src/index.js 37:8

Getting this error when including react-multistep in my webpack project:

Windows 10
Webpack 4.28.3
React 16.7

Steps to repo (in a react project with above Webpack version, running Webpack dev-server):

  • npm i react-multistep --save
  • In a JSX file add the following line:
    import MultiStep from 'react-multistep/src/index';
  • Wait for dev-server to compile, but it fails with this error:
ERROR in ./node_modules/react-multistep/src/index.js 37:8
Module parse failed: Unexpected token (37:8)
You may need an appropriate loader to handle this file type.
|
| export default class MultiStep extends React.Component {
>   state = {
|     showPreviousBtn: false,
|     showNextBtn: true,

Tried going into the node_modules/react-multistep file and do the "npm run build-with-webpack" you suggested in some other issues (but seems like this just builds the sample app and has nothing to do with using the node module in a real project) and it gave a similar error.

Seems like this issue is similar to #38, #30, #23, #20, none of which were solved in a general way.

customisation options

How do i customise this wizard. I want to add wrapper for content and footer buttons and want separate navigation bar.

Improvements to the library

Hey @srdjan I'm using this library and I did a few fixes for the new ref system, also I added a few options in my branch. I would like to know if you would like to receive a proper PR, if so I can prepare it.

Documentation to work with create-react-app?

Hi
First of all thank you for the great project. However I am trying to use it in my project (CRA) and I get the following:

./node_modules/react-multistep/src/index.js
Module parse failed: Unexpected token (98:6)
You may need an appropriate loader to handle this file type.
|   renderSteps() {
|     return this.props.steps.map((s, i)=> (
|       <li className={this.getClassName("progtrckr", i)} onClick={this.handleOnClick} key={i} value={i}>
|         <em>{i+1}</em>
|         <span>{this.props.steps[i].name}</span>

any ideas? happy to contribute to the docs if you point me in the right direction.

Thanks

Failed to compile.

./node_modules/react-multistep/src/index.js
Module parse failed: Unexpected token (37:8)
You may need an appropriate loader to handle this file type.
|
| export default class MultiStep extends React.Component {
| state = {
| showPreviousBtn: false,
| showNextBtn: true,

Form validation

Hi, I looked at the index.js and cannot see any validation included. How would you validate an individual step?

Any plan to integrate with Redux forms? Thanks.

Implement submit button

Thanks for this library. Please, how do one create a submit button after the completion of filling the form since only Prev and Next buttons are the ones available? And also how do one handle validations on each steps?

How to className to container and Previous, Next buttons

I want to style using the parent class.

ie, I want to use like this:
<MultiStep showNavigation={true} className="my-class" steps={steps}/>
But className not working.

Is there any way to give className to the container???

Also, I want to add className to Previous and Next buttons for styling.

I'm waiting for your reply.

docs?

is there a plan to add documentation soon? do you need help with it?

Hard dependency on jsx

Hi, your module throws errors on the jsx in line 53 of index.js. The jsx which should not be in your published module.

Please always export your code without any dependencies on es6 or jsx, so other people can include it as is.

Thanks in advance!

Unable to load this module with WebPack

bug? I use with babel-loader 6.2.4 and babel-preset-es2015 6.9.0

node_modules/react-multistep/src/index.js Unexpected token (98:6)
You may need an appropriate loader to handle this file type.

Next button is not showing up if number of props.steps increased during multistep lifecycle

My case:
I have 3 steps, if the third step is valid, I'll send the fourth step to props.steps of multistep component and if the fourth is valid, I'll send the fifth step to multistep and so forth until I finish my scenario journey.

The issue:
Steps:

  • If we just have three steps and I am already in the third one.
  • After some user inputs, the third step got valid.
  • My code automatically sends the fourth step to the multistep component.
  • The nav styles get updated, but the buttons still as is, with NO next button visible.

Why:
Because updating the buttons only happens on three events
When the user hits
1- The navigation list items
2- Next button
3- Previous button

The fix:

  • Buttons should be updated on props.steps changes

I have created a pull-request with the fix
#57

Thank you

Data is not persistent across Steps

Hi @srdjan. I noticed that state data is not been saved between steps. I know this works fine in your demo page but If follow these steps you will be able to see what I am talking about

  • Clone this repo
  • npm install
  • npm run build
  • upload build to a webserver

Do you have any idea what might be wrong?

Regards

Ivan

Unexpected Token

Getting the following error while building:
SyntaxError: Unexpected token: name (MultiStep) [./~/react-multistep/src/index.js:2,0]

Running React 15.5.4

You may need an appropriate loader to handle this file type.

ERROR in .//react-multistep/src/multistep.js
Module parse failed: /Developer/NullPay/TierraPay/client/node_modules/react-multistep/src/multistep.js Unexpected token (98:6)
You may need an appropriate loader to handle this file type.
| renderSteps() {
| return this.props.steps.map((s, i)=> (
| <li className={this.getClassName("progtrckr", i)} onClick={this.handleOnClick} key={i} value={i}>
| {i+1}
| {this.props.steps[i].name}
@ ./
/react-multistep/src/index.js 2:0-35
@ ./app/bundles/WalletApp/components/SendMoney/SendMoney.jsx
@ ./app/bundles/WalletApp/startup/registration.jsx
@ multi es5-shim/es5-shim es5-shim/es5-sham babel-polyfill ./app/bundles/WalletApp/startup/registration

I add this on my react_on_rails gem for rails app

Error while compiling in webpack

I have imported the package and in while building in webpack, I am getting following error.
ERROR in ./~/react-multistep/src/index.js
Module parse failed: E:\work\webui\scm-hackfest\node_modules\react-multistep\src\index.js Unexpected token (98:6)
You may need an appropriate loader to handle this file type.
| renderSteps() {
| return this.props.steps.map((s, i)=> (
| <li className={this.getClassName("progtrckr", i)} onClick={this.handleOn
Click} key={i} value={i}>
| {i+1}
| {this.props.steps[i].name}
@ ./app/containers/TemplatePage/index.js 53:16-42
Child html-webpack-plugin for "index.html":

It says I don't have appropriate loader. Please let me know if I am missing something.

Validation for input forms

Hello, how can one add validation to the input forms? I want to prevent the next page from showing up if no data has been entered in the present page's input forms. Thank you

form data does not persist

Form data does not appear to persist across 'steps', however, your gh-pages branch does. Is there a reason the state of each form field is not kept between steps in your master branch?

I am a bit confused.

Not able to use the npm package - SyntaxError: Unexpected token

Trying to use your multistep plugin in my project and getting:

ERROR in ./~/react-multistep/src/index.js Module parse failed: /Users/demo/node_modules/react-multistep/src/index.js Unexpected token (98:6) You may need an appropriate loader to handle this file type. SyntaxError: Unexpected token (98:6)

My .babelrc file looks like so:

{ "plugins": ["transform-react-jsx"], "presets": ["react", "es2015", "stage-2"], "env": { "development": { "presets": [ "react-hmre"] }, "production": { "plugins": [ "transform-react-constant-elements", "transform-react-remove-prop-types" ] } } }

any idea what's going on?

Question - Whats the best way to access a method inside a Child Step component

Hello,

This is more of a question than a issue.

I'm using your example code here:
https://github.com/Srdjan/react-multistep/tree/master/example/app

But as the user clicks on the "Next" button I need to first call a method inside the child (step) component before rendering it.

For example, I have a isValidated() method inside each of my child (step) components. When you click on the next button I want to first check if the current step has validated and then move on.

e.g.:

next() {
    if (this.props.steps[this.state.compState].component.isValidated()) {
       this.setNavState(this.state.compState + 1)
    }
}

I want to do this without using a store (flux / redux events) as this has more to do with component state rather than data state.

Once way is to somehow assign a "ref" to the child step component in the render() of MultiStep.

e.g.

render() {
    return (
        ...
        { this.props.steps[this.state.compState].component}.refs = 'activeComponent' }
        ...
    )
}

and then in next() access the activeComponent's isValidated() method.

next() {
    if (this.refs.activeComponent.isValidated()) {
       this.setNavState(this.state.compState + 1)
    }
}

But unfortunately I am not sure if we can add a refs to the step property as the child step component is passed in the array.

How would you do this? any advise / help?

Clicking on step name fires onClick but doesn't go to step

To reproduce:

  1. Click on step name (such as "StepTwo" of example)
  2. Notice how progtrckr becomes unstyled and the desired step isn't selected.

This occurs because the handleOnClick method uses event.target instead of event.currentTarget.

When you click on the <span> that contains the step name, the parent <li>'s onClick is still fired, but evt.target.value is undefined because the span (the target) doesn't have a value. Using currentTarget ensures that the value comes from the element with the actual handler (the <li>).

More on currentTarget

Problem running example

Hey,

I'm trying to learn your repo using the example but encoutered problems with the last two steps.
On react-multistep/example when running sudo npm run build:dev I receive the following error:

npm ERR! missing script: build:dev

any thoughts on how and why can it happen?

Issue on npm run build

Hi,

When I execute the command npm run build after executing npm install I get the below mentioned error

error: Must use "outdir" when there are multiple input files

FYI: I have checked out the master

Failed to compile on fresh install

With create-react-app, I installed via npm install react-multistep. Then, following the directions provided in the readme I get the following error:

`./node_modules/react-multistep/src/index.js
SyntaxError: ...\node_modules\react-multistep\src\index.js: Unexpected token (63:6)

61 | const renderSteps = () =>
62 | props.steps.map((s, i) => (

63 | <li
| ^
64 | className={'progtrckr-' + stylesState[i]}
65 | onClick={handleOnClick}
66 | key={i}`

Rubbish Plugin

Rubbish Plugin. No proper example. No proper Demo. Error in index.js in node_modules.

npm test: showing the error as below

E:\localstorage\react-multistep-master>npm test

[email protected] test E:\bitbucket\react-multistep-master
todo... mocha

'todo...' is not recognized as an internal or external command,
operable program or batch file.
npm ERR! Test failed. See above for more details

Note: I had tried to run "Dev Instructions", but it is showing the error as above. Help me out of this issue.
wizard-npmtest-not-working

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.