Skip to content

Commit 071c922

Browse files
authored
Merge pull request #14 from GlobalHive/develop
Merge develop into master
2 parents 5c2d98a + b110bd7 commit 071c922

6 files changed

Lines changed: 65 additions & 17 deletions

File tree

docs/.vuepress/config.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ export default defineUserConfig({
3535
{
3636
text: 'VueJS Tour API',
3737
collapsible: true,
38-
children: [ 'props', 'options', 'methods', 'styling' ],
38+
children: [ 'props', 'options', 'methods', 'callbacks', 'styling' ],
3939
},
4040
],
4141
}),

docs/guide/callbacks.md

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
# Callbacks
2+
3+
::: warning
4+
VueJS Tour is written for Vue 3 composition api. There are no plans to support Vue 2.x
5+
:::
6+
7+
## Component instance callbacks
8+
9+
### `onTourStart();`
10+
11+
The `@onTourStart` callback is executed when the tour starts.
12+
13+
```vue{4,11-13}
14+
<template>
15+
<div>
16+
...
17+
<VTour :steps="steps" autoStart @onTourStart='onTourStart'/>
18+
</div>
19+
</template>
20+
21+
<script setup>
22+
const steps = [...];
23+
24+
const onTourStart = () => {
25+
console.log('Tour started!');
26+
};
27+
</script>
28+
```
29+
30+
### `onTourEnd();`
31+
32+
The `@onTourEnd` callback is executed when the tour ends.
33+
34+
```vue{4,11-13}
35+
<template>
36+
<div>
37+
...
38+
<VTour :steps="steps" autoStart @onTourEnd='onTourEnd'/>
39+
</div>
40+
</template>
41+
42+
<script setup>
43+
const steps = [...];
44+
45+
const onTourEnd = () => {
46+
console.log('Tour ended!');
47+
};
48+
</script>
49+
```

docs/guide/props.md

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,11 @@ VueJS Tour is written for Vue 3 composition api. There are no plans to support V
55
:::
66

77
| Prop | Type | Default | Required | Description |
8-
|:------------:|:---------:|:-----------:|:---:|-----------------------------------------------------------------------------|
9-
| `steps` | `Array` | `undefined` | `true` | An array of steps to be used in the tour. |
10-
| `autoStart` | `Boolean` | `false` | `false` | If `true`, the tour will start automatically when the component is mounted. |
11-
| `startDelay` | `Number` | `0` | `false` | If set, the tour will start after x miliseconds. |
12-
| `highlight` | `Boolean` | `false` | `false` | If `true`, the target will get highlighted. |
8+
|:------------:|:---------:|:-----------:|:--------:|-----------------------------------------------------------------------------|
9+
| `steps` | `Array` | `undefined` | `true` | An array of steps to be used in the tour. |
10+
| `autoStart` | `Boolean` | `false` | `false` | If `true`, the tour will start automatically when the component is mounted. |
11+
| `startDelay` | `Number` | `0` | `false` | If set, the tour will start after x miliseconds. |
12+
| `highlight` | `Boolean` | `false` | `false` | If `true`, the target will get highlighted. |
1313

1414
## Example
1515

@@ -30,7 +30,4 @@ const steps = [...];
3030
<br>
3131
<br>
3232

33-
```js
34-
console.log('TODO: Add highlight example image here')
35-
```
36-
![Placeholder for the highlight example. Source: codemyui.com](https://codemyui.com/wp-content/uploads/2017/11/Strike-Off-ToDo-List-Animation.gif "TODO Gif")
33+
![Highlight example gif](https://raw.githubusercontent.com/GlobalHive/vuejs-tour/master/highlight.gif)

docs/index.md

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,13 @@ features:
1717
details: VueJS Tour uses sass/scss to make it easy to customize the look of your tour.
1818
---
1919

20-
<VTour :steps="steps" ref="tour" highlight/>
20+
<VTour :steps="steps" ref="tour" highlight @onTourEnd='onTourEnd'/>
2121

2222
<script setup>
2323
import { onMounted, ref } from "vue";
24+
import { useRouter } from "vue-router";
2425
const tour = ref(null);
26+
const router = useRouter();
2527
const steps = [
2628
{
2729
target: ".hero img",
@@ -49,6 +51,9 @@ const steps = [
4951
onMounted(() => {
5052
tour.value.resetTour();
5153
});
54+
const onTourEnd = () => {
55+
router.push("/guide/getting-started");
56+
};
5257
</script>
5358
<style lang="scss">
5459
@import "../src/style/style.scss";

highlight.gif

10 KB
Loading

src/components/VTour.vue

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ const props = defineProps({
5555
default: false
5656
}
5757
});
58+
const emit = defineEmits(["onTourStart", "onTourEnd"]);
5859
defineExpose({
5960
startTour,
6061
nextStep,
@@ -79,16 +80,15 @@ async function startTour() {
7980
]
8081
});
8182
props.highlight ? highlightTarget() : null;
83+
emit("onTourStart");
8284
}, props.startDelay);
8385
}
84-
8586
function highlightTarget() {
8687
let _currentStep = document.querySelector(`${step.getCurrentStep.target}`);
8788
let _lastStep = document.querySelector(`${step.getLastStep.target}`);
8889
_currentStep.classList.add("vjt-highlight");
8990
if (_lastStep != null && _currentStep !== _lastStep) _lastStep.classList.remove("vjt-highlight");
9091
}
91-
9292
async function nextStep() {
9393
if (step.currentStep < maxSteps.value) {
9494
step.getCurrentStep.onNext ? await step.getCurrentStep.onNext() : null;
@@ -102,7 +102,6 @@ async function nextStep() {
102102
}
103103
endTour();
104104
}
105-
106105
async function prevStep() {
107106
if (step.currentStep > 0) {
108107
step.getCurrentStep.onPrev ? await step.getCurrentStep.onPrev() : null;
@@ -114,7 +113,6 @@ async function prevStep() {
114113
recalculatePopper();
115114
}
116115
}
117-
118116
function endTour() {
119117
document.getElementById("vjt-tooltip").setAttribute("data-hidden", "");
120118
document.querySelector(".vjt-highlight").classList.remove("vjt-highlight");
@@ -123,15 +121,14 @@ function endTour() {
123121
jump(document.body, {
124122
duration: 500,
125123
});
124+
emit("onTourEnd");
126125
}
127-
128126
function resetTour() {
129127
step.currentStep = 0;
130128
step.lastStep = 0;
131129
localStorage.removeItem("vjt-tour");
132130
startTour();
133131
}
134-
135132
async function recalculatePopper() {
136133
popper.value.setOptions({
137134
placement: `${step.getCurrentStep.placement ? step.getCurrentStep.placement : "top"}`

0 commit comments

Comments
 (0)