Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

bs-stepper

Johann-S137.9kMIT1.7.0TypeScript support: included

A stepper for Bootstrap 4

bootstrap, bootstrap 4, vanillajs, react, angular, stepper

readme

bs-stepper

npm version dependencies Status devDependencies Status Build Status Coveralls github branch JavaScript Style Guide JS gzip size CSS gzip size

A stepper plugin for Bootstrap 4.

You can use it on React and Angular too because this plugin is written with the most used JavaScript framework: VanillaJS.

Demo

If you want to see our last changes it's here: https://bs-stepper.netlify.com/

Features:

  • Linear stepper
  • Non linear stepper
  • Fade effect with .fade
  • Vertical stepper
  • Works with Bootstrap 4
  • Accessible
  • Works without dependencies (so no jQuery needed)
  • Built in UMD to be used everywhere
  • Small, only 2kb

Table of contents

Install

With npm or yarn

// npm
npm install bs-stepper --save

// yarn
yarn add bs-stepper

CDN

CDN Link
jsDelivr, js minified https://cdn.jsdelivr.net/npm/bs-stepper/dist/js/bs-stepper.min.js
jsDelivr, css minified https://cdn.jsdelivr.net/npm/bs-stepper/dist/css/bs-stepper.min.css

How to use it

HTML markup

Include the CSS file:

<link rel="stylesheet" href="bs-stepper.min.css">

Add the following HTML:

<div class="bs-stepper">
  <div class="bs-stepper-header" role="tablist">
    <!-- your steps here -->
    <div class="step" data-target="#logins-part">
      <button type="button" class="step-trigger" role="tab" aria-controls="logins-part" id="logins-part-trigger">
        <span class="bs-stepper-circle">1</span>
        <span class="bs-stepper-label">Logins</span>
      </button>
    </div>
    <div class="line"></div>
    <div class="step" data-target="#information-part">
      <button type="button" class="step-trigger" role="tab" aria-controls="information-part" id="information-part-trigger">
        <span class="bs-stepper-circle">2</span>
        <span class="bs-stepper-label">Various information</span>
      </button>
    </div>
  </div>
  <div class="bs-stepper-content">
    <!-- your steps content here -->
    <div id="logins-part" class="content" role="tabpanel" aria-labelledby="logins-part-trigger"></div>
    <div id="information-part" class="content" role="tabpanel" aria-labelledby="information-part-trigger"></div>
  </div>
</div>
  • If you want to use the fade fade animation, add .fade class on your .content and set animation to true.
  • To create a vertical stepper, just add .vertical class on your stepper. All steppers will switch to vertical on small viewports.

JavaScript

In HTML before the end of the <body> tag

<script src="bs-stepper.min.js"></script>

Or with npm

import Stepper from 'bs-stepper'

Create a stepper

You should wait for the document ready event and create a new instance of Stepper.

Vanilla JS

document.addEventListener('DOMContentLoaded', function () {
  var stepper = new Stepper(document.querySelector('.bs-stepper'))
})

With jQuery

$(document).ready(function () {
  var stepper = new Stepper($('.bs-stepper')[0])
})

For more examples check out this file.

This library is UMD ready so you can use it everywhere.

Methods

constructor

Create an instance of Stepper, accept two parameters.

Parameters

  • element
  • type: DOMElement

Pass your Stepper DOMElement

  • options (optional)

    • type: Object

    default value:

    {
      linear: true,
      animation: false,
      selectors: {
        steps: '.step',
        trigger: '.step-trigger',
        stepper: '.bs-stepper'
      }
    }

    Allows you to customize the stepper selectors and it's behaviour.

next

Will navigate to the next step of your stepper. This method also emit show.bs-stepper before showing the step and shown.bs-stepper when the step is displayed.

var stepper = new Stepper(document.querySelector('.bs-stepper'))
stepper.next()

previous

Will navigate to the previous step of your stepper. This method also emit show.bs-stepper before showing the step and shown.bs-stepper when the step is displayed.

to

Will navigate to a step of your stepper. This method also emit show.bs-stepper before showing the step and shown.bs-stepper when the step is displayed.

var stepper = new Stepper(document.querySelector('.bs-stepper'))

/// Will navigate to the second step
stepper.to(2)

reset

