Fix popover and arrow rendering
Browse files- index.html +4 -0
- src/driver.ts +3 -3
- src/events.ts +1 -1
- src/highlight.ts +1 -2
- src/popover.ts +8 -4
index.html
CHANGED
@@ -449,6 +449,10 @@ npm install driver.js</pre
|
|
449 |
|
450 |
driverObj.highlight({
|
451 |
element: "#hooks",
|
|
|
|
|
|
|
|
|
452 |
});
|
453 |
|
454 |
window.setTimeout(() => {
|
|
|
449 |
|
450 |
driverObj.highlight({
|
451 |
element: "#hooks",
|
452 |
+
popover: {
|
453 |
+
title: "Hooks",
|
454 |
+
description: "Here are all the hooks",
|
455 |
+
},
|
456 |
});
|
457 |
|
458 |
window.setTimeout(() => {
|
src/driver.ts
CHANGED
@@ -1,8 +1,8 @@
|
|
1 |
import { destroyPopover, Popover } from "./popover";
|
2 |
import { destroyStage } from "./stage";
|
3 |
-
import { destroyEvents, initEvents } from "./events";
|
4 |
import { Config, configure, getConfig } from "./config";
|
5 |
-
import { destroyHighlight, highlight
|
6 |
import { destroyEmitter, listen } from "./emitter";
|
7 |
|
8 |
import "./style.css";
|
@@ -70,7 +70,7 @@ export function driver(options: Config = {}) {
|
|
70 |
return {
|
71 |
isActive: () => getState("isInitialized") || false,
|
72 |
refresh: () => {
|
73 |
-
|
74 |
},
|
75 |
drive: (steps: DriveStep[]) => console.log(steps),
|
76 |
highlight: (step: DriveStep) => {
|
|
|
1 |
import { destroyPopover, Popover } from "./popover";
|
2 |
import { destroyStage } from "./stage";
|
3 |
+
import { destroyEvents, initEvents, requireRefresh } from "./events";
|
4 |
import { Config, configure, getConfig } from "./config";
|
5 |
+
import { destroyHighlight, highlight } from "./highlight";
|
6 |
import { destroyEmitter, listen } from "./emitter";
|
7 |
|
8 |
import "./style.css";
|
|
|
70 |
return {
|
71 |
isActive: () => getState("isInitialized") || false,
|
72 |
refresh: () => {
|
73 |
+
requireRefresh();
|
74 |
},
|
75 |
drive: (steps: DriveStep[]) => console.log(steps),
|
76 |
highlight: (step: DriveStep) => {
|
src/events.ts
CHANGED
@@ -2,7 +2,7 @@ import { refreshActiveHighlight } from "./highlight";
|
|
2 |
import { emit } from "./emitter";
|
3 |
import { getState, setState } from "./state";
|
4 |
|
5 |
-
function requireRefresh() {
|
6 |
const resizeTimeout = getState("resizeTimeout");
|
7 |
if (resizeTimeout) {
|
8 |
window.cancelAnimationFrame(resizeTimeout);
|
|
|
2 |
import { emit } from "./emitter";
|
3 |
import { getState, setState } from "./state";
|
4 |
|
5 |
+
export function requireRefresh() {
|
6 |
const resizeTimeout = getState("resizeTimeout");
|
7 |
if (resizeTimeout) {
|
8 |
window.cancelAnimationFrame(resizeTimeout);
|
src/highlight.ts
CHANGED
@@ -68,7 +68,6 @@ function transferHighlight(toElement: Element, toStep: DriveStep) {
|
|
68 |
const isFirstHighlight = !fromElement || fromElement === toElement;
|
69 |
const isToDummyElement = toElement.id === "driver-dummy-element";
|
70 |
const isFromDummyElement = fromElement.id === "driver-dummy-element";
|
71 |
-
const hasNoPreviousPopover = fromStep && !fromStep.popover;
|
72 |
|
73 |
const highlightStartedHook = getConfig("onHighlightStarted");
|
74 |
const highlightedHook = getConfig("onHighlighted");
|
@@ -82,7 +81,7 @@ function transferHighlight(toElement: Element, toStep: DriveStep) {
|
|
82 |
highlightStartedHook(isToDummyElement ? undefined : toElement, toStep);
|
83 |
}
|
84 |
|
85 |
-
const hasDelayedPopover = !isFirstHighlight
|
86 |
let isPopoverRendered = false;
|
87 |
|
88 |
hidePopover();
|
|
|
68 |
const isFirstHighlight = !fromElement || fromElement === toElement;
|
69 |
const isToDummyElement = toElement.id === "driver-dummy-element";
|
70 |
const isFromDummyElement = fromElement.id === "driver-dummy-element";
|
|
|
71 |
|
72 |
const highlightStartedHook = getConfig("onHighlightStarted");
|
73 |
const highlightedHook = getConfig("onHighlighted");
|
|
|
81 |
highlightStartedHook(isToDummyElement ? undefined : toElement, toStep);
|
82 |
}
|
83 |
|
84 |
+
const hasDelayedPopover = !isFirstHighlight;
|
85 |
let isPopoverRendered = false;
|
86 |
|
87 |
hidePopover();
|
src/popover.ts
CHANGED
@@ -53,9 +53,9 @@ export function renderPopover(element: Element, step: DriveStep) {
|
|
53 |
description,
|
54 |
showButtons = undefined,
|
55 |
// doneBtnText = 'Done',
|
56 |
-
closeBtnText=
|
57 |
-
nextBtnText=
|
58 |
-
prevBtnText =
|
59 |
} = step.popover || {};
|
60 |
|
61 |
popover.nextButton.innerHTML = nextBtnText;
|
@@ -361,7 +361,11 @@ export function repositionPopover(element: Element, step: DriveStep) {
|
|
361 |
// e.g. if element scrolled out of the screen to the top, the arrow should be rendered
|
362 |
// pointing to the top. If the element scrolled out of the screen to the bottom,
|
363 |
// the arrow should be rendered pointing to the bottom.
|
364 |
-
|
|
|
|
|
|
|
|
|
365 |
}
|
366 |
|
367 |
function renderPopoverArrow(alignment: Alignment, side: Side, element: Element) {
|
|
|
53 |
description,
|
54 |
showButtons = undefined,
|
55 |
// doneBtnText = 'Done',
|
56 |
+
closeBtnText = "Close",
|
57 |
+
nextBtnText = "Next →",
|
58 |
+
prevBtnText = "← Previous",
|
59 |
} = step.popover || {};
|
60 |
|
61 |
popover.nextButton.innerHTML = nextBtnText;
|
|
|
361 |
// e.g. if element scrolled out of the screen to the top, the arrow should be rendered
|
362 |
// pointing to the top. If the element scrolled out of the screen to the bottom,
|
363 |
// the arrow should be rendered pointing to the bottom.
|
364 |
+
if (!noneOptimal) {
|
365 |
+
renderPopoverArrow(requiredAlignment, popoverRenderedSide, element);
|
366 |
+
} else {
|
367 |
+
popover.arrow.classList.add("driver-popover-arrow-none");
|
368 |
+
}
|
369 |
}
|
370 |
|
371 |
function renderPopoverArrow(alignment: Alignment, side: Side, element: Element) {
|