JSPM

multistep-react-form

1.0.0
  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • 0
  • Score
    100M100P100Q26352F
  • License MIT

Multistep form

Package Exports

  • multistep-react-form
  • multistep-react-form/dist/index.js

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (multistep-react-form) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

react-multistep-form

A React component package to create customizable, multi-step forms. This package includes a StepsController component for managing form steps, validation, and responsiveness.

Features

  • Create customizable multi-step forms.
  • Add custom validation logic for step transitions.
  • Responsive design with configurable breakpoints.
  • Supports custom class names for styling.

Installation

Install the package via npm:

npm install react-multistep-form

Usage

The StepsController component manages the overall structure of the multi-step form, handling transitions and validation.

Props:

PROPERTY DESCRIPTION TYPE DEFAULT isRequired
title The title displayed at the top of the form. string '' false
breakpoint The width breakpoint for responsive design. number 1119 false
manageNextStep A function that manages validation logic before moving to function () => true false
the next step.
steps An array of step, each containing a component to render. Array [] true

Example

Here is an example of how to use the StepsController component:

import React from 'react';
import StepsController from 'react-multiste-form';

const steps = [
    <StepOneForm />,
    <StepTwoForm />,
    <StepThreeForm />
];

const manageNextStepValidation = (currentStep, formData) => {
    // Example validation logic
    if (currentStep === 1 && !formData.name) {
        return false; // Prevent navigation if name is not provided
    }
    return true;
};

const MyForm = () => (
    <StepsController
        title="Add a new company"
        breakpoint={856}
        manageNextStepValidation={manageNextStepValidation}
        steps={steps}
    />
);

export default MyForm;

Custom Validation:

The manageNextStepValidation function takes two arguments: the currentStep (number) and formData (object). Return true to allow navigation to the next step, or false to block it based on your custom validation logic.

const manageNextStepValidation = (currentStep, formData) => {
    // Validation logic
    return true; // or false
};

Breakpoint:

Use the breakpoint prop to define the width at which the form layout will switch from a desktop view to a mobile-friendly layout.

License

This project is licensed under the MIT License.