Add bottom right positioning
Browse files- demo/scripts/demo.js +1 -1
- src/core/popover.js +24 -1
- src/driver.scss +5 -1
demo/scripts/demo.js
CHANGED
@@ -8,7 +8,7 @@ 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: 'bottom-
|
12 |
},
|
13 |
}, {
|
14 |
element: '#logo_img',
|
|
|
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: 'bottom-right'
|
12 |
},
|
13 |
}, {
|
14 |
element: '#logo_img',
|
src/core/popover.js
CHANGED
@@ -142,6 +142,9 @@ export default class Popover extends Element {
|
|
142 |
case 'bottom-center':
|
143 |
this.positionOnBottomCenter(position);
|
144 |
break;
|
|
|
|
|
|
|
145 |
case 'auto':
|
146 |
default:
|
147 |
this.autoPosition(position);
|
@@ -262,7 +265,27 @@ export default class Popover extends Element {
|
|
262 |
this.node.style.bottom = '';
|
263 |
|
264 |
// Add the tip at the top center
|
265 |
-
this.tipNode.classList.add('top', 'center');
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
266 |
}
|
267 |
|
268 |
/**
|
|
|
142 |
case 'bottom-center':
|
143 |
this.positionOnBottomCenter(position);
|
144 |
break;
|
145 |
+
case 'bottom-right':
|
146 |
+
this.positionOnBottomRight(position);
|
147 |
+
break;
|
148 |
case 'auto':
|
149 |
default:
|
150 |
this.autoPosition(position);
|
|
|
265 |
this.node.style.bottom = '';
|
266 |
|
267 |
// Add the tip at the top center
|
268 |
+
this.tipNode.classList.add('top', 'position-center');
|
269 |
+
}
|
270 |
+
|
271 |
+
/**
|
272 |
+
* Shows the popover on the bottom-right of the given position
|
273 |
+
* @param {Position} elementPosition
|
274 |
+
* @private
|
275 |
+
*/
|
276 |
+
positionOnBottomRight(elementPosition) {
|
277 |
+
// const popoverWidth = this.getSize().width / 2;
|
278 |
+
// const nodeCenter = elementPosition.left + ((elementPosition.right - elementPosition.left) / 2);
|
279 |
+
const popoverMargin = this.options.padding + 10; // adding 10 to give it a little distance from the element
|
280 |
+
|
281 |
+
this.node.style.top = `${elementPosition.bottom + popoverMargin}px`;
|
282 |
+
this.node.style.right = `${elementPosition.left - this.options.padding}px`;
|
283 |
+
// this.node.style.left = `${nodeCenter - popoverWidth - this.options.padding}px`;
|
284 |
+
this.node.style.left = '';
|
285 |
+
this.node.style.bottom = '';
|
286 |
+
|
287 |
+
// Add the tip at the top center
|
288 |
+
this.tipNode.classList.add('top', 'position-right');
|
289 |
}
|
290 |
|
291 |
/**
|
src/driver.scss
CHANGED
@@ -66,9 +66,13 @@ div#driver-popover-item {
|
|
66 |
border-left-color: transparent;
|
67 |
}
|
68 |
|
69 |
-
&.center {
|
70 |
left: 49%;
|
71 |
}
|
|
|
|
|
|
|
|
|
72 |
}
|
73 |
|
74 |
.driver-popover-footer {
|
|
|
66 |
border-left-color: transparent;
|
67 |
}
|
68 |
|
69 |
+
&.position-center {
|
70 |
left: 49%;
|
71 |
}
|
72 |
+
|
73 |
+
&.position-right {
|
74 |
+
right: 20px;
|
75 |
+
}
|
76 |
}
|
77 |
|
78 |
.driver-popover-footer {
|