A simple stepper provides a wizard-like workflow by dividing content into logical steps.

Overview

react-basic-stepper

A simple stepper provides a wizard-like workflow by dividing content into logical steps.

step1

Install

npm install --save react-basic-stepper

Usage

The react-basic-stepper provide a two component to recreate a wizard-like workflow by dividing content into logical steps. You have Stepper that is the wrapper steps components and the Step component. You must import the styles of these components

import 'react-basic-stepper/dist/index.css';

1. Simple basic usage

...
import { Stepper, Step } from 'react-basic-stepper';
import 'react-basic-stepper/dist/index.css';
...
return (
    <Stepper>
        <Step>
            <h3>Step1</h3>
        </Step>
        <Step>
            <h3>Step2</h3>
        </Step>
         <Step>
            <h3>Step3</h3>
        </Step>
    </Stepper>
    )

step1 You can set labels for each Step component

Step1

Step2

Step3

) ">
...
import { Stepper, Step } from 'react-basic-stepper';
import 'react-basic-stepper/dist/index.css';
...
return (
    <Stepper>
        <Step label="Step1">
            <h3>Step1</h3>
        </Step>
        <Step label="Step1">
            <h3>Step2</h3>
        </Step>
        <Step label="Step1">
            <h3>Step3</h3>
        </Step>
    </Stepper>
        )

2. Vertical Stepper with labels for each step

 ...
return (
    <Stepper mode='vertical'>
        <Step label='Step #1'>
            <h3>Step1</h3>
         </Step>
         <Step label='Step #2'>
            <h3>Step2</h3>
            <p>
              Lorem, ipsum dolor sit amet consectetur adipisicing elit. Quidem
              nesciunt eum, error explicabo alias, architecto beatae, ducimus
              vitae optio repellat minima iure id quisquam eius voluptatem
              voluptates. Iusto, accusamus mollitia!
            </p>
         </Step>
        <Step label='Step #3'>
            <h3>Step3</h3>
            <p>
              Lorem, ipsum dolor sit amet consectetur adipisicing elit. Quidem
              nesciunt eum, error explicabo alias, architecto beatae, ducimus
              vitae optio repellat minima iure id quisquam eius voluptatem
              voluptates. Iusto, accusamus mollitia!
            </p>
            <p>
              Lorem, ipsum dolor sit amet consectetur adipisicing elit. Quidem
              nesciunt eum, error explicabo alias, architecto beatae, ducimus
              vitae optio repellat minima iure id quisquam eius voluptatem
              voluptates. Iusto, accusamus mollitia!
            </p>
         </Step>
    </Stepper>
    )

step1

3. Stepper wizzard component

For the creation of medium and complex wizards, the Step component has a property disabled to disable its access based on logical conditions. The Stepper component has a linear property that allows access only to the immediate next step. To control the action of the next and previous steps, you can use a ref to pointer the Stepper and set nextStep and prevStep programmatically.

...
import { Step, Stepper, StepperRef } from 'react-basic-stepper';
function StepperControlled(): JSX.Element {
  ....
  const [mode, setMode] = useState<any>(window.innerWidth < 756 ? 'vertical' : 'horizontal');
  const stepper = useRef<StepperRef>();
  ...
  return (
  <Stepper ref={stepper} mode={mode}>
      <Step label='User Data'>
        <ComponentForm1></ComponentForm1>
        <Button onClick={() => {
            if (!componentForm1DataValid) {
              alert('ComponentFrom1 data form must be valid');
              return;
            }
            stepper.current?.nextStep();
          }}>Next</Button>
      </Step>
    <Step label='Email' disabled={!componentForm1DataValid}>
      <ComponentForm2></ComponentForm2>
      <Button
          style={{ marginRight: '8px', backgroundColor: '#aaa' }}
          onClick={() => {
            stepper.current?.prevStep();
          }}>Back</Button>
      <Button onClick={() => {
            if (!componentForm1DataValid) {
              alert('ComponentForm1Data data form must be valid');
              return;
            }
            stepper.current?.nextStep();
          }}>Next</Button>
    </Step>
    <Step disabled={!componentForm1DataValid || !componentForm2DataValid}
      label='Materials selected'>
       <ComponentForm3></ComponentForm3>
       <Button style={{ marginRight: '8px', backgroundColor: '#aaa' }}
          onClick={() => {
            stepper.current?.prevStep();
          }}>Back</Button>
       <Button
          onClick={() => {
            if (!componentForm3DataValid) {
              alert('ComponentForm3 data form must be valid');
              return;
            }
            stepper.current?.nextStep();
          }}
        >Next</Button>
    </Step>
    <Step
      disabled={!componentForm1DataValid || !componentForm2DataValid || !componentForm3DataValid}
      label='Done'
    >
      <Button
        style={{ marginRight: '8px', backgroundColor: '#aaa' }}
        onClick={() => {
          stepper.current?.prevStep();
        }}
      >
        Back
      </Button>
      <Button> Save</Button>
    </Step>
  </Stepper>
  }

step1

The Stepper component has props to customize some styles of the steps header sections

export interface HeaderStepStyles {
  color?: string; // Setting the color of the circles.
  activatedStepBackground?: string; // Setting the backgroundColor of the current circle (Current Step).
  stepsBackgroud?: string; // Setting the backgroundColor of the circles except the circle associated with the current step on.
  lineColor?: string; // Setting the color of the line between of the steps circles
}

Example of a Stepper with the red color activated and the blue line between the circles

...
import { Stepper, Step } from 'react-basic-stepper';
...
return (
    <Stepper
          headerStyles={{
            activatedStepBackground: 'red',
            color: '#fff',
            lineColor: 'blue'
          }}
        >
          <Step>
            <h3>Step1</h3>
          </Step>
          <Step>
            <h3>Step2</h3>
          </Step>
          <Step>
            <h3>Step3</h3>
          </Step>
          <Step>
            <h3>Step4</h3>
          </Step>
        </Stepper>
)

step4

4. Stepper Interfaces

export interface StepperProps {
  children: Array<ReactElement> | ReactElement | any; // Steps component inside the Stepper
  indexStep?: number; // Set the initial activated Step, default = 0
  stepChange?: Function; // Callback function that return the current step on
  headerStyles?: HeaderStepStyles; // Object to change the styles of the Stepper header
  linearMode?: boolean; // Linear mode for the transitions of each step, default = false
  verticalLabels?: boolean; // Allow Step header text labels to be placed at the bottom or to the right of the circles, default = true
  hideLabels?: boolean; // Allow to hide the text labels, default = false
  hideLines?: boolean; // Allow to hide the line between each step header circles, default = false
  mode?: 'vertical' | 'horizontal'; // Allow to display the stepper 'vertical' or 'horizontal', default = 'horizontal'
}
export interface StepperRef {
  nextStep: Function; // function in the ref object of the Stepper which sets the next step programmatically
  prevStep: Function; // function in the ref object of the Stepper which sets the previous step programmatically
}

export interface Steps {
  children?: any; // Any JSX.Element or ReactElement to render inside the Step component
  label?: string; // Label to be displayed in the header for every step
  disabled?: boolean | null | undefined | number | string; // allow the access to the Step, default = true
}

Demo

License

MIT © josealejandro2928

You might also like...

A web application for a company that provides commercial and scientific space travel services

A web application for a company that provides commercial and scientific space travel services. The application allows users to book rockets and join selected space missions using real live data from the SpaceX API.

Apr 5, 2022

GitHub action that compares basehead commits and provides all changed files in a pull request or push.

Get PR/push Files Get all added/modified/removed/renamed files in a pull request or push's commits. You can choose to get all files, only added files,

May 21, 2022

A web application for a company that provides commercial and scientific space travel services. The application allows users to book rockets and join selected space missions.

Space Travelers' Hub A web application for a company that provides commercial and scientific space travel services. The application allows users to bo

Oct 14, 2022

A simple and responsive quizlet-like flashcard component with a few additional options

A simple and responsive quizlet-like flashcard component with a few additional options

Welcome to react-quizlet-flashcard 👋 A simple and responsive quizlet-like flashcard component with a few additional options. Front and back card acce

Dec 17, 2022

A set of higher-order components to turn any list into an animated, accessible and touch-friendly sortable list✌️

A set of higher-order components to turn any list into an animated, accessible and touch-friendly sortable list✌️

A set of higher-order components to turn any list into an animated, accessible and touch-friendly sortable list Examples available here: http://claude

Jan 2, 2023

Transform SVGs into React components 🦁

Transform SVGs into React components 🦁

Transform SVGs into React components 🦁 Try it out online! Watch the talk at React Europe SVGR transforms SVG into ready to use components. It is part

Jan 3, 2023

Tina is an open source editor that brings visual editing into React websites. Tina empowers developers to give their teams a contextual and intuitive editing experience without sacrificing code quality.

Tina is an open source editor that brings visual editing into React websites. Tina empowers developers to give their teams a contextual and intuitive editing experience without sacrificing code quality.

Tina is an open-source toolkit for building content management directly into your website. Community Forum Getting Started Checkout the tutorial to ge

Jan 1, 2023

Grid-tool - Small tool that allows you to integrate a predefined or generated grid into your front-end development environment.

Grid tool Small tool that allows you to integrate a predefined or generated grid into your front-end development environment. Tool installation includ

Jan 4, 2022

🌀 Insert Awesome Shapes into Your React Site with Ease

🌀 Insert Awesome Shapes into Your React Site with Ease

React Awesome Shapes 🌀 Insert Awesome Shapes into Your React Site with Ease. Loved the project? Please consider donating to help it improve! Consider

Dec 30, 2022
Owner
Jose Alejandro Concepción Álvarez
Jose Alejandro Concepción Álvarez
Eisen Matrix - a prioritization app that uses Eisenhower matrix technique as workflow to prioritize a list of tasks & built with React Native

Eisen Matrix is a prioritization app that uses Eisenhower matrix technique as workflow to prioritize a list of tasks & built with React Native for learning purposes inspired by Einsen which is written in Kotlin.

Nafees Nazik 11 Nov 28, 2022
Expo Demo: Screen Capture with Managed Workflow

Expo Demo: Screen Capture with Managed Workflow This code demonstrates how to setup screen capture on an Expo app, without having to eject from the ma

Luis Taniça 12 Dec 30, 2022
Next-gen, highly customizable content editor for the browser - based on React and Redux and written in TypeScript. WYSIWYG on steroids.

ReactPage ReactPage is a smart, extensible and modern editor ("WYSIWYG") for the web written in React. If you are fed up with the limitations of conte

null 9.1k Jan 6, 2023
An experimental hover effect, where a content preview is shown while a mini map indicates the position of the cursor.

Hover Preview Effect with Mini Map An experimental hover effect, where a content preview is shown while a mini map indicates the position of the curso

Codrops 27 Dec 29, 2022
Recoil is an experimental state management library for React apps. It provides several capabilities that are difficult to achieve with React alone, while being compatible with the newest features of React.

Recoil · Recoil is an experimental set of utilities for state management with React. Please see the website: https://recoiljs.org Installation The Rec

Facebook Experimental 18.2k Jan 8, 2023
nivo provides a rich set of dataviz components, built on top of the awesome d3 and Reactjs libraries

nivo provides supercharged React components to easily build dataviz apps, it's built on top of d3. Several libraries already exist for React d3 integr

Raphaël Benitte 10.9k Dec 31, 2022
Mobile app development framework and SDK using HTML5 and JavaScript. Create beautiful and performant cross-platform mobile apps. Based on Web Components, and provides bindings for Angular 1, 2, React and Vue.js.

Onsen UI - Cross-Platform Hybrid App and PWA Framework Onsen UI is an open source framework that makes it easy to create native-feeling Progressive We

null 8.7k Jan 8, 2023
a react-based framework that provides accessibility, modularity, responsiveness, and theming in a tidy package

Grommet: focus on the essential experience Documentation Visit the Grommet website for more information. Support / Contributing Before opening an issu

grommet 8.1k Jan 5, 2023
An Ember CLI Addon that provides a variety of UI components.

We use https://waffle.io/softlayer/sl-ember-components to work our issues. What sl-ember-components is An Ember CLI Addon that provides UI components

SoftLayer 115 May 7, 2022
A web application for a company that provides commercial and scientific space travel services.

Space Traveler's Hub Space Traveler's Hub is a project built with React redux, implemented with Ducks files structure and, React Router to interact be

Ismael Antonio 6 Mar 15, 2022