Add left bottom popover positioning
Browse files- demo/scripts/demo.js +3 -3
- src/core/popover.js +22 -3
- src/driver.scss +1 -0
demo/scripts/demo.js
CHANGED
@@ -8,21 +8,21 @@ document.addEventListener('DOMContentLoaded', function () {
|
|
8 |
title: 'Before we start',
|
9 |
description: 'This is just one use-case, make sure to check out the rest of the docs below.',
|
10 |
nextBtnText: 'Okay, Start!',
|
11 |
-
position: 'left-
|
12 |
},
|
13 |
}, {
|
14 |
element: '#logo_img',
|
15 |
popover: {
|
16 |
title: 'Focus Anything',
|
17 |
description: 'You can use it to highlight literally anything, images, text, div, span, li etc.',
|
18 |
-
position: 'left-
|
19 |
},
|
20 |
}, {
|
21 |
element: '#name_driver',
|
22 |
popover: {
|
23 |
title: 'Why Driver?',
|
24 |
description: 'Because it lets you drive the user across the page',
|
25 |
-
position: 'left-
|
26 |
}
|
27 |
}, {
|
28 |
element: '#driver-demo-head',
|
|
|
8 |
title: 'Before we start',
|
9 |
description: 'This is just one use-case, make sure to check out the rest of the docs below.',
|
10 |
nextBtnText: 'Okay, Start!',
|
11 |
+
position: 'left-bottom'
|
12 |
},
|
13 |
}, {
|
14 |
element: '#logo_img',
|
15 |
popover: {
|
16 |
title: 'Focus Anything',
|
17 |
description: 'You can use it to highlight literally anything, images, text, div, span, li etc.',
|
18 |
+
position: 'left-bottom',
|
19 |
},
|
20 |
}, {
|
21 |
element: '#name_driver',
|
22 |
popover: {
|
23 |
title: 'Why Driver?',
|
24 |
description: 'Because it lets you drive the user across the page',
|
25 |
+
position: 'left-bottom'
|
26 |
}
|
27 |
}, {
|
28 |
element: '#driver-demo-head',
|
src/core/popover.js
CHANGED
@@ -132,6 +132,9 @@ export default class Popover extends Element {
|
|
132 |
case 'left-center':
|
133 |
this.positionOnLeftCenter(position);
|
134 |
break;
|
|
|
|
|
|
|
135 |
case 'right':
|
136 |
this.positionOnRight(position);
|
137 |
break;
|
@@ -203,6 +206,25 @@ export default class Popover extends Element {
|
|
203 |
this.tipNode.classList.add('right');
|
204 |
}
|
205 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
206 |
/**
|
207 |
* Shows the popover on the left center of the given position
|
208 |
* @param {Position} elementPosition
|
@@ -303,13 +325,10 @@ export default class Popover extends Element {
|
|
303 |
* @private
|
304 |
*/
|
305 |
positionOnBottomRight(elementPosition) {
|
306 |
-
// const popoverWidth = this.getSize().width / 2;
|
307 |
-
// const nodeCenter = elementPosition.left + ((elementPosition.right - elementPosition.left) / 2);
|
308 |
const popoverMargin = this.options.padding + 10; // adding 10 to give it a little distance from the element
|
309 |
|
310 |
this.node.style.top = `${elementPosition.bottom + popoverMargin}px`;
|
311 |
this.node.style.right = `${elementPosition.left - this.options.padding}px`;
|
312 |
-
// this.node.style.left = `${nodeCenter - popoverWidth - this.options.padding}px`;
|
313 |
this.node.style.left = '';
|
314 |
this.node.style.bottom = '';
|
315 |
|
|
|
132 |
case 'left-center':
|
133 |
this.positionOnLeftCenter(position);
|
134 |
break;
|
135 |
+
case 'left-bottom':
|
136 |
+
this.positionOnLeftBottom(position);
|
137 |
+
break;
|
138 |
case 'right':
|
139 |
this.positionOnRight(position);
|
140 |
break;
|
|
|
206 |
this.tipNode.classList.add('right');
|
207 |
}
|
208 |
|
209 |
+
/**
|
210 |
+
* Shows the popover on the left of the given position
|
211 |
+
* @param {Position} elementPosition
|
212 |
+
* @private
|
213 |
+
*/
|
214 |
+
positionOnLeftBottom(elementPosition) {
|
215 |
+
const popoverDimensions = this.getSize();
|
216 |
+
|
217 |
+
const popoverWidth = popoverDimensions.width;
|
218 |
+
const popoverMargin = this.options.padding + 10; // adding 10 to give it a little distance from the element
|
219 |
+
|
220 |
+
this.node.style.left = `${elementPosition.left - popoverWidth - popoverMargin}px`;
|
221 |
+
this.node.style.top = `${(elementPosition.bottom + this.options.padding) - popoverDimensions.height}px`;
|
222 |
+
this.node.style.bottom = '';
|
223 |
+
this.node.style.right = '';
|
224 |
+
|
225 |
+
this.tipNode.classList.add('right', 'position-bottom');
|
226 |
+
}
|
227 |
+
|
228 |
/**
|
229 |
* Shows the popover on the left center of the given position
|
230 |
* @param {Position} elementPosition
|
|
|
325 |
* @private
|
326 |
*/
|
327 |
positionOnBottomRight(elementPosition) {
|
|
|
|
|
328 |
const popoverMargin = this.options.padding + 10; // adding 10 to give it a little distance from the element
|
329 |
|
330 |
this.node.style.top = `${elementPosition.bottom + popoverMargin}px`;
|
331 |
this.node.style.right = `${elementPosition.left - this.options.padding}px`;
|
|
|
332 |
this.node.style.left = '';
|
333 |
this.node.style.bottom = '';
|
334 |
|
src/driver.scss
CHANGED
@@ -62,6 +62,7 @@ div#driver-popover-item {
|
|
62 |
}
|
63 |
|
64 |
&.position-bottom {
|
|
|
65 |
bottom: 20px;
|
66 |
}
|
67 |
}
|
|
|
62 |
}
|
63 |
|
64 |
&.position-bottom {
|
65 |
+
top: auto;
|
66 |
bottom: 20px;
|
67 |
}
|
68 |
}
|