New Contrast Pro UI Kit and template with 5 admin dashboards, 23 pages and 10000+ components for $49 ($50 off)🎉
postImage

How to create a beautiful stepper using bootstrap and Contrast

blogImage

By Emmanuel Chinonso

Web Developer

How to create a stepper component in react using bootstrap and Contrast.

Stepper is a component that displays content as a process with defined by user milestones. Following steps are separated and connected by buttons. This is a great solution for a variety of registration forms, where you don't want to scare the user with loads of fields and questions. Stepper can be aligned vertically as well as horizontally.

Examples of React Bootstrap steps use:

  • Registration form
  • Payment gateway
  • Tutorial with steps

We are going to look at how to create this stepper today using a react library known as contrast.

Contrast also known as CDBReact is a react library which is an Elegant UI kit with full bootstrap support that has reusable components for building mobile-first, responsive websites, and web apps.

To use stepper you need to download the pro version here.

Prerequisites

The stepper would be built using React, Bootstrap, and CDBReact. You don’t need to have any previous knowledge of CDBReact but the following are necessary:

  • Basic React Knowledge
  • JavaScript knowledge
  • Basic Bootstrap knowledge
  • NPM installed

Setup

First Check that you have node installed. To do this, run the following command in your terminal.

Code:

node-v

This should show you the current version of node you have installed on your machine. If you don’t have nodejs installed, download it here. Installing node also installs npm on your PC but you can still confirm using npm-v. Now that we have node installed, we can start up our React project by going to the directory of our choice and running

Code:

npx create-react-app stepper-app

I named the project Stepper-app but you can use any name of your choice.

Install CDBReact

Now, we have to install CDBReact in our project Run the following command to install CBDReact

npm install --save cdbreact

Or using Yarn

yarn add cdbreact

Note that we don’t need to install bootstrap or add it anywhere in our project as CDBReact does that for us upon installation.

Stepper

We can now create a file named stepper.js. This is where we are going to import the stepper and other components. This is also where we will be writing our code. The contrast stepper component must first be imported before using it.

Code:

import React from "react";
import { CDBStepper, CDBStep, CDBInput, CDBBtn, CDBContainer } from "cdbreact";

In the code we imported some imported components we need to build a stepper. They include

  • CDBStepper
  • CDBStep
  • CDBInput
  • CDBBtn
  • CDBContainer

Code:

const Stepper = () => {
return (
<CDBContainer>
<CDBContainer style={{ height: "500px", width: "150px" }}>
<CDBStepper direction="vertical">
<CDBStep
id={1}
far
icon="folder-open"
name="Basic Information"
handleClick={() => this.handleNextPrevClick(1)}
active={this.state.active}
/>
<CDBStep
id={2}
icon="pencil-alt"
name="Personal Data"
handleClick={() => this.handleNextPrevClick(2)}
active={this.state.active}
/>
<CDBStep
id={3}
icon="dragon"
name="Terms and Conditions"
handleClick={() => this.handleNextPrevClick(3)}
active={this.state.active}
/>
<CDBStep
id={4}
icon="check"
name="Finish"
handleClick={() => this.handleNextPrevClick(4)}
active={this.state.active}
/>
</CDBStepper>
</CDBContainer>
<CDBContainer
style={{
height: "500px",
width: "100%",
display: "flex",
alignItems: "center",
}}
>
{this.state.active === 1 && (
<CDBContainer md="12">
<h3
className="font-weight-bold pl-0 my-4 "
style={{
width: "100%",
fontSize: "30px",
textAlign: "center",
}}
>
Your Information
</h3>
<CDBInput label="Email" className="mt-4" />
<CDBInput label="username" className="mt-4" />
<CDBInput label="Password" className="mt-4" />
<CDBInput label="Repeat Password" className="mt-4" />
<CDBBtn
color="dark"
block
flat
className="float-right"
onClick={() => this.handleNextPrevClick(2)}
>
Next
</CDBBtn>
</CDBContainer>
)}
{this.state.active === 2 && (
<CDBContainer md="12">
<h3
className="font-weight-bold pl-0 my-4"
style={{
width: "100%",
fontSize: "30px",
textAlign: "center",
}}
>
Personal Data
</h3>
<CDBInput label="First Name" className="mt-3" />
<CDBInput label="Second Name" className="mt-3" />
<CDBInput label="Surname" className="mt-3" />
<CDBInput label="Address" type="textarea" rows="2" />
<CDBBtn
color="light"
flat
className="float-left"
onClick={() => this.handleNextPrevClick(1)}
>
Previous
</CDBBtn>
<CDBBtn
color="dark"
flat
className="float-right"
onClick={() => this.handleNextPrevClick(3)}
>
Next
</CDBBtn>
</CDBContainer>
)}
{this.state.active === 3 && (
<CDBContainer md="12">
<h3
className="font-weight-bold pl-0 my-4"
style={{
width: "100%",
fontSize: "30px",
textAlign: "center",
}}
>
Terms and conditions
</h3>
<CDBInput
label="I agreee to the terms and conditions"
type="checkbox"
id="checkbox3"
/>
<CDBInput
label="I want to receive newsletter"
type="checkbox"
id="checkbox4"
/>
<CDBBtn
color="light"
className="float-left"
flat
onClick={() => this.handleNextPrevClick(2)}
>
Previous
</CDBBtn>
<CDBBtn
color="dark"
className="float-right"
flat
onClick={() => this.handleNextPrevClick(4)}
>
Next
</CDBBtn>
</CDBContainer>
)}
{this.state.active === 4 && (
<CDBContainer md="12">
<h3
className="font-weight-bold pl-0 my-4"
style={{
width: "100%",
fontSize: "30px",
textAlign: "center",
}}
>
Finish
</h3>
<h2 className="text-center font-weight-bold my-4">
Registration completed!
</h2>
<CDBBtn
color="light"
flat
className="float-left"
onClick={() => this.handleNextPrevClick(3)}
>
Previous
</CDBBtn>
<CDBBtn
color="success"
flat
className="float-right"
onClick={this.handleSubmission}
>
submit
</CDBBtn>
</CDBContainer>
)}
</CDBContainer>
</CDBContainer>
);
};
export default Stepper;

In the above code, we added styling to the various components we have imported to create the stepper.

Code

import './App.css';
import tab from './stepper';
function App() {
return (
<Router>
<div className="App">
< Stepper />
</div>
</Router>
);
}
export default App;

Conclusion

Building a stepper using contrast is quite simple and allows you to use several tools including bootstrap styling without installing bootstrap to create your stepper. You can also check out some other features you can use in CDBReact Stepper Docs . you can also check the code here in our github.

Create Stunning websites and web apps

Building different custom components in react for your web apps or websites can get very stressful. Thats why we decided to build contrast. We have put together a UI kit with over 10000+ components, 5 admin dashboards and 23 additional different pages template for building almost any type of web app or webpage into a single product called Contrast Pro.Try contrast pro

ad-banner

Contrast React Bootstrap PRO is a Multipurpose pro template, UI kit to build your next landing, admin, SAAS, prelaunch, etc project with a clean, well documented, well crafted template and UI components.Learn more about Contrast Pro

Share Post:

Comments

...