Socket
Socket
Sign inDemoInstall

react-dynamic-stepper

Package Overview
Dependencies
5
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    react-dynamic-stepper

Advanced and multi-feature react stepper component designed to be incredibly versatile for a variety of workflows and use cases.


Version published
Weekly downloads
5
increased by66.67%
Maintainers
1
Created
Weekly downloads
 

Changelog

Source

1.0.3 (2024-01-23)

Bug Fixes

  • stepperfooter.tsx: update navigate to next step functionality (40938d5)

Readme

Source

Table of Contents:

Overview:

Advanced and multi-feature stepper component designed to be incredibly versatile for a variety of workflows and use cases.

It supports the following:

  • Horizontal stepper UI.
  • Vertical stepper UI.
  • Inline stepper UI.
  • Sequence stepper.
  • Right to left languages.
  • Custom pallet.
  • Custom header.
  • Custom footer.
  • Navigate to the required step programmatically.

Back to top

Demo:

Checkout the demo of this package on codepen

Back to top

Installation:

  • Via npm:
npm install react-dynamic-stepper
  • Via yarn:
yarn add react-dynamic-stepper
  • Via pnpm:
pnpm add react-dynamic-stepper

Back to top

Usage:

import { Stepper } from 'react-dynamic-stepper';

const App = () => {
  const steps = [
          {
            header: {
              label: 'Step 1',
            },
            content: <div>First step content</div>,
            isError: false,
            isWarning: false,
            isComplete: true,
          },
          {
            header: {
              label: 'Step 2',
            },
            content: <div>Second step content</div>,
            onClickHandler: () => console.log('clicked on second step next button'),
            isLoading: false,
            isError: false,
            isComplete: true,
          },
          {
            header: {
              label: 'Step 3',
            },
            content: <div>Third step content</div>,
            isError: false,
            isComplete: true,
          },
        ];

  const submitStepper = () => {
    console.log('submitted');
  };

  return (
    <Stepper
      steps={steps}
      footerData={{
        submitHandler: submitStepper,
      }}
    />
  );
};

Back to top

Stepper props:

PropTypeDefaultRequiredDescription
isRightToLeftLanguageBooleanfalseNoIf true, sets the direction of the stepper to rtl
isVerticalBooleanfalseNoIf true, sets the orientation of the stepper to vertical
isInlineBooleanfalseNoIf true, sets the header display of the stepper to inline
isSequenceStepperBooleanfalseNoIf true, sets the stepper to sequence mode (forces the user to complete steps in sequence)
isStepConnectorBooleantrueNoIf false, removes the step connector
refuseRef<NavigateToStepHandler>nullNoIt exposes navigateToStep function, that can programmatically navigate the user to a specific step
stepsStepInterface[]-YesArray of steps
footerDataFooterDataInterface[]-YesFooter data
palletPalletInterface[]-NoPallet for custom color codes

Back to top

StepInterface:

PropTypeDefaultRequiredDescription
header.labelString-YesThe label to display on the step header
header.indicatorReactNodeStep numberNoCustom indicator for the step
contentReactNode-YesThe content to display for the step
onClickHandlerFunction: () => void or () => Promise<void>-NoInvoked when the next button of the current step is clicked
isLoadingBooleanfalseNoIf true, the 'Next' button will be disabled
isErrorBooleanfalseNoIf true, will display the step with error UI
isWarningBooleanfalseNoIf true, will display the step with warning UI
isCompleteBooleanfalseYesIf true, will display the step with completed UI and enables 'Next' button

Back to top

FooterDataInterface:

PropTypeDefaultRequiredDescription
prevBtnLabelStringBack to ${prevStepLabel}NoLabel for the prev button
prevBtnClassNameStringundefinedNoCSS classname(s) to be applied to prev button
nextBtnLabelStringContinue to ${nextStepLabel}NoLabel for the next button
nextBtnClassNameStringundefinedNoCSS classname(s) to be applied to next button
submitBtnLabelStringSubmitNoLabel for submit button in the last step
submitBtnClassNameStringundefinedNoCSS classname(s) to be applied to the submit button in the last step
submitHandlerFunction: () => void or () => Promise<void>-YesInvoked when the submit button is clicked

Back to top

PalletInterface:

PropTypeDefaultRequiredDescription
defaultString#627c90YesDefault color code
warningString#f1c40fYesColor code for warning UI
dangerString#e95a4bYesColor code for error UI
successString#4caf50YesColor code for success UI

Back to top

Features and Methods

Navigate to step programmatically:

The ref passed to the Stepper component exposes a navigateToStep function, that can programmatically navigate the user to a specific step. It can be useful in scenarios when controlling step navigation from outside the Stepper component is required.

Important Note:

Make sure to mark the required steps as completed if you want to navigate programmatically so that you can submit your stepper. This ensures that all necessary steps have been taken before the finish line.

JavaScript
import { useRef } from 'react';
import { Stepper } from 'react-dynamic-stepper';

const App = () => {
  const stepperRef = useRef(null);

  return (
    <>
      <button
        onClick={() => {
          stepperRef.current?.navigateToStep(1);
        }}
      >
        Navigate to step 2 programmatically
      </button>
      <Stepper
        ref={stepperRef}
        /* OTHER PROPS */
      />
    </>
  );
};
TypeScript
import { useRef } from 'react';
import { Stepper, NavigateToStepHandler } from 'react-dynamic-stepper';

const App = () => {
  const stepperRef = useRef<NavigateToStepHandler>(null);

  return (
    <>
      <button
        onClick={() => {
          stepperRef.current?.navigateToStep(1);
        }}
      >
        Navigate to step 2 programmatically
      </button>
      <Stepper
        ref={stepperRef}
        /* OTHER PROPS */
      />
    </>
  );
};

Back to top

Invoke a function on Next button click of current step

  • step.onClickHandler => This is invoked when the 'Next' button of the current step is clicked.
  • If your onClickHandler returns a Promise and you want to navigate to the next step only if the Promise resolves successfully, you need to throw error inside the catch block:
const submitCurrentStep = async () => {
    try {
      /* Your business logic here */
    } catch (error) {
      throw error;
    } finally {
      /* Cleanup code here */
    }
  };

Back to top

Keywords

FAQs

Last updated on 23 Jan 2024

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc