npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

react-multistep-wizard-form

v1.0.3

Published

react-multistep-wizard-form is a flexible and easy-to-use React component for creating multi-step forms or wizards.

Downloads

264

Readme

MultiStep Wizard Form

react-multistep-wizard-form is a versatile React component that simplifies creating multi-step forms. It allows you to easily manage complex forms with multiple sections and dynamic navigation.

Demo

You can see a live demo of the component here. Source code of demo component here

Installation

To install the package, use npm or yarn:

npm install react-multistep-wizard-form

or

yarn add react-multistep-wizard-form

Usage

Import Components You can import the following components and hooks from the package:

import {
  WizardForm,
  WizardSections,
  useWizardForm,
} from "react-multistep-wizard-form";

Basic Usage

Wrap your form sections with WizardForm and WizardSections. Pass the onSubmitWizardForm function to WizardForm to handle form submission.

<WizardForm onSubmitWizardForm={() => setFormSubmitted(true)}>
  <WizardSections>
    <NameSection />
    <ContactSection />
    {showAddressSection && <AddressSection />}
  </WizardSections>
</WizardForm>

Custom Navigation

You can create a custom navigation indicator using the useWizardForm hook:

const CustomNav = () => {
  const { totalWizardSteps, currWizardStep } = useWizardForm();

  if (totalWizardSteps <= 1) return null;

  const getClass = (idx: number) =>
    idx === currWizardStep
      ? "CurrentSection"
      : idx < currWizardStep
      ? "section-completed"
      : "Section-not-completed";

  return (
    <div className="CustomNav">
      {Array.from({ length: totalWizardSteps }).map((_, idx) => (
        <div className="CustomNavGroup" key={"CustomNav-" + idx}>
          <div className={`Circle ${getClass(idx)}`}>{idx + 1}</div>
          {idx + 1 !== totalWizardSteps && <div className="Bar"></div>}
        </div>
      ))}
    </div>
  );
};

Use the custom navigation in your WizardForm:

<WizardForm onSubmitWizardForm={() => setFormSubmitted(true)}>
  <CustomNav />
  <WizardSections>
    <NameSection />
    <ContactSection />
  </WizardSections>
</WizardForm>

Hooks

The useWizardForm hook provides the following functionalities:

  1. totalWizardSteps: Returns the total number of steps in the wizard form. This is useful for rendering progress indicators or navigation elements.

  2. currWizardStep: Returns the index of the current step being displayed. This can be used to highlight the current step or manage conditional rendering.

  3. isFirstWizardStep: A boolean value that indicates whether the current step is the first step. This can be used to conditionally disable or hide the "Previous" button.

  4. isLastWizardStep: A boolean value that indicates whether the current step is the last step. This can be used to conditionally disable or hide the "Next" button or display a submit button.

  5. isWizardFormSubmitted: A boolean value that indicates whether the wizard form has been submitted. This value becomes true when the form is successfully submitted, either through user action or programmatic submission.

  6. nextWizardStep: A function to move to the next step in the wizard. This function should be called when the user clicks a "Next" button or when you programmatically want to advance to the next step.

  7. previousWizardStep: A function to move to the previous step in the wizard. This function should be called when the user clicks a "Previous" button or when you programmatically want to go back to the previous step.

  8. submitWizardForm: A function that triggers the form submission process programmatically. This function can be used to submit the form and invoke the onSubmitWizardForm callback.

Contributing

We welcome contributions to this project! If you would like to contribute, please visit our GitHub repository for more information on how to get started.

License

This project is licensed under the MIT License. See the LICENSE file for details.