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

Exporting StepOptionsButton type to be able to add tour steps buttons dynamically with type checking #2137

Merged
merged 1 commit into from Nov 21, 2022

Conversation

xhafan
Copy link
Contributor

@xhafan xhafan commented Nov 7, 2022

I'd like to create Shepherd tour steps dynamically, with step buttons based on the index of the step. The first step would have only the Next button, steps in the middle would have Back and Next buttons, and the last step would have Back and Done buttons. Here's the code:

const tour = new Shepherd.Tour({...});

steps.forEach((step, i) => { // steps is an array of objects with properties text, title, and elementIdentifier
            
            // below I want to have "Shepherd.Step.StepOptionsButton" instead of "any"
            const buttons: Shepherd.Step.StepOptionsButton[] = []; 
            if (i > 0) {
                buttons.push({
                    text: "Back",
                    action: tour.back
                });
            }

            if (i < this.modelValue.steps.length - 1) {
                buttons.push({
                    text: "Next",
                    action: tour.next
                });
            }

            if (i == this.modelValue.steps.length - 1) {
                buttons.push({
                    text: "Done",
                    action: tour.complete
                });
            }

            tour.addStep({
                title: step.title,
                text: step.text,
                attachTo: {
                    element: step.elementIdentifier,
                    on: "bottom"
                },
                buttons: buttons,
                canClickTarget: false
            });
        });
...

@RobbieTheWagner RobbieTheWagner merged commit e5a82cc into shepherd-pro:master Nov 21, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants