Add more examples
Browse files- index.html +86 -18
- src/config.ts +7 -3
- src/driver.ts +1 -0
- src/popover.ts +3 -3
index.html
CHANGED
@@ -88,7 +88,6 @@
|
|
88 |
|
89 |
.buttons {
|
90 |
display: flex;
|
91 |
-
margin-top: 20px;
|
92 |
gap: 10px;
|
93 |
max-width: 500px;
|
94 |
flex-wrap: wrap;
|
@@ -129,6 +128,8 @@
|
|
129 |
<p>Rewritten and enhanced version of driver.js</p>
|
130 |
</div>
|
131 |
|
|
|
|
|
132 |
<div class="buttons">
|
133 |
<button id="highlight-btn">Animated Highlight</button>
|
134 |
<button id="simple-highlight-btn">Simple Highlight</button>
|
@@ -143,15 +144,23 @@
|
|
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="
|
149 |
-
<button id="next-button">Next
|
150 |
-
<button id="
|
151 |
<button id="next-prev-button">Next Previous Buttons</button>
|
152 |
<button id="close-button">Close Buttons</button>
|
|
|
153 |
|
154 |
-
|
|
|
|
|
|
|
155 |
</div>
|
156 |
|
157 |
<ul>
|
@@ -298,23 +307,72 @@ npm install driver.js</pre
|
|
298 |
});
|
299 |
});
|
300 |
|
301 |
-
|
302 |
-
|
303 |
-
const driverObj = driver({
|
304 |
-
showButtons: ['next', 'previous', 'done']
|
305 |
-
});
|
306 |
|
307 |
driverObj.highlight({
|
308 |
-
element: "#
|
309 |
popover: {
|
310 |
title: "No Buttons",
|
311 |
-
showButtons: [
|
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 |
});
|
@@ -456,31 +514,32 @@ npm install driver.js</pre
|
|
456 |
|
457 |
document.getElementById("hooks").addEventListener("click", () => {
|
458 |
const hooksEl = document.getElementById("hooks-list");
|
|
|
459 |
|
460 |
const driverObj = driver({
|
461 |
animate: true,
|
462 |
onDeselected: (element, step) => {
|
463 |
const li = document.createElement("li");
|
464 |
// prettier-ignore
|
465 |
-
li.innerHTML = `Deselected: ${element
|
466 |
hooksEl.append(li);
|
467 |
},
|
468 |
onHighlightStarted: (element, step) => {
|
469 |
const li = document.createElement("li");
|
470 |
// prettier-ignore
|
471 |
-
li.innerHTML = `Highlight Started: ${element
|
472 |
hooksEl.append(li);
|
473 |
},
|
474 |
onHighlighted: (element, step) => {
|
475 |
const li = document.createElement("li");
|
476 |
// prettier-ignore
|
477 |
-
li.innerHTML = `Highlighted: ${element
|
478 |
hooksEl.append(li);
|
479 |
},
|
480 |
onClose: (element, step) => {
|
481 |
const li = document.createElement("li");
|
482 |
// prettier-ignore
|
483 |
-
li.innerHTML = `Closed: ${element
|
484 |
hooksEl.append(li);
|
485 |
},
|
486 |
});
|
@@ -493,6 +552,15 @@ npm install driver.js</pre
|
|
493 |
},
|
494 |
});
|
495 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
496 |
window.setTimeout(() => {
|
497 |
driverObj.highlight({
|
498 |
element: "#hooks-list",
|
@@ -500,7 +568,7 @@ npm install driver.js</pre
|
|
500 |
description: "Here are all the hooks",
|
501 |
},
|
502 |
});
|
503 |
-
},
|
504 |
});
|
505 |
|
506 |
document.getElementById("scrollable-area-btn").addEventListener("click", () => {
|
|
|
88 |
|
89 |
.buttons {
|
90 |
display: flex;
|
|
|
91 |
gap: 10px;
|
92 |
max-width: 500px;
|
93 |
flex-wrap: wrap;
|
|
|
128 |
<p>Rewritten and enhanced version of driver.js</p>
|
129 |
</div>
|
130 |
|
131 |
+
<h2>Highlight Feature</h2>
|
132 |
+
<p>given below are the examples of simple `highlight`</p>
|
133 |
<div class="buttons">
|
134 |
<button id="highlight-btn">Animated Highlight</button>
|
135 |
<button id="simple-highlight-btn">Simple Highlight</button>
|
|
|
144 |
<button id="activate-check-btn">Activate and Check</button>
|
145 |
<button id="backdrop-color-btn">Backdrop Color</button>
|
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>
|
153 |
+
<button id="buttons-from-popover">Selected Buttons</button>
|
154 |
+
<button id="next-button">Next Button</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 |
+
</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>
|
164 |
</div>
|
165 |
|
166 |
<ul>
|
|
|
307 |
});
|
308 |
});
|
309 |
|
310 |
+
document.getElementById("buttons-from-popover").addEventListener("click", () => {
|
311 |
+
const driverObj = driver();
|
|
|
|
|
|
|
312 |
|
313 |
driverObj.highlight({
|
314 |
+
element: "#buttons-from-popover",
|
315 |
popover: {
|
316 |
title: "No Buttons",
|
317 |
+
showButtons: ["close"],
|
318 |
description:
|
319 |
"No buttons are shown by default for highlight. You can pass in the option to show the buttons you want.",
|
320 |
},
|
321 |
});
|
322 |
});
|
323 |
|
324 |
+
document.getElementById("next-button").addEventListener("click", () => {
|
325 |
+
const driverObj = driver();
|
326 |
+
|
327 |
+
driverObj.highlight({
|
328 |
+
element: "#next-button",
|
329 |
+
popover: {
|
330 |
+
title: "Next and Close",
|
331 |
+
showButtons: ["close", "next"],
|
332 |
+
description: "This one only has next and close buttons, nothing else.",
|
333 |
+
},
|
334 |
+
});
|
335 |
+
});
|
336 |
+
|
337 |
+
document.getElementById("previous-button").addEventListener("click", () => {
|
338 |
+
const driverObj = driver();
|
339 |
+
|
340 |
+
driverObj.highlight({
|
341 |
+
element: "#previous-button",
|
342 |
+
popover: {
|
343 |
+
title: "Previous and Close",
|
344 |
+
showButtons: ["close", "previous"],
|
345 |
+
description: "This one only has previous and close buttons, nothing else.",
|
346 |
+
},
|
347 |
+
});
|
348 |
+
});
|
349 |
+
|
350 |
+
document.getElementById("next-prev-button").addEventListener("click", () => {
|
351 |
+
const driverObj = driver();
|
352 |
+
|
353 |
+
driverObj.highlight({
|
354 |
+
element: "#next-prev-button",
|
355 |
+
popover: {
|
356 |
+
title: "Next and Previous Only",
|
357 |
+
showButtons: ["next", "previous"],
|
358 |
+
description: "This one only has next and previous buttons.",
|
359 |
+
},
|
360 |
+
});
|
361 |
+
});
|
362 |
+
|
363 |
+
document.getElementById("close-button").addEventListener("click", () => {
|
364 |
+
const driverObj = driver();
|
365 |
+
|
366 |
+
driverObj.highlight({
|
367 |
+
element: "#close-button",
|
368 |
+
popover: {
|
369 |
+
title: "Close Only",
|
370 |
+
showButtons: ["close"],
|
371 |
+
description: "This one only has close button.",
|
372 |
+
},
|
373 |
+
});
|
374 |
+
});
|
375 |
+
|
376 |
document.getElementById("is-active-btn").addEventListener("click", () => {
|
377 |
alert(driver().isActive());
|
378 |
});
|
|
|
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,
|
521 |
onDeselected: (element, step) => {
|
522 |
const li = document.createElement("li");
|
523 |
// prettier-ignore
|
524 |
+
li.innerHTML = `Deselected: ${element?.textContent?.slice(0, 10)}..<br> ${JSON.stringify(step)}..`;
|
525 |
hooksEl.append(li);
|
526 |
},
|
527 |
onHighlightStarted: (element, step) => {
|
528 |
const li = document.createElement("li");
|
529 |
// prettier-ignore
|
530 |
+
li.innerHTML = `Highlight Started: ${element?.textContent?.slice(0, 10) || 'None'}..<br> ${JSON.stringify(step)}..`;
|
531 |
hooksEl.append(li);
|
532 |
},
|
533 |
onHighlighted: (element, step) => {
|
534 |
const li = document.createElement("li");
|
535 |
// prettier-ignore
|
536 |
+
li.innerHTML = `Highlighted: ${element?.textContent?.slice(0, 10) || 'None'}..<br> ${JSON.stringify(step)}..`;
|
537 |
hooksEl.append(li);
|
538 |
},
|
539 |
onClose: (element, step) => {
|
540 |
const li = document.createElement("li");
|
541 |
// prettier-ignore
|
542 |
+
li.innerHTML = `Closed: ${element?.textContent?.slice(0, 10) || 'None'}..<br> ${JSON.stringify(step)}..`;
|
543 |
hooksEl.append(li);
|
544 |
},
|
545 |
});
|
|
|
552 |
},
|
553 |
});
|
554 |
|
555 |
+
window.setTimeout(() => {
|
556 |
+
driverObj.highlight({
|
557 |
+
popover: {
|
558 |
+
title: "Popup Hook",
|
559 |
+
description: "There is no element below this popover",
|
560 |
+
},
|
561 |
+
});
|
562 |
+
}, 1000);
|
563 |
+
|
564 |
window.setTimeout(() => {
|
565 |
driverObj.highlight({
|
566 |
element: "#hooks-list",
|
|
|
568 |
description: "Here are all the hooks",
|
569 |
},
|
570 |
});
|
571 |
+
}, 2000);
|
572 |
});
|
573 |
|
574 |
document.getElementById("scrollable-area-btn").addEventListener("click", () => {
|
src/config.ts
CHANGED
@@ -12,12 +12,16 @@ export type Config = {
|
|
12 |
popoverOffset?: number;
|
13 |
showButtons?: AllowedButtons[];
|
14 |
|
|
|
15 |
onHighlightStarted?: (element: Element | undefined, step: DriveStep) => void;
|
16 |
onHighlighted?: (element: Element | undefined, step: DriveStep) => void;
|
17 |
-
|
18 |
onDeselected?: (element: Element | undefined, step: DriveStep) => void;
|
19 |
-
|
20 |
onClose?: (element: Element | undefined, step: DriveStep) => void;
|
|
|
|
|
|
|
|
|
|
|
21 |
};
|
22 |
|
23 |
let currentConfig: Config = {};
|
@@ -31,7 +35,7 @@ export function configure(config: Config = {}) {
|
|
31 |
stagePadding: 10,
|
32 |
stageRadius: 5,
|
33 |
popoverOffset: 10,
|
34 |
-
showButtons: ["next", "previous", "
|
35 |
backdropColor: "#000",
|
36 |
...config,
|
37 |
};
|
|
|
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;
|
|
|
18 |
onDeselected?: (element: Element | undefined, step: DriveStep) => void;
|
|
|
19 |
onClose?: (element: Element | undefined, step: DriveStep) => void;
|
20 |
+
|
21 |
+
// Event based callbacks, called upon events
|
22 |
+
onNextClick?: (element: Element | undefined, step: DriveStep) => void;
|
23 |
+
onPreviousClick?: (element: Element | undefined, step: DriveStep) => void;
|
24 |
+
onCloseClick?: (element: Element | undefined, step: DriveStep) => void;
|
25 |
};
|
26 |
|
27 |
let currentConfig: Config = {};
|
|
|
35 |
stagePadding: 10,
|
36 |
stageRadius: 5,
|
37 |
popoverOffset: 10,
|
38 |
+
showButtons: ["next", "previous", "close"],
|
39 |
backdropColor: "#000",
|
40 |
...config,
|
41 |
};
|
src/driver.ts
CHANGED
@@ -74,6 +74,7 @@ export function driver(options: Config = {}) {
|
|
74 |
},
|
75 |
drive: (steps: DriveStep[]) => console.log(steps),
|
76 |
highlight: (step: DriveStep) => {
|
|
|
77 |
init();
|
78 |
highlight({
|
79 |
...step,
|
|
|
74 |
},
|
75 |
drive: (steps: DriveStep[]) => console.log(steps),
|
76 |
highlight: (step: DriveStep) => {
|
77 |
+
console.log(step.popover?.showButtons);
|
78 |
init();
|
79 |
highlight({
|
80 |
...step,
|
src/popover.ts
CHANGED
@@ -5,7 +5,7 @@ import { DriveStep } from "./driver";
|
|
5 |
|
6 |
export type Side = "top" | "right" | "bottom" | "left" | "over";
|
7 |
export type Alignment = "start" | "center" | "end";
|
8 |
-
export type AllowedButtons = "next" | "previous" | "
|
9 |
|
10 |
export type Popover = {
|
11 |
title?: string;
|
@@ -79,7 +79,7 @@ export function renderPopover(element: Element, step: DriveStep) {
|
|
79 |
|
80 |
const showButtonsConfig: AllowedButtons[] = popoverShowButtons !== undefined ? popoverShowButtons : getConfig("showButtons")!;
|
81 |
|
82 |
-
console.log(
|
83 |
if (showButtonsConfig?.length! > 0) {
|
84 |
popover.footer.style.display = "flex";
|
85 |
|
@@ -91,7 +91,7 @@ export function renderPopover(element: Element, step: DriveStep) {
|
|
91 |
popover.previousButton.style.display = "none";
|
92 |
}
|
93 |
|
94 |
-
if (!showButtonsConfig.includes('
|
95 |
popover.closeButton.style.display = "none";
|
96 |
}
|
97 |
} else {
|
|
|
5 |
|
6 |
export type Side = "top" | "right" | "bottom" | "left" | "over";
|
7 |
export type Alignment = "start" | "center" | "end";
|
8 |
+
export type AllowedButtons = "next" | "previous" | "close";
|
9 |
|
10 |
export type Popover = {
|
11 |
title?: string;
|
|
|
79 |
|
80 |
const showButtonsConfig: AllowedButtons[] = popoverShowButtons !== undefined ? popoverShowButtons : getConfig("showButtons")!;
|
81 |
|
82 |
+
console.log(popoverShowButtons);
|
83 |
if (showButtonsConfig?.length! > 0) {
|
84 |
popover.footer.style.display = "flex";
|
85 |
|
|
|
91 |
popover.previousButton.style.display = "none";
|
92 |
}
|
93 |
|
94 |
+
if (!showButtonsConfig.includes('close')) {
|
95 |
popover.closeButton.style.display = "none";
|
96 |
}
|
97 |
} else {
|