Huang Chenghao
commited on
Feature/support click mask to next step (#499)
Browse files* feature: Support click mask to next step
* refactor: rename `clickMaskBehavior` to `overlayClickBehavior`
- index.html +11 -0
- src/config.ts +2 -0
- src/driver.ts +14 -1
index.html
CHANGED
|
@@ -169,6 +169,7 @@
|
|
| 169 |
<button id="simple-highlight-btn">Simple Highlight</button>
|
| 170 |
<button id="transition-highlight-btn">Transition Highlight</button>
|
| 171 |
<button id="disallow-close">Disallow Close</button>
|
|
|
|
| 172 |
<button id="dark-highlight-btn">Super Dark Highlight</button>
|
| 173 |
<button id="dim-highlight-btn">Super Dim Highlight</button>
|
| 174 |
<button id="scrollable-area-btn">Scrollable Area</button>
|
|
@@ -1099,6 +1100,16 @@ npm install driver.js</pre
|
|
| 1099 |
});
|
| 1100 |
});
|
| 1101 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1102 |
document.getElementById("destroy-btn").addEventListener("click", () => {
|
| 1103 |
driver().destroy();
|
| 1104 |
});
|
|
|
|
| 169 |
<button id="simple-highlight-btn">Simple Highlight</button>
|
| 170 |
<button id="transition-highlight-btn">Transition Highlight</button>
|
| 171 |
<button id="disallow-close">Disallow Close</button>
|
| 172 |
+
<button id="click-overlay-to-next">Click Overlay to Next</button>
|
| 173 |
<button id="dark-highlight-btn">Super Dark Highlight</button>
|
| 174 |
<button id="dim-highlight-btn">Super Dim Highlight</button>
|
| 175 |
<button id="scrollable-area-btn">Scrollable Area</button>
|
|
|
|
| 1100 |
});
|
| 1101 |
});
|
| 1102 |
|
| 1103 |
+
document.getElementById("click-overlay-to-next").addEventListener("click", () => {
|
| 1104 |
+
const driverObj = driver({
|
| 1105 |
+
animate: true,
|
| 1106 |
+
overlayClickBehavior: 'nextStep',
|
| 1107 |
+
steps: basicTourSteps,
|
| 1108 |
+
});
|
| 1109 |
+
|
| 1110 |
+
driverObj.drive();
|
| 1111 |
+
});
|
| 1112 |
+
|
| 1113 |
document.getElementById("destroy-btn").addEventListener("click", () => {
|
| 1114 |
driver().destroy();
|
| 1115 |
});
|
src/config.ts
CHANGED
|
@@ -12,6 +12,7 @@ export type Config = {
|
|
| 12 |
overlayOpacity?: number;
|
| 13 |
smoothScroll?: boolean;
|
| 14 |
allowClose?: boolean;
|
|
|
|
| 15 |
stagePadding?: number;
|
| 16 |
stageRadius?: number;
|
| 17 |
|
|
@@ -54,6 +55,7 @@ export function configure(config: Config = {}) {
|
|
| 54 |
currentConfig = {
|
| 55 |
animate: true,
|
| 56 |
allowClose: true,
|
|
|
|
| 57 |
overlayOpacity: 0.7,
|
| 58 |
smoothScroll: false,
|
| 59 |
disableActiveInteraction: false,
|
|
|
|
| 12 |
overlayOpacity?: number;
|
| 13 |
smoothScroll?: boolean;
|
| 14 |
allowClose?: boolean;
|
| 15 |
+
overlayClickBehavior?: 'close' | 'nextStep';
|
| 16 |
stagePadding?: number;
|
| 17 |
stageRadius?: number;
|
| 18 |
|
|
|
|
| 55 |
currentConfig = {
|
| 56 |
animate: true,
|
| 57 |
allowClose: true,
|
| 58 |
+
overlayClickBehavior: 'close',
|
| 59 |
overlayOpacity: 0.7,
|
| 60 |
smoothScroll: false,
|
| 61 |
disableActiveInteraction: false,
|
src/driver.ts
CHANGED
|
@@ -26,6 +26,19 @@ export function driver(options: Config = {}) {
|
|
| 26 |
destroy();
|
| 27 |
}
|
| 28 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 29 |
function moveNext() {
|
| 30 |
const activeIndex = getState("activeIndex");
|
| 31 |
const steps = getConfig("steps") || [];
|
|
@@ -129,7 +142,7 @@ export function driver(options: Config = {}) {
|
|
| 129 |
|
| 130 |
initEvents();
|
| 131 |
|
| 132 |
-
listen("overlayClick",
|
| 133 |
listen("escapePress", handleClose);
|
| 134 |
listen("arrowLeftPress", handleArrowLeft);
|
| 135 |
listen("arrowRightPress", handleArrowRight);
|
|
|
|
| 26 |
destroy();
|
| 27 |
}
|
| 28 |
|
| 29 |
+
function handleOverlayClick() {
|
| 30 |
+
const overlayClickBehavior = getConfig("overlayClickBehavior");
|
| 31 |
+
|
| 32 |
+
if (getConfig("allowClose") && overlayClickBehavior === "close") {
|
| 33 |
+
destroy();
|
| 34 |
+
return;
|
| 35 |
+
}
|
| 36 |
+
|
| 37 |
+
if (overlayClickBehavior === "nextStep") {
|
| 38 |
+
moveNext();
|
| 39 |
+
}
|
| 40 |
+
}
|
| 41 |
+
|
| 42 |
function moveNext() {
|
| 43 |
const activeIndex = getState("activeIndex");
|
| 44 |
const steps = getConfig("steps") || [];
|
|
|
|
| 142 |
|
| 143 |
initEvents();
|
| 144 |
|
| 145 |
+
listen("overlayClick", handleOverlayClick);
|
| 146 |
listen("escapePress", handleClose);
|
| 147 |
listen("arrowLeftPress", handleArrowLeft);
|
| 148 |
listen("arrowRightPress", handleArrowRight);
|