1
Fork 0

Make the final step Continue button say Finish instead.

This commit is contained in:
Bauke 2023-06-17 15:15:10 +02:00
parent 76a86eacff
commit 93be9bfca8
Signed by: Bauke
GPG Key ID: C1C0F29952BCF558
1 changed files with 33 additions and 24 deletions

View File

@ -57,31 +57,33 @@ function startTour(
eventHandlers: TourStepEventHandler[], eventHandlers: TourStepEventHandler[],
runMainAgainAfterComplete: boolean, runMainAgainAfterComplete: boolean,
): void { ): void {
const defaultButtons: Shepherd.Step.StepOptionsButton[] = [
{
classes: "btn",
text: "Continue",
action() {
this.next();
},
},
{
classes: "btn",
text: "Back",
action() {
this.back();
},
},
{
classes: "btn",
text: "Exit",
action() {
this.cancel();
},
},
];
const tour = new Shepherd.Tour({ const tour = new Shepherd.Tour({
defaultStepOptions: { defaultStepOptions: {
buttons: [ buttons: [...defaultButtons],
{
classes: "btn",
text: "Continue",
action() {
this.next();
},
},
{
classes: "btn",
text: "Back",
action() {
this.back();
},
},
{
classes: "btn",
text: "Exit",
action() {
this.cancel();
},
},
],
}, },
useModalOverlay: true, useModalOverlay: true,
}); });
@ -106,7 +108,14 @@ function startTour(
// For every step we have, add it to the tour and subsequently add all the // For every step we have, add it to the tour and subsequently add all the
// event handlers to that step. // event handlers to that step.
for (const stepOptions of steps) { for (const [stepNumber, stepOptions] of steps.entries()) {
// If the final step doesn't have buttons defined, set the "Continue" button
// text to "Finish".
if (stepOptions.buttons === undefined && stepNumber + 1 === steps.length) {
stepOptions.buttons = [...defaultButtons];
stepOptions.buttons[0].text = "Finish";
}
const step = tour.addStep(stepOptions); const step = tour.addStep(stepOptions);
for (const [targetStepId, [eventName, eventHandler]] of eventHandlers) { for (const [targetStepId, [eventName, eventHandler]] of eventHandlers) {