- Plugins
- Stepper
Plugins
Tailwind CSS Stepper
Dynamic stepper plugin that guides users through the steps of a task.
Installation
To get started, install Stepper plugin via npm, else you can skip this step if you are already using Preline UI as a package.
npm i @preline/stepper
Basic usage
Prefer to create your own style? Here is a completely unstylized example.
<div data-hs-stepper>
<div class="hs-stepper-active:text-blue-500 hs-stepper-success:text-blue-500" data-hs-stepper-nav-item='{
"index": 1
}'>
1 Step
</div>
<div class="hs-stepper-active:text-blue-500 hs-stepper-success:text-blue-500" data-hs-stepper-nav-item='{
"index": 2
}'>
2 Step
</div>
<div class="hs-stepper-active:text-blue-500 hs-stepper-success:text-blue-500" data-hs-stepper-nav-item='{
"index": 3
}'>
3 Step
</div>
<div data-hs-stepper-content-item='{
"index": 1
}' style="display: none;">
First content.
</div>
<div data-hs-stepper-content-item='{
"index": 2
}' style="display: none;">
Second content.
</div>
<div data-hs-stepper-content-item='{
"index": 3
}' style="display: none;">
Third content.
</div>
<div data-hs-stepper-content-item='{
"isFinal": true
}' style="display: none;">
Final content.
</div>
<button class="hs-stepper-disabled:opacity-50" type="button" data-hs-stepper-back-btn>
Back
</button>
<button type="button" data-hs-stepper-skip-btn style="display: none;">
Skip
</button>
<button type="button" data-hs-stepper-next-btn>
Next
</button>
<button type="button" data-hs-stepper-finish-btn style="display: none;">
Finish
</button>
<button type="reset" data-hs-stepper-reset-btn style="display: none;">
Reset
</button>
</div>
Methods
The HSStepper
object is contained within the global window
object
Randomize an error state (public method).
const stepper = new HSStepper(document.querySelector('#stepper'));
let errorState = 1;
stepper.on('beforeNext', (index) => {
if (index === 2) {
stepper.setProcessedNavItem(index);
setTimeout(() => {
stepper.unsetProcessedNavItem(index);
stepper.enableButtons();
if (errorState) {
stepper.goToNext();
} else {
stepper.setErrorNavItem(index);
}
errorState = !errorState;
}, 2000);
}
});
Randomize an error state (mixed).
const stepper = HSStepper.getInstance('#stepper');
let errorState = 1;
stepper.on('beforeNext', (index) => {
if (index === 2) {
stepper.setProcessedNavItem(index);
setTimeout(() => {
stepper.unsetProcessedNavItem(index);
stepper.enableButtons();
if (errorState) {
stepper.goToNext();
} else {
stepper.setErrorNavItem(index);
}
errorState = !errorState;
}, 2000);
}
});
Events
An example when a function is run before the next step.
const el = HSStepper.getInstance('#stepper');
el.on('next', (currentIndex) => {...});
Demo examples
Looking for prebuilt UI components based on the Tailwind CSS? Preline UI packs hundreds of component examples for all your website needs.
Check out Preline UI Components