Move hook from popover to elementg
Browse files- index.html +3 -3
- src/config.ts +2 -1
- src/driver.ts +9 -3
- src/highlight.ts +1 -1
- src/popover.ts +0 -1
index.html
CHANGED
|
@@ -489,12 +489,12 @@ npm install driver.js</pre
|
|
| 489 |
},
|
| 490 |
{
|
| 491 |
element: ".dynamic-el",
|
|
|
|
|
|
|
|
|
|
| 492 |
popover: {
|
| 493 |
title: "Dynamic Elements",
|
| 494 |
description: "This was created before we moved here",
|
| 495 |
-
onDeselected: element => {
|
| 496 |
-
element?.parentElement?.removeChild(element);
|
| 497 |
-
},
|
| 498 |
},
|
| 499 |
},
|
| 500 |
{
|
|
|
|
| 489 |
},
|
| 490 |
{
|
| 491 |
element: ".dynamic-el",
|
| 492 |
+
onDeselected: element => {
|
| 493 |
+
element?.parentElement?.removeChild(element);
|
| 494 |
+
},
|
| 495 |
popover: {
|
| 496 |
title: "Dynamic Elements",
|
| 497 |
description: "This was created before we moved here",
|
|
|
|
|
|
|
|
|
|
| 498 |
},
|
| 499 |
},
|
| 500 |
{
|
src/config.ts
CHANGED
|
@@ -11,14 +11,15 @@ export type Config = {
|
|
| 11 |
opacity?: number;
|
| 12 |
stagePadding?: number;
|
| 13 |
stageRadius?: number;
|
|
|
|
| 14 |
allowKeyboardControl?: boolean;
|
| 15 |
|
| 16 |
// Popover specific configuration
|
| 17 |
popoverClass?: string;
|
| 18 |
popoverOffset?: number;
|
| 19 |
showButtons?: AllowedButtons[];
|
| 20 |
-
showProgress?: boolean;
|
| 21 |
disableButtons?: AllowedButtons[];
|
|
|
|
| 22 |
|
| 23 |
// Button texts
|
| 24 |
progressText?: string;
|
|
|
|
| 11 |
opacity?: number;
|
| 12 |
stagePadding?: number;
|
| 13 |
stageRadius?: number;
|
| 14 |
+
|
| 15 |
allowKeyboardControl?: boolean;
|
| 16 |
|
| 17 |
// Popover specific configuration
|
| 18 |
popoverClass?: string;
|
| 19 |
popoverOffset?: number;
|
| 20 |
showButtons?: AllowedButtons[];
|
|
|
|
| 21 |
disableButtons?: AllowedButtons[];
|
| 22 |
+
showProgress?: boolean;
|
| 23 |
|
| 24 |
// Button texts
|
| 25 |
progressText?: string;
|
src/driver.ts
CHANGED
|
@@ -10,6 +10,7 @@ import { getState, resetState, setState } from "./state";
|
|
| 10 |
|
| 11 |
export type DriveStep = {
|
| 12 |
element?: string | Element;
|
|
|
|
| 13 |
popover?: Popover;
|
| 14 |
};
|
| 15 |
|
|
@@ -120,9 +121,14 @@ export function driver(options: Config = {}) {
|
|
| 120 |
|
| 121 |
const doneBtnText = currentStep.popover?.doneBtnText || getConfig("doneBtnText") || "Done";
|
| 122 |
const allowsClosing = getConfig("allowClose");
|
| 123 |
-
const showProgress =
|
|
|
|
|
|
|
|
|
|
| 124 |
const progressText = currentStep.popover?.progressText || getConfig("progressText") || "{{current}} of {{total}}";
|
| 125 |
-
const progressTextReplaced = progressText
|
|
|
|
|
|
|
| 126 |
|
| 127 |
console.log(showProgress);
|
| 128 |
highlight({
|
|
@@ -164,7 +170,7 @@ export function driver(options: Config = {}) {
|
|
| 164 |
return;
|
| 165 |
}
|
| 166 |
|
| 167 |
-
const onDeselected = activeStep?.
|
| 168 |
const onDestroyed = getConfig("onDestroyed");
|
| 169 |
|
| 170 |
document.body.classList.remove("driver-active", "driver-fade", "driver-simple");
|
|
|
|
| 10 |
|
| 11 |
export type DriveStep = {
|
| 12 |
element?: string | Element;
|
| 13 |
+
onDeselected?: (element: Element | undefined, step: DriveStep) => void;
|
| 14 |
popover?: Popover;
|
| 15 |
};
|
| 16 |
|
|
|
|
| 121 |
|
| 122 |
const doneBtnText = currentStep.popover?.doneBtnText || getConfig("doneBtnText") || "Done";
|
| 123 |
const allowsClosing = getConfig("allowClose");
|
| 124 |
+
const showProgress =
|
| 125 |
+
typeof currentStep.popover?.showProgress !== "undefined"
|
| 126 |
+
? currentStep.popover?.showProgress
|
| 127 |
+
: getConfig("showProgress");
|
| 128 |
const progressText = currentStep.popover?.progressText || getConfig("progressText") || "{{current}} of {{total}}";
|
| 129 |
+
const progressTextReplaced = progressText
|
| 130 |
+
.replace("{{current}}", `${stepIndex + 1}`)
|
| 131 |
+
.replace("{{total}}", `${steps.length}`);
|
| 132 |
|
| 133 |
console.log(showProgress);
|
| 134 |
highlight({
|
|
|
|
| 170 |
return;
|
| 171 |
}
|
| 172 |
|
| 173 |
+
const onDeselected = activeStep?.onDeselected || getConfig("onDeselected");
|
| 174 |
const onDestroyed = getConfig("onDestroyed");
|
| 175 |
|
| 176 |
document.body.classList.remove("driver-active", "driver-fade", "driver-simple");
|
src/highlight.ts
CHANGED
|
@@ -72,7 +72,7 @@ function transferHighlight(toElement: Element, toStep: DriveStep) {
|
|
| 72 |
const isAnimatedTour = getConfig("animate");
|
| 73 |
const highlightStartedHook = getConfig("onHighlightStarted");
|
| 74 |
const highlightedHook = getConfig("onHighlighted");
|
| 75 |
-
const deselectedHook = fromStep?.
|
| 76 |
|
| 77 |
if (!isFirstHighlight && deselectedHook) {
|
| 78 |
deselectedHook(isFromDummyElement ? undefined : fromElement, fromStep!);
|
|
|
|
| 72 |
const isAnimatedTour = getConfig("animate");
|
| 73 |
const highlightStartedHook = getConfig("onHighlightStarted");
|
| 74 |
const highlightedHook = getConfig("onHighlighted");
|
| 75 |
+
const deselectedHook = fromStep?.onDeselected || getConfig("onDeselected");
|
| 76 |
|
| 77 |
if (!isFirstHighlight && deselectedHook) {
|
| 78 |
deselectedHook(isFromDummyElement ? undefined : fromElement, fromStep!);
|
src/popover.ts
CHANGED
|
@@ -29,7 +29,6 @@ export type Popover = {
|
|
| 29 |
|
| 30 |
// Called after the popover is rendered
|
| 31 |
onPopoverRendered?: (popover: PopoverDOM) => void;
|
| 32 |
-
onDeselected?: (element: Element | undefined, step: DriveStep) => void;
|
| 33 |
|
| 34 |
// Button callbacks
|
| 35 |
onNextClick?: (element: Element | undefined, step: DriveStep) => void;
|
|
|
|
| 29 |
|
| 30 |
// Called after the popover is rendered
|
| 31 |
onPopoverRendered?: (popover: PopoverDOM) => void;
|
|
|
|
| 32 |
|
| 33 |
// Button callbacks
|
| 34 |
onNextClick?: (element: Element | undefined, step: DriveStep) => void;
|