Add support button handling
Browse files- index.html +39 -1
- src/config.ts +3 -2
- src/driver.ts +1 -1
- src/popover.ts +19 -9
index.html
CHANGED
|
@@ -143,6 +143,14 @@
|
|
| 143 |
<button id="activate-check-btn">Activate and Check</button>
|
| 144 |
<button id="backdrop-color-btn">Backdrop Color</button>
|
| 145 |
<button id="hooks">Hooks</button>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 146 |
<button id="destroy-btn">Destroy</button>
|
| 147 |
</div>
|
| 148 |
|
|
@@ -277,6 +285,36 @@ npm install driver.js</pre
|
|
| 277 |
<script type="module">
|
| 278 |
import { driver } from "./src/driver.ts";
|
| 279 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 280 |
document.getElementById("is-active-btn").addEventListener("click", () => {
|
| 281 |
alert(driver().isActive());
|
| 282 |
});
|
|
@@ -488,7 +526,7 @@ npm install driver.js</pre
|
|
| 488 |
});
|
| 489 |
driverObj.highlight({
|
| 490 |
popover: {
|
| 491 |
-
showButtons:
|
| 492 |
description:
|
| 493 |
"<div class='gif-popover'><img style='max-width: 100%' src='https://i.imgur.com/EAQhHu5.gif' /><p>Go and build something cool!</p></div>",
|
| 494 |
},
|
|
|
|
| 143 |
<button id="activate-check-btn">Activate and Check</button>
|
| 144 |
<button id="backdrop-color-btn">Backdrop Color</button>
|
| 145 |
<button id="hooks">Hooks</button>
|
| 146 |
+
|
| 147 |
+
<button id="no-buttons">No Buttons</button>
|
| 148 |
+
<button id="all-buttons">All Buttons</button>
|
| 149 |
+
<button id="next-button">Next Buttons</button>
|
| 150 |
+
<button id="prev-button">Previous Buttons</button>
|
| 151 |
+
<button id="next-prev-button">Next Previous Buttons</button>
|
| 152 |
+
<button id="close-button">Close Buttons</button>
|
| 153 |
+
|
| 154 |
<button id="destroy-btn">Destroy</button>
|
| 155 |
</div>
|
| 156 |
|
|
|
|
| 285 |
<script type="module">
|
| 286 |
import { driver } from "./src/driver.ts";
|
| 287 |
|
| 288 |
+
document.getElementById("no-buttons").addEventListener("click", () => {
|
| 289 |
+
const driverObj = driver({});
|
| 290 |
+
|
| 291 |
+
driverObj.highlight({
|
| 292 |
+
element: "#no-buttons",
|
| 293 |
+
popover: {
|
| 294 |
+
title: "No Buttons",
|
| 295 |
+
description:
|
| 296 |
+
"No buttons are shown by default for highlight. You can pass in the option to show the buttons you want.",
|
| 297 |
+
},
|
| 298 |
+
});
|
| 299 |
+
});
|
| 300 |
+
|
| 301 |
+
|
| 302 |
+
document.getElementById("all-buttons").addEventListener("click", () => {
|
| 303 |
+
const driverObj = driver({
|
| 304 |
+
showButtons: ['next', 'previous', 'done']
|
| 305 |
+
});
|
| 306 |
+
|
| 307 |
+
driverObj.highlight({
|
| 308 |
+
element: "#no-buttons",
|
| 309 |
+
popover: {
|
| 310 |
+
title: "No Buttons",
|
| 311 |
+
showButtons: ['done', 'previous', 'next'],
|
| 312 |
+
description:
|
| 313 |
+
"No buttons are shown by default for highlight. You can pass in the option to show the buttons you want.",
|
| 314 |
+
},
|
| 315 |
+
});
|
| 316 |
+
});
|
| 317 |
+
|
| 318 |
document.getElementById("is-active-btn").addEventListener("click", () => {
|
| 319 |
alert(driver().isActive());
|
| 320 |
});
|
|
|
|
| 526 |
});
|
| 527 |
driverObj.highlight({
|
| 528 |
popover: {
|
| 529 |
+
showButtons: [],
|
| 530 |
description:
|
| 531 |
"<div class='gif-popover'><img style='max-width: 100%' src='https://i.imgur.com/EAQhHu5.gif' /><p>Go and build something cool!</p></div>",
|
| 532 |
},
|
src/config.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
| 1 |
import { DriveStep } from "./driver";
|
|
|
|
| 2 |
|
| 3 |
export type Config = {
|
| 4 |
animate?: boolean;
|
|
@@ -9,7 +10,7 @@ export type Config = {
|
|
| 9 |
stagePadding?: number;
|
| 10 |
stageRadius?: number;
|
| 11 |
popoverOffset?: number;
|
| 12 |
-
showButtons?:
|
| 13 |
|
| 14 |
onHighlightStarted?: (element: Element | undefined, step: DriveStep) => void;
|
| 15 |
onHighlighted?: (element: Element | undefined, step: DriveStep) => void;
|
|
@@ -30,7 +31,7 @@ export function configure(config: Config = {}) {
|
|
| 30 |
stagePadding: 10,
|
| 31 |
stageRadius: 5,
|
| 32 |
popoverOffset: 10,
|
| 33 |
-
showButtons:
|
| 34 |
backdropColor: "#000",
|
| 35 |
...config,
|
| 36 |
};
|
|
|
|
| 1 |
import { DriveStep } from "./driver";
|
| 2 |
+
import { AllowedButtons } from "./popover";
|
| 3 |
|
| 4 |
export type Config = {
|
| 5 |
animate?: boolean;
|
|
|
|
| 10 |
stagePadding?: number;
|
| 11 |
stageRadius?: number;
|
| 12 |
popoverOffset?: number;
|
| 13 |
+
showButtons?: AllowedButtons[];
|
| 14 |
|
| 15 |
onHighlightStarted?: (element: Element | undefined, step: DriveStep) => void;
|
| 16 |
onHighlighted?: (element: Element | undefined, step: DriveStep) => void;
|
|
|
|
| 31 |
stagePadding: 10,
|
| 32 |
stageRadius: 5,
|
| 33 |
popoverOffset: 10,
|
| 34 |
+
showButtons: ["next", "previous", "done"],
|
| 35 |
backdropColor: "#000",
|
| 36 |
...config,
|
| 37 |
};
|
src/driver.ts
CHANGED
|
@@ -79,7 +79,7 @@ export function driver(options: Config = {}) {
|
|
| 79 |
...step,
|
| 80 |
popover: step.popover
|
| 81 |
? {
|
| 82 |
-
showButtons:
|
| 83 |
...step.popover!,
|
| 84 |
}
|
| 85 |
: undefined,
|
|
|
|
| 79 |
...step,
|
| 80 |
popover: step.popover
|
| 81 |
? {
|
| 82 |
+
showButtons: [],
|
| 83 |
...step.popover!,
|
| 84 |
}
|
| 85 |
: undefined,
|
src/popover.ts
CHANGED
|
@@ -5,6 +5,7 @@ import { DriveStep } from "./driver";
|
|
| 5 |
|
| 6 |
export type Side = "top" | "right" | "bottom" | "left" | "over";
|
| 7 |
export type Alignment = "start" | "center" | "end";
|
|
|
|
| 8 |
|
| 9 |
export type Popover = {
|
| 10 |
title?: string;
|
|
@@ -12,7 +13,7 @@ export type Popover = {
|
|
| 12 |
side?: Side;
|
| 13 |
align?: Alignment;
|
| 14 |
|
| 15 |
-
showButtons?:
|
| 16 |
|
| 17 |
doneBtnText?: string;
|
| 18 |
closeBtnText?: string;
|
|
@@ -51,7 +52,7 @@ export function renderPopover(element: Element, step: DriveStep) {
|
|
| 51 |
const {
|
| 52 |
title,
|
| 53 |
description,
|
| 54 |
-
showButtons = undefined,
|
| 55 |
// doneBtnText = 'Done',
|
| 56 |
closeBtnText = "Close",
|
| 57 |
nextBtnText = "Next →",
|
|
@@ -76,15 +77,24 @@ export function renderPopover(element: Element, step: DriveStep) {
|
|
| 76 |
popover.description.style.display = "none";
|
| 77 |
}
|
| 78 |
|
| 79 |
-
|
| 80 |
-
popover.footer.style.display = "flex";
|
| 81 |
-
} else {
|
| 82 |
-
popover.footer.style.display = "none";
|
| 83 |
-
}
|
| 84 |
|
| 85 |
-
|
|
|
|
| 86 |
popover.footer.style.display = "flex";
|
| 87 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 88 |
popover.footer.style.display = "none";
|
| 89 |
}
|
| 90 |
|
|
|
|
| 5 |
|
| 6 |
export type Side = "top" | "right" | "bottom" | "left" | "over";
|
| 7 |
export type Alignment = "start" | "center" | "end";
|
| 8 |
+
export type AllowedButtons = "next" | "previous" | "done";
|
| 9 |
|
| 10 |
export type Popover = {
|
| 11 |
title?: string;
|
|
|
|
| 13 |
side?: Side;
|
| 14 |
align?: Alignment;
|
| 15 |
|
| 16 |
+
showButtons?: AllowedButtons[];
|
| 17 |
|
| 18 |
doneBtnText?: string;
|
| 19 |
closeBtnText?: string;
|
|
|
|
| 52 |
const {
|
| 53 |
title,
|
| 54 |
description,
|
| 55 |
+
showButtons: popoverShowButtons = undefined,
|
| 56 |
// doneBtnText = 'Done',
|
| 57 |
closeBtnText = "Close",
|
| 58 |
nextBtnText = "Next →",
|
|
|
|
| 77 |
popover.description.style.display = "none";
|
| 78 |
}
|
| 79 |
|
| 80 |
+
const showButtonsConfig: AllowedButtons[] = popoverShowButtons !== undefined ? popoverShowButtons : getConfig("showButtons")!;
|
|
|
|
|
|
|
|
|
|
|
|
|
| 81 |
|
| 82 |
+
console.log(showButtonsConfig);
|
| 83 |
+
if (showButtonsConfig?.length! > 0) {
|
| 84 |
popover.footer.style.display = "flex";
|
| 85 |
+
|
| 86 |
+
if (!showButtonsConfig.includes('next')) {
|
| 87 |
+
popover.nextButton.style.display = "none";
|
| 88 |
+
}
|
| 89 |
+
|
| 90 |
+
if (!showButtonsConfig.includes('previous')) {
|
| 91 |
+
popover.previousButton.style.display = "none";
|
| 92 |
+
}
|
| 93 |
+
|
| 94 |
+
if (!showButtonsConfig.includes('done')) {
|
| 95 |
+
popover.closeButton.style.display = "none";
|
| 96 |
+
}
|
| 97 |
+
} else {
|
| 98 |
popover.footer.style.display = "none";
|
| 99 |
}
|
| 100 |
|