Styling of the popup buttons
Browse files- index.html +4 -3
- src/highlight.ts +2 -2
- src/popover.ts +22 -3
- src/style.css +51 -0
index.html
CHANGED
|
@@ -256,8 +256,8 @@ npm install driver.js</pre
|
|
| 256 |
driver({ animate: true }).highlight({
|
| 257 |
element: "h2",
|
| 258 |
popover: {
|
| 259 |
-
title: "
|
| 260 |
-
description: "A lightweight, no-dependency JavaScript engine to drive user's focus
|
| 261 |
},
|
| 262 |
});
|
| 263 |
});
|
|
@@ -267,7 +267,8 @@ npm install driver.js</pre
|
|
| 267 |
element: "#large-paragraph-text",
|
| 268 |
popover: {
|
| 269 |
title: "driver.js",
|
| 270 |
-
description:
|
|
|
|
| 271 |
align: "end",
|
| 272 |
side: "top",
|
| 273 |
},
|
|
|
|
| 256 |
driver({ animate: true }).highlight({
|
| 257 |
element: "h2",
|
| 258 |
popover: {
|
| 259 |
+
title: "MIT License",
|
| 260 |
+
description: "A lightweight, no-dependency JavaScript engine to drive user's focus.",
|
| 261 |
},
|
| 262 |
});
|
| 263 |
});
|
|
|
|
| 267 |
element: "#large-paragraph-text",
|
| 268 |
popover: {
|
| 269 |
title: "driver.js",
|
| 270 |
+
description:
|
| 271 |
+
"Highlight anything, anywhere on the page. Yes, literally anything including SVG portions, scrollable items etc.",
|
| 272 |
align: "end",
|
| 273 |
side: "top",
|
| 274 |
},
|
src/highlight.ts
CHANGED
|
@@ -99,7 +99,7 @@ function transferHighlight(from: Element, to: Element, toStep: DriveStep) {
|
|
| 99 |
const isHalfwayThrough = timeRemaining <= duration / 2;
|
| 100 |
|
| 101 |
if (toStep.popover && isHalfwayThrough && !isPopoverRendered && hasDelayedPopover) {
|
| 102 |
-
renderPopover(to);
|
| 103 |
isPopoverRendered = true;
|
| 104 |
}
|
| 105 |
|
|
@@ -119,7 +119,7 @@ function transferHighlight(from: Element, to: Element, toStep: DriveStep) {
|
|
| 119 |
|
| 120 |
bringInView(to);
|
| 121 |
if (!hasDelayedPopover && toStep.popover) {
|
| 122 |
-
renderPopover(to);
|
| 123 |
}
|
| 124 |
|
| 125 |
from.classList.remove("driver-active-element");
|
|
|
|
| 99 |
const isHalfwayThrough = timeRemaining <= duration / 2;
|
| 100 |
|
| 101 |
if (toStep.popover && isHalfwayThrough && !isPopoverRendered && hasDelayedPopover) {
|
| 102 |
+
renderPopover(to, toStep);
|
| 103 |
isPopoverRendered = true;
|
| 104 |
}
|
| 105 |
|
|
|
|
| 119 |
|
| 120 |
bringInView(to);
|
| 121 |
if (!hasDelayedPopover && toStep.popover) {
|
| 122 |
+
renderPopover(to, toStep);
|
| 123 |
}
|
| 124 |
|
| 125 |
from.classList.remove("driver-active-element");
|
src/popover.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
| 1 |
import { bringInView } from "./utils";
|
| 2 |
import { getConfig } from "./config";
|
| 3 |
import { getState, setState } from "./state";
|
|
|
|
| 4 |
|
| 5 |
export type Side = "top" | "right" | "bottom" | "left" | "over";
|
| 6 |
export type Alignment = "start" | "center" | "end";
|
|
@@ -33,13 +34,29 @@ export function hidePopover() {
|
|
| 33 |
popover.wrapper.style.display = "none";
|
| 34 |
}
|
| 35 |
|
| 36 |
-
export function renderPopover(element: Element) {
|
| 37 |
let popover = getState("popover");
|
| 38 |
if (!popover) {
|
| 39 |
popover = createPopover();
|
| 40 |
document.body.appendChild(popover.wrapper);
|
| 41 |
}
|
| 42 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 43 |
// Reset the popover position
|
| 44 |
const popoverWrapper = popover.wrapper;
|
| 45 |
popoverWrapper.style.display = "block";
|
|
@@ -183,8 +200,8 @@ export function repositionPopover(element: Element) {
|
|
| 183 |
// @TODO These values will come from the config
|
| 184 |
// Configure the popover positioning
|
| 185 |
const requiredAlignment: Alignment = "start";
|
| 186 |
-
const requiredSide: Side = element.id === "driver-dummy-element" ? "over" : "left" as Side;
|
| 187 |
-
const popoverPadding = getConfig(
|
| 188 |
|
| 189 |
const popoverDimensions = getPopoverDimensions()!;
|
| 190 |
const popoverArrowDimensions = popover.arrow.getBoundingClientRect();
|
|
@@ -423,10 +440,12 @@ function createPopover(): PopoverDOM {
|
|
| 423 |
|
| 424 |
const title = document.createElement("div");
|
| 425 |
title.classList.add("driver-popover-title");
|
|
|
|
| 426 |
title.innerText = "Popover Title";
|
| 427 |
|
| 428 |
const description = document.createElement("div");
|
| 429 |
description.classList.add("driver-popover-description");
|
|
|
|
| 430 |
description.innerText = "Popover description is here";
|
| 431 |
|
| 432 |
const footer = document.createElement("div");
|
|
|
|
| 1 |
import { bringInView } from "./utils";
|
| 2 |
import { getConfig } from "./config";
|
| 3 |
import { getState, setState } from "./state";
|
| 4 |
+
import { DriveStep } from "./driver";
|
| 5 |
|
| 6 |
export type Side = "top" | "right" | "bottom" | "left" | "over";
|
| 7 |
export type Alignment = "start" | "center" | "end";
|
|
|
|
| 34 |
popover.wrapper.style.display = "none";
|
| 35 |
}
|
| 36 |
|
| 37 |
+
export function renderPopover(element: Element, step: DriveStep) {
|
| 38 |
let popover = getState("popover");
|
| 39 |
if (!popover) {
|
| 40 |
popover = createPopover();
|
| 41 |
document.body.appendChild(popover.wrapper);
|
| 42 |
}
|
| 43 |
|
| 44 |
+
const { title, description } = step.popover || {};
|
| 45 |
+
|
| 46 |
+
if (title) {
|
| 47 |
+
popover.title.innerText = title;
|
| 48 |
+
popover.title.style.display = "block";
|
| 49 |
+
} else {
|
| 50 |
+
popover.title.style.display = "none";
|
| 51 |
+
}
|
| 52 |
+
|
| 53 |
+
if (description) {
|
| 54 |
+
popover.description.innerHTML = description;
|
| 55 |
+
popover.description.style.display = "block";
|
| 56 |
+
} else {
|
| 57 |
+
popover.description.style.display = "none";
|
| 58 |
+
}
|
| 59 |
+
|
| 60 |
// Reset the popover position
|
| 61 |
const popoverWrapper = popover.wrapper;
|
| 62 |
popoverWrapper.style.display = "block";
|
|
|
|
| 200 |
// @TODO These values will come from the config
|
| 201 |
// Configure the popover positioning
|
| 202 |
const requiredAlignment: Alignment = "start";
|
| 203 |
+
const requiredSide: Side = element.id === "driver-dummy-element" ? "over" : ("left" as Side);
|
| 204 |
+
const popoverPadding = getConfig("stagePadding") || 0;
|
| 205 |
|
| 206 |
const popoverDimensions = getPopoverDimensions()!;
|
| 207 |
const popoverArrowDimensions = popover.arrow.getBoundingClientRect();
|
|
|
|
| 440 |
|
| 441 |
const title = document.createElement("div");
|
| 442 |
title.classList.add("driver-popover-title");
|
| 443 |
+
title.style.display = "none";
|
| 444 |
title.innerText = "Popover Title";
|
| 445 |
|
| 446 |
const description = document.createElement("div");
|
| 447 |
description.classList.add("driver-popover-description");
|
| 448 |
+
description.style.display = "none";
|
| 449 |
description.innerText = "Popover description is here";
|
| 450 |
|
| 451 |
const footer = document.createElement("div");
|
src/style.css
CHANGED
|
@@ -33,8 +33,11 @@
|
|
| 33 |
|
| 34 |
/* Popover styles */
|
| 35 |
.driver-popover {
|
|
|
|
|
|
|
| 36 |
color: #2d2d2d;
|
| 37 |
margin: 0;
|
|
|
|
| 38 |
border-radius: 5px;
|
| 39 |
min-width: 250px;
|
| 40 |
max-width: 300px;
|
|
@@ -46,6 +49,54 @@
|
|
| 46 |
background-color: #fff;
|
| 47 |
}
|
| 48 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 49 |
.driver-popover-arrow {
|
| 50 |
content: "";
|
| 51 |
position: absolute;
|
|
|
|
| 33 |
|
| 34 |
/* Popover styles */
|
| 35 |
.driver-popover {
|
| 36 |
+
all: unset;
|
| 37 |
+
box-sizing: border-box;
|
| 38 |
color: #2d2d2d;
|
| 39 |
margin: 0;
|
| 40 |
+
padding: 15px;
|
| 41 |
border-radius: 5px;
|
| 42 |
min-width: 250px;
|
| 43 |
max-width: 300px;
|
|
|
|
| 49 |
background-color: #fff;
|
| 50 |
}
|
| 51 |
|
| 52 |
+
.driver-popover-title {
|
| 53 |
+
font: 19px / normal sans-serif;
|
| 54 |
+
margin: 0 0 5px;
|
| 55 |
+
font-weight: 700;
|
| 56 |
+
display: block;
|
| 57 |
+
position: relative;
|
| 58 |
+
line-height: 1.5;
|
| 59 |
+
zoom: 1;
|
| 60 |
+
}
|
| 61 |
+
|
| 62 |
+
.driver-popover-description {
|
| 63 |
+
margin-bottom: 0;
|
| 64 |
+
font: 14px / normal sans-serif;
|
| 65 |
+
line-height: 1.5;
|
| 66 |
+
color: #2d2d2d;
|
| 67 |
+
font-weight: 400;
|
| 68 |
+
zoom: 1;
|
| 69 |
+
}
|
| 70 |
+
|
| 71 |
+
.driver-popover-footer {
|
| 72 |
+
margin-top: 15px;
|
| 73 |
+
text-align: right;
|
| 74 |
+
zoom: 1;
|
| 75 |
+
display: flex;
|
| 76 |
+
justify-content: space-between;
|
| 77 |
+
}
|
| 78 |
+
|
| 79 |
+
.driver-popover-footer button {
|
| 80 |
+
all: unset;
|
| 81 |
+
display: inline-block;
|
| 82 |
+
box-sizing: border-box;
|
| 83 |
+
padding: 5px 10px;
|
| 84 |
+
text-decoration: none;
|
| 85 |
+
text-shadow: 1px 1px 0 #fff;
|
| 86 |
+
color: #2d2d2d;
|
| 87 |
+
font: 12px / normal sans-serif;
|
| 88 |
+
cursor: pointer;
|
| 89 |
+
outline: 0;
|
| 90 |
+
zoom: 1;
|
| 91 |
+
line-height: 1.3;
|
| 92 |
+
border: 1px solid #ccc;
|
| 93 |
+
border-radius: 4px;
|
| 94 |
+
}
|
| 95 |
+
|
| 96 |
+
.driver-popover-footer-btns button + button {
|
| 97 |
+
margin-left: 5px;
|
| 98 |
+
}
|
| 99 |
+
|
| 100 |
.driver-popover-arrow {
|
| 101 |
content: "";
|
| 102 |
position: absolute;
|