0.1.6 • Published 2 years ago

@keyvaluesystems/react-vertical-stepper v0.1.6

Weekly downloads
-
License
ISC
Repository
github
Last release
2 years ago

React Vertical Stepper

A fully customizable ready to use vertical stepper UI package for React. Try tweaking a vertical stepper using this codesandbox link here

Installation

npm install react-vertical-stepper

You’ll need to install React separately since it isn't included in the package.

Usage

React Vertical Stepper can run in a very basic mode by just providing the steps and currentStepIndex props like this:

import  React,  {  useState  }  from  'react';
import Stepper from 'react-vertical-stepper';

function  App()  {
  const [currentStepIndex, setCurrentStepIndex] = useState(0);
  
  stepsArray = [{
      label: 'Step 1',
      description: 'This is Step 1',
      status: 'completed'
    },{
      label: 'Step 2',
      description: 'This is Step 2',
      status: 'visited'
    },{
      label: 'Step 3',
      description: 'This is Step 3',
      status: 'unvisited'
  }];

  return (
    <Stepper
      steps={stepsArray}
      currentStepIndex={currentStepIndex}
    />
  );
}

export default App;

The steps array is an array of objects with basic keys like

  • label - a string that can be shown as step label title to your step indicator
  • description - a string that can be show as step description below the step label
  • status - can be provided with any of visited, unvisited, completed. Will be required if you are using default styles.

Note: You can also add any other keys to the step object and other statuses like skipped for different customizations as per requirements

You can customize the step indicator bubble with your own DOM element using the renderBubble prop

<Stepper
  steps={stepsArray}
  currentStepIndex={currentStepIndex}
  renderBubble={(step, stepIndex) => (<div key={stepIndex}>{step.label}</div>)}
/>

The step param provided by the renderBubble callback is the same object you pass as array item in steps prop.

Props

Props that can be passed to the component are listed below:

Style Customizations

All the default styles provided by this package are overridable using the style prop the below code shows all the overridable styles:

import React from 'react';
import Stepper from 'react-vertical-stepper';

function App() {

 const stylesOverride = {
   LabelTitle: (step, stepIndex) => ({...styles}),
   ActiveLabelTitle: (step, stepIndex) => ({...styles}),
   LabelDescription: (step, stepIndex) => ({...styles}),
   ActiveLabelDescription: (step, stepIndex) => ({...styles}),
   LineSeparator: (step, stepIndex) => ({...styles}),
   InactiveLineSeparator: (step, stepIndex) => ({...styles}),
   Bubble: (step, stepIndex) => ({...styles}),
   ActiveBubble: (step, stepIndex) => ({...styles}),
   InActiveBubble: (step, stepIndex) => ({...styles}),
 };
 return (
   <Stepper
      steps={stepsArray}
      currentStepIndex={currentStepIndex}
      styles={stylesOverride}
   />
 );
}

export default App;
  • LabelTitle - overrides the step label style
  • ActiveLabelTitle - overrides the step label style of current active step
  • LabelDescription - overrides the step description style
  • ActiveLabelDescription - overrides the step description style of current active step
  • LineSeparator - overrides default step connector line styles
  • InactiveLineSeparator - overrides styles of step connector line after current active step
  • Bubble - overrides default styles of step indicator
  • ActiveBubble - overrides default styles of step indicator of current active step
  • InActiveBubble - overrides default styles of step indicator that has unvisited step status