Configuring button texts
Browse files- index.html +25 -3
- src/config.ts +5 -0
- src/popover.ts +8 -7
index.html
CHANGED
|
@@ -146,7 +146,7 @@
|
|
| 146 |
<button id="hooks">Hooks</button>
|
| 147 |
<button id="destroy-btn" style="border-color: red; background: red; color: white">Destroy</button>
|
| 148 |
</div>
|
| 149 |
-
<br
|
| 150 |
<p>given below are the examples of simple `highlight`</p>
|
| 151 |
<div class="buttons">
|
| 152 |
<button id="no-buttons">No Buttons</button>
|
|
@@ -155,9 +155,10 @@
|
|
| 155 |
<button id="previous-button">Previous Buttons</button>
|
| 156 |
<button id="next-prev-button">Next Previous Buttons</button>
|
| 157 |
<button id="close-button">Close Buttons</button>
|
|
|
|
| 158 |
</div>
|
| 159 |
|
| 160 |
-
<br
|
| 161 |
<p>You can Attach events to buttons.</p>
|
| 162 |
<div class="buttons">
|
| 163 |
<button id="button-config-events">Global Button Listeners</button>
|
|
@@ -373,6 +374,27 @@ npm install driver.js</pre
|
|
| 373 |
});
|
| 374 |
});
|
| 375 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 376 |
document.getElementById("is-active-btn").addEventListener("click", () => {
|
| 377 |
alert(driver().isActive());
|
| 378 |
});
|
|
@@ -514,7 +536,7 @@ npm install driver.js</pre
|
|
| 514 |
|
| 515 |
document.getElementById("hooks").addEventListener("click", () => {
|
| 516 |
const hooksEl = document.getElementById("hooks-list");
|
| 517 |
-
hooksEl.innerHTML =
|
| 518 |
|
| 519 |
const driverObj = driver({
|
| 520 |
animate: true,
|
|
|
|
| 146 |
<button id="hooks">Hooks</button>
|
| 147 |
<button id="destroy-btn" style="border-color: red; background: red; color: white">Destroy</button>
|
| 148 |
</div>
|
| 149 |
+
<br />
|
| 150 |
<p>given below are the examples of simple `highlight`</p>
|
| 151 |
<div class="buttons">
|
| 152 |
<button id="no-buttons">No Buttons</button>
|
|
|
|
| 155 |
<button id="previous-button">Previous Buttons</button>
|
| 156 |
<button id="next-prev-button">Next Previous Buttons</button>
|
| 157 |
<button id="close-button">Close Buttons</button>
|
| 158 |
+
<button id="button-texts">Button Texts</button>
|
| 159 |
</div>
|
| 160 |
|
| 161 |
+
<br />
|
| 162 |
<p>You can Attach events to buttons.</p>
|
| 163 |
<div class="buttons">
|
| 164 |
<button id="button-config-events">Global Button Listeners</button>
|
|
|
|
| 374 |
});
|
| 375 |
});
|
| 376 |
|
| 377 |
+
document.getElementById("button-texts").addEventListener("click", () => {
|
| 378 |
+
const driverObj = driver({
|
| 379 |
+
prevBtnText: "<——",
|
| 380 |
+
nextBtnText: "——>",
|
| 381 |
+
closeBtnText: "X",
|
| 382 |
+
});
|
| 383 |
+
|
| 384 |
+
driverObj.highlight({
|
| 385 |
+
element: "#button-texts",
|
| 386 |
+
popover: {
|
| 387 |
+
side: "left",
|
| 388 |
+
title: "Button from Config",
|
| 389 |
+
showButtons: ["close", "next", "previous"],
|
| 390 |
+
closeBtnText: "xx",
|
| 391 |
+
nextBtnText: "==>",
|
| 392 |
+
prevBtnText: "<==",
|
| 393 |
+
description: "These buttons are configured using driver config.",
|
| 394 |
+
},
|
| 395 |
+
});
|
| 396 |
+
});
|
| 397 |
+
|
| 398 |
document.getElementById("is-active-btn").addEventListener("click", () => {
|
| 399 |
alert(driver().isActive());
|
| 400 |
});
|
|
|
|
| 536 |
|
| 537 |
document.getElementById("hooks").addEventListener("click", () => {
|
| 538 |
const hooksEl = document.getElementById("hooks-list");
|
| 539 |
+
hooksEl.innerHTML = "";
|
| 540 |
|
| 541 |
const driverObj = driver({
|
| 542 |
animate: true,
|
src/config.ts
CHANGED
|
@@ -12,6 +12,11 @@ export type Config = {
|
|
| 12 |
popoverOffset?: number;
|
| 13 |
showButtons?: AllowedButtons[];
|
| 14 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 15 |
// State based callbacks, called upon state changes
|
| 16 |
onHighlightStarted?: (element: Element | undefined, step: DriveStep) => void;
|
| 17 |
onHighlighted?: (element: Element | undefined, step: DriveStep) => void;
|
|
|
|
| 12 |
popoverOffset?: number;
|
| 13 |
showButtons?: AllowedButtons[];
|
| 14 |
|
| 15 |
+
// Button texts
|
| 16 |
+
nextBtnText?: string;
|
| 17 |
+
prevBtnText?: string;
|
| 18 |
+
closeBtnText?: string;
|
| 19 |
+
|
| 20 |
// State based callbacks, called upon state changes
|
| 21 |
onHighlightStarted?: (element: Element | undefined, step: DriveStep) => void;
|
| 22 |
onHighlighted?: (element: Element | undefined, step: DriveStep) => void;
|
src/popover.ts
CHANGED
|
@@ -54,9 +54,9 @@ export function renderPopover(element: Element, step: DriveStep) {
|
|
| 54 |
description,
|
| 55 |
showButtons: popoverShowButtons = undefined,
|
| 56 |
// doneBtnText = 'Done',
|
| 57 |
-
closeBtnText = "Close",
|
| 58 |
-
nextBtnText = "Next →",
|
| 59 |
-
prevBtnText = "← Previous",
|
| 60 |
} = step.popover || {};
|
| 61 |
|
| 62 |
popover.nextButton.innerHTML = nextBtnText;
|
|
@@ -77,21 +77,22 @@ export function renderPopover(element: Element, step: DriveStep) {
|
|
| 77 |
popover.description.style.display = "none";
|
| 78 |
}
|
| 79 |
|
| 80 |
-
const showButtonsConfig: AllowedButtons[] =
|
|
|
|
| 81 |
|
| 82 |
console.log(popoverShowButtons);
|
| 83 |
if (showButtonsConfig?.length! > 0) {
|
| 84 |
popover.footer.style.display = "flex";
|
| 85 |
|
| 86 |
-
if (!showButtonsConfig.includes(
|
| 87 |
popover.nextButton.style.display = "none";
|
| 88 |
}
|
| 89 |
|
| 90 |
-
if (!showButtonsConfig.includes(
|
| 91 |
popover.previousButton.style.display = "none";
|
| 92 |
}
|
| 93 |
|
| 94 |
-
if (!showButtonsConfig.includes(
|
| 95 |
popover.closeButton.style.display = "none";
|
| 96 |
}
|
| 97 |
} else {
|
|
|
|
| 54 |
description,
|
| 55 |
showButtons: popoverShowButtons = undefined,
|
| 56 |
// doneBtnText = 'Done',
|
| 57 |
+
closeBtnText = getConfig("closeBtnText") || "Close",
|
| 58 |
+
nextBtnText = getConfig("nextBtnText") || "Next →",
|
| 59 |
+
prevBtnText = getConfig("prevBtnText") || "← Previous",
|
| 60 |
} = step.popover || {};
|
| 61 |
|
| 62 |
popover.nextButton.innerHTML = nextBtnText;
|
|
|
|
| 77 |
popover.description.style.display = "none";
|
| 78 |
}
|
| 79 |
|
| 80 |
+
const showButtonsConfig: AllowedButtons[] =
|
| 81 |
+
popoverShowButtons !== undefined ? popoverShowButtons : getConfig("showButtons")!;
|
| 82 |
|
| 83 |
console.log(popoverShowButtons);
|
| 84 |
if (showButtonsConfig?.length! > 0) {
|
| 85 |
popover.footer.style.display = "flex";
|
| 86 |
|
| 87 |
+
if (!showButtonsConfig.includes("next")) {
|
| 88 |
popover.nextButton.style.display = "none";
|
| 89 |
}
|
| 90 |
|
| 91 |
+
if (!showButtonsConfig.includes("previous")) {
|
| 92 |
popover.previousButton.style.display = "none";
|
| 93 |
}
|
| 94 |
|
| 95 |
+
if (!showButtonsConfig.includes("close")) {
|
| 96 |
popover.closeButton.style.display = "none";
|
| 97 |
}
|
| 98 |
} else {
|