Will reset you stepper to the first step (usefull for linear stepper). This method also emit show.bs-stepper before showing the step and shown.bs-stepper when the step is displayed.

destroy

Remove stored data relative to your stepper and listeners.

Events

The methods which trigger a step change trigger two events:

  • show.bs-stepper
  • shown.bs-stepper

You can listen on those events like that:

var stepperEl = document.getElementById('stepper')
var stepper = new Stepper(stepperEl)

stepperEl.addEventListener('show.bs-stepper', function (event) {
  // You can call prevent to stop the rendering of your step
  // event.preventDefault()

  console.warn(event.detail.indexStep)
})

stepperEl.addEventListener('shown.bs-stepper', function (event) {
  console.warn('step shown')
})

The event detail object contains the following properties:

{
  indexStep: contains the id of the step which will be displayed,
  to: alias of indexStep,
  from: previous step id (or current step id)
}

If you need to prevent the display of a step, you have to call preventDefault on the show.bs-stepper listener.

Compatibility

bsStepper is compatible with:

  • IE10+
  • Edge
  • Firefox
  • Chrome
  • Safari
  • Chrome Android
  • Safari iOS

You can find our BrowserStack list of browsers here.

Support me

If you want to thank me or supporting my work:

Thanks

BrowserStack Logo

Thanks to BrowserStack for providing the infrastructure that allows us to test in real browsers!

License

MIT

changelog

Changelog

All notable changes to this project will be documented in this file. See standard-version for commit guidelines.

1.7.0 (2019-07-24)

Bug Fixes

  • tests: undefined event var (ba557a2)
  • vertical: weird behavior without fade (3684792)

Features

  • events: add from and to properties in detail (16b146a)

1.6.1 (2019-06-19)

Bug Fixes

  • docs: update docs about config default values (e545b03)

1.6.0 (2019-06-19)

Bug Fixes

  • core: add unit test with custom selectors (af31361)
  • events: do not modified current step if events are prevented (5cd49d3)
  • typing: improve typescript typing (ae2f687)

Features

  • core: allow to customize stepper internal css classes (#28) (b39db02)
  • docs: add a link to the change log (7215d95)

1.5.0 (2019-03-22)

Features

  • events: dispatch show events (show and shown) (8b49845)

1.4.1 (2019-03-18)

Bug Fixes

  • selector: remove a selector (e80d3e3)

BREAKING CHANGES

1.4.0 (2019-02-26)

Bug Fixes

  • build: bump css too (c135bd5)
  • build: do not try to add dist during the process (c89e165)
  • core: adjust css for retro compatibility (0402870)
  • html: remove btn class which isn't needed (b46e048)
  • linear: fade effet wasn't applied (5c6ce96)
  • to: should handle higher value (55bcb2a)

Features

  • build: improve banners (6021e03)
  • build: improve build process (75c62ca)
  • core: rewrite css smartly (30d895c)
  • to: add a method to navigate to a specific step (f7e1add)

1.3.0 (2018-10-29)

Bug Fixes

  • accessibility: replace aria-current by aria-selected following the application of aria tab pattern (353791b)
  • accessibility: use aria attributes, and change links by buttons (4de6e32)
  • button: add padding and cursor (f197040)
  • docs: align previous button with submit (6ff73dd)
  • docs: better order for next/previous buttons (cd74f77)
  • step: remove step padding (ea048f0)
  • testing: unit tests (65f43dd)
  • unit-tests: add the required trigger id (10fed58)

Features

1.2.1 (2018-10-22)

Bug Fixes

  • css: use visibility instead of opacity (ddd53f2)

1.2.0 (2018-10-21)

Bug Fixes

  • index: remove listeners for linear stepper too (7a7862d)

Features

  • core: add vertical stepper (eca853a)
  • index: add reset method for linear stepper (a056adc)

1.1.1 (2018-10-15)

Bug Fixes

  • typing: missing animation option (806d2c1)

1.1.0 (2018-10-15)

Bug Fixes

  • fade: add d-none by default for fade steppers (cb4a14d)
  • fade: use an option to enable/disable (bd94d50)
  • typing: make stepper option optional (c10ced0)

Features

1.0.0 (2018-10-12)

Features

  • core: Linear stepper
  • core: Non linear stepper