JSPM

custom-react-step-progress-bar

1.0.1
  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 27
  • Score
    100M100P100Q46494F
  • License ISC

A simple react step progress bar component for multi-step forms.

Package Exports

  • custom-react-step-progress-bar

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 (custom-react-step-progress-bar) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

Installation

To install and set up the library, run:

$ npm i custom-react-step-progress-bar

Or if you prefer using Yarn:

$ yarn add custom-react-step-progress-bar

Usage

Importing custom-react-step-progress-bar

Import the custom-react-step-progress-bar component into your React application:

import ProgressBar from "custom-react-step-progress-bar";
Example with custom-react-step-progress-bar
import React, { useState } from "react";
import { Route, withRouter } from "react-router";
import ProgressBar from "custom-react-step-progress-bar";

const stepperComponent = props => {
  const { path } = props.match;
  const [step, setStep] = useState(0);
  const [stepOne, setStepOne] = useState(false);
  const [stepTwo, setStepTwo] = useState(false);
  const [stepThree, setStepThree] = useState(false);

  const onStepThreeClick = () => {
    setStep(2);
    props.history.push(`${path}/step-3`);
  };

  const onStepTwoClick = () => {
    setStep(1);
    console.log(path);
    props.history.push(`${path}/step-2`);
  };

  const onStepOneClick = () => {
    setStep(0);
    props.history.push(path);
  };

  const progressBarMenu = [
    {
      stepName: "Step One",
      onClick: onStepOneClick,
      completeStep: stepOne,
    },
    {
      stepName: "Step Two",
      onClick: onStepTwoClick,
      completeStep: stepTwo,
    },
    {
      stepName: "Step Three",
      onClick: onStepThreeClick,
      completeStep: stepThree,
    },
  ];
  const StepOneDetails = () => {
    return (
      <div>
        <p>step 1</p>
        <button
          onClick={() => {
            setStepOne(true);
            onStepTwoClick();
          }}
        >
          done
        </button>
      </div>
    );
  };

  const StepTwoDetails = () => {
    return (
      <div>
        <p>step 2</p>
        <button
          onClick={() => {
            setStepTwo(true);
            onStepThreeClick();
          }}
        >
          done
        </button>
      </div>
    );
  };

  const StepThreeDetails = () => {
    return (
      <div>
        <p>step 3</p>
        <button
          onClick={() => {
            setStepThree(true);
          }}
        >
          done
        </button>
      </div>
    );
  };

  return (
    <div>
      <div className="add-patients-header">
        <ProgressBar progressBarMenu={progressBarMenu} currentActive={step} />
      </div>
      <div className="add-patient-children">
        <Route exact path={`${path}`} component={StepOneDetails} />
        <Route exact path={`${path}/step-2`} component={StepTwoDetails} />
        <Route exact path={`${path}/step-3`} component={StepThreeDetails} />
      </div>
    </div>
  );
};

export default withRouter(stepperComponent);

In the above example,we xan see how to use the custom-react-step-progress-bar.

The above example is with function-based component , you can also use class-based component.

In these step-progress-bar it is necessary to add onClick and completeStep in progressBarMenu list, stepName and image are the optional fields.

Authors

Shubham Gapat - GitHub

License

None