@dfinity/gix-components
Version:
A UI kit developed by the GIX team
35 lines (34 loc) • 865 B
JavaScript
export class WizardStepsState {
currentStep;
currentStepIndex = 0;
previousStepIndex = 0;
steps;
constructor(steps) {
this.steps = steps;
this.currentStep = this.steps[0];
}
next() {
if (this.currentStepIndex < this.steps.length - 1) {
this.move(this.currentStepIndex + 1);
}
return this;
}
get diff() {
return this.currentStepIndex - this.previousStepIndex;
}
back() {
if (this.currentStepIndex > 0) {
this.move(this.currentStepIndex - 1);
}
return this;
}
set(newStep) {
this.move(newStep);
return this;
}
move(nextStep) {
this.previousStepIndex = this.currentStepIndex;
this.currentStepIndex = nextStep;
this.currentStep = this.steps[this.currentStepIndex];
}
}