Add confirm on exit tour example
Browse files
docs/src/components/CodeSample.tsx
CHANGED
@@ -52,6 +52,14 @@ export function CodeSample(props: CodeSampleProps) {
|
|
52 |
|
53 |
setDriverObj(driverObj);
|
54 |
} else if (tour) {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
55 |
if (tour?.[2]?.popover?.title === "Next Step is Async") {
|
56 |
tour[2].popover.onNextClick = () => {
|
57 |
mountDummyElement();
|
@@ -67,7 +75,7 @@ export function CodeSample(props: CodeSampleProps) {
|
|
67 |
tour[4].popover.onPrevClick = () => {
|
68 |
mountDummyElement();
|
69 |
driverObj.movePrevious();
|
70 |
-
}
|
71 |
|
72 |
// @ts-ignore
|
73 |
tour[3].popover.onPrevClick = () => {
|
|
|
52 |
|
53 |
setDriverObj(driverObj);
|
54 |
} else if (tour) {
|
55 |
+
if (id === "confirm-destroy") {
|
56 |
+
config!.onDestroyStarted = () => {
|
57 |
+
if (!driverObj.hasNextStep() || confirm("Are you sure?")) {
|
58 |
+
driverObj.destroy();
|
59 |
+
}
|
60 |
+
};
|
61 |
+
}
|
62 |
+
|
63 |
if (tour?.[2]?.popover?.title === "Next Step is Async") {
|
64 |
tour[2].popover.onNextClick = () => {
|
65 |
mountDummyElement();
|
|
|
75 |
tour[4].popover.onPrevClick = () => {
|
76 |
mountDummyElement();
|
77 |
driverObj.movePrevious();
|
78 |
+
};
|
79 |
|
80 |
// @ts-ignore
|
81 |
tour[3].popover.onPrevClick = () => {
|
docs/src/content/guides/async-tour.mdx
CHANGED
@@ -5,7 +5,6 @@ sort: 3
|
|
5 |
---
|
6 |
|
7 |
import { CodeSample } from "../../components/CodeSample.tsx";
|
8 |
-
export let driverObj = null;
|
9 |
|
10 |
You can also have async steps in your tour. This is useful when you want to load some data from the server and then show the tour.
|
11 |
|
|
|
5 |
---
|
6 |
|
7 |
import { CodeSample } from "../../components/CodeSample.tsx";
|
|
|
8 |
|
9 |
You can also have async steps in your tour. This is useful when you want to load some data from the server and then show the tour.
|
10 |
|
docs/src/content/guides/confirm-on-exit.mdx
ADDED
@@ -0,0 +1,50 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
---
|
2 |
+
title: "Confirm on Exit"
|
3 |
+
groupTitle: "Examples"
|
4 |
+
sort: 3
|
5 |
+
---
|
6 |
+
|
7 |
+
import { CodeSample } from "../../components/CodeSample.tsx";
|
8 |
+
|
9 |
+
You can use the `onDestroyStarted` hook to add a confirmation dialog or some other logic when the user tries to exit the tour. In the example below, upon exit we check if there are any tour steps left and ask for confirmation before we exit.
|
10 |
+
|
11 |
+
<CodeSample
|
12 |
+
heading={'Confirm on Exit'}
|
13 |
+
config={{
|
14 |
+
animate: true,
|
15 |
+
showProgress: true,
|
16 |
+
showButtons: ['next', 'previous'],
|
17 |
+
}}
|
18 |
+
tour={[
|
19 |
+
{ element: '#confirm-destroy', popover: { title: 'Animated Tour Example', description: 'Here is the code example showing animated tour. Let\'s walk you through it.', side: "left", align: 'start' }},
|
20 |
+
{ element: '.line:nth-child(1)', popover: { title: 'Import the Library', description: 'It works the same in vanilla JavaScript as well as frameworks.', side: "bottom", align: 'start' }},
|
21 |
+
{ element: '.line:nth-child(2)', popover: { title: 'Importing CSS', description: 'Import the CSS which gives you the default styling for popover and overlay.', side: "bottom", align: 'start' }},
|
22 |
+
{ popover: { title: 'Happy Coding', description: 'And that is all, go ahead and start adding tours to your applications.' } }
|
23 |
+
]}
|
24 |
+
id={"confirm-destroy"}
|
25 |
+
client:load>
|
26 |
+
```js
|
27 |
+
import { driver } from "driver.js";
|
28 |
+
import "driver.js/dist/driver.css";
|
29 |
+
|
30 |
+
const driverObj = driver({
|
31 |
+
showProgress: true,
|
32 |
+
steps: [
|
33 |
+
{ element: '#confirm-destroy-example', popover: { title: 'Animated Tour Example', description: 'Here is the code example showing animated tour. Let\'s walk you through it.', side: "left", align: 'start' }},
|
34 |
+
{ element: 'code .line:nth-child(1)', popover: { title: 'Import the Library', description: 'It works the same in vanilla JavaScript as well as frameworks.', side: "bottom", align: 'start' }},
|
35 |
+
{ element: 'code .line:nth-child(2)', popover: { title: 'Importing CSS', description: 'Import the CSS which gives you the default styling for popover and overlay.', side: "bottom", align: 'start' }},
|
36 |
+
{ popover: { title: 'Happy Coding', description: 'And that is all, go ahead and start adding tours to your applications.' } }
|
37 |
+
],
|
38 |
+
// onDestroyStarted is called when the user tries to exit the tour
|
39 |
+
onDestroyStarted: () => {
|
40 |
+
if (!driverObj.hasNextStep() || confirm("Are you sure?")) {
|
41 |
+
driverObj.destroy();
|
42 |
+
}
|
43 |
+
},
|
44 |
+
});
|
45 |
+
|
46 |
+
driver.drive();
|
47 |
+
```
|
48 |
+
</CodeSample>
|
49 |
+
|
50 |
+
> **Note:** By overriding the `onDestroyStarted` hook, you are responsible for calling `driverObj.destroy()` to exit the tour.
|