1.0.4 • Published 8 months ago

multistep-react-form v1.0.4

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

multistep-react-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 multistep-react-form

Usage

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

Props:

PROPERTYDESCRIPTIONTYPEDEFAULTisRequired
titleThe title displayed at the top of the form.string''false
breakpointThe width breakpoint for responsive design.number1119false
manageNextStepA function that manages validation logic.function() => truefalse
stepsAn array of steps, 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 'multistep-react-form';

const steps = [
    <StepOneForm formData={formData} validationError={validationError} handleFieldChange={handleFieldChange} />,
    <StepTwoForm formData={formData} validationError={validationError} handleFieldChange={handleFieldChange} />,
    <StepThreeForm formData={formData} validationError={validationError} handleFieldChange={handleFieldChange} />
];

const manageNextStep = (currentStep) => {
    // 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}
        manageNextStep={manageNextStep}
        steps={steps}
    />
);

export default MyForm;

Custom Validation:

The manageNextStep 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 manageNextStep = (currentStep) => {
    // 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.

1.0.4

8 months ago

1.0.3

10 months ago

1.0.2

10 months ago

1.0.1

10 months ago

1.0.0

10 months ago