Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Add getStepNumber option for enabling customization of step num… #2017

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/core/showElement.ts
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ export function _updateProgressBar(
*/
export default async function _showElement(
intro: IntroJs,
targetElement: IntroStep
targetElement: IntroStep,
) {
if (isFunction(intro._introChangeCallback)) {
await intro._introChangeCallback.call(intro, targetElement.element);
Expand Down Expand Up @@ -279,7 +279,7 @@ export default async function _showElement(
intro._lastShowElementTimer = window.setTimeout(() => {
// set current step to the label
if (oldHelperNumberLayer !== null) {
oldHelperNumberLayer.innerHTML = `${targetElement.step} ${intro._options.stepNumbersOfLabel} ${intro._introItems.length}`;
oldHelperNumberLayer.innerHTML = intro._options.getStepNumber(targetElement.step,intro._introItems.length,intro._options.stepNumbersOfLabel)
}

// set current tooltip text
Expand Down Expand Up @@ -421,7 +421,7 @@ export default async function _showElement(

if (intro._options.showStepNumbers === true) {
helperNumberLayer.className = "introjs-helperNumberLayer";
helperNumberLayer.innerHTML = `${targetElement.step} ${intro._options.stepNumbersOfLabel} ${intro._introItems.length}`;
helperNumberLayer.innerHTML=intro._options.getStepNumber(targetElement.step,intro._introItems.length,intro._options.stepNumbersOfLabel)
tooltipLayer.appendChild(helperNumberLayer);
}

Expand Down
5 changes: 5 additions & 0 deletions src/option.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,8 @@ export interface Options {
buttonClass: string;
/* additional classes to put on progress bar */
progressBarAdditionalClass: boolean;
/* function for creating stepNumber label */
getStepNumber:(stepIndex:number,stepsCount:number,stepNumbersOfLabel:string)=>string
}

export function getDefaultOptions(): Options {
Expand Down Expand Up @@ -135,6 +137,9 @@ export function getDefaultOptions(): Options {
hintAnimation: true,
buttonClass: "introjs-button",
progressBarAdditionalClass: false,
getStepNumber(stepIndex,stepsCount,stepNumbersOfLabel){
return `${stepIndex} ${stepNumbersOfLabel} ${stepsCount}`;
}
};
}

Expand Down