Add offset option in popover
Browse files- src/core/popover.js +15 -14
- types/index.d.ts +6 -0
src/core/popover.js
CHANGED
@@ -30,6 +30,7 @@ export default class Popover extends Element {
|
|
30 |
isLast: true,
|
31 |
totalCount: 1,
|
32 |
currentIndex: 0,
|
|
|
33 |
showButtons: true,
|
34 |
closeBtnText: 'Close',
|
35 |
doneBtnText: 'Done',
|
@@ -214,7 +215,7 @@ export default class Popover extends Element {
|
|
214 |
const popoverMargin = this.options.padding + 10; // adding 10 to give it a little distance from the element
|
215 |
|
216 |
this.node.style.left = `${elementPosition.left - popoverWidth - popoverMargin}px`;
|
217 |
-
this.node.style.top = `${elementPosition.top - this.options.padding}px`;
|
218 |
this.node.style.right = '';
|
219 |
this.node.style.bottom = '';
|
220 |
|
@@ -233,7 +234,7 @@ export default class Popover extends Element {
|
|
233 |
const popoverMargin = this.options.padding + 10; // adding 10 to give it a little distance from the element
|
234 |
|
235 |
this.node.style.left = `${elementPosition.left - popoverWidth - popoverMargin}px`;
|
236 |
-
this.node.style.top = `${(elementPosition.bottom + this.options.padding) - popoverDimensions.height}px`;
|
237 |
this.node.style.bottom = '';
|
238 |
this.node.style.right = '';
|
239 |
|
@@ -254,10 +255,10 @@ export default class Popover extends Element {
|
|
254 |
|
255 |
const popoverMargin = this.options.padding + 10; // adding 10 to give it a little distance from the element
|
256 |
const elementCenter = (elementPosition.bottom - elementPosition.top) / 2;
|
257 |
-
const
|
258 |
|
259 |
this.node.style.left = `${elementPosition.left - popoverWidth - popoverMargin}px`;
|
260 |
-
this.node.style.top = `${
|
261 |
this.node.style.right = '';
|
262 |
this.node.style.bottom = '';
|
263 |
|
@@ -273,7 +274,7 @@ export default class Popover extends Element {
|
|
273 |
const popoverMargin = this.options.padding + 10; // adding 10 to give it a little distance from the element
|
274 |
|
275 |
this.node.style.left = `${elementPosition.right + popoverMargin}px`;
|
276 |
-
this.node.style.top = `${elementPosition.top - this.options.padding}px`;
|
277 |
this.node.style.right = '';
|
278 |
this.node.style.bottom = '';
|
279 |
|
@@ -292,10 +293,10 @@ export default class Popover extends Element {
|
|
292 |
const popoverHeight = popoverDimensions.height;
|
293 |
const popoverCenter = popoverHeight / 2;
|
294 |
const elementCenter = (elementPosition.bottom - elementPosition.top) / 2;
|
295 |
-
const
|
296 |
|
297 |
this.node.style.left = `${elementPosition.right + popoverMargin}px`;
|
298 |
-
this.node.style.top = `${
|
299 |
this.node.style.right = '';
|
300 |
this.node.style.bottom = '';
|
301 |
|
@@ -312,7 +313,7 @@ export default class Popover extends Element {
|
|
312 |
const popoverDimensions = this.getSize();
|
313 |
|
314 |
this.node.style.left = `${elementPosition.right + popoverMargin}px`;
|
315 |
-
this.node.style.top = `${(elementPosition.bottom + this.options.padding) - popoverDimensions.height}px`;
|
316 |
this.node.style.bottom = '';
|
317 |
this.node.style.right = '';
|
318 |
|
@@ -329,7 +330,7 @@ export default class Popover extends Element {
|
|
329 |
const popoverMargin = this.options.padding + 10; // adding 10 to give it a little distance from the element
|
330 |
|
331 |
this.node.style.top = `${elementPosition.top - popoverHeight - popoverMargin}px`;
|
332 |
-
this.node.style.left = `${elementPosition.left - this.options.padding}px`;
|
333 |
this.node.style.right = '';
|
334 |
this.node.style.bottom = '';
|
335 |
|
@@ -347,7 +348,7 @@ export default class Popover extends Element {
|
|
347 |
const popoverWidth = dimensions.width / 2;
|
348 |
|
349 |
const popoverMargin = this.options.padding + 10; // adding 10 to give it a little distance from the element
|
350 |
-
const nodeCenter = elementPosition.left + ((elementPosition.right - elementPosition.left) / 2);
|
351 |
|
352 |
this.node.style.top = `${elementPosition.top - popoverHeight - popoverMargin}px`;
|
353 |
this.node.style.left = `${nodeCenter - popoverWidth - this.options.padding}px`;
|
@@ -369,7 +370,7 @@ export default class Popover extends Element {
|
|
369 |
const popoverMargin = this.options.padding + 10; // adding 10 to give it a little distance from the element
|
370 |
|
371 |
this.node.style.top = `${elementPosition.top - popoverHeight - popoverMargin}px`;
|
372 |
-
this.node.style.left = `${(elementPosition.right + this.options.padding) - dimensions.width}px`;
|
373 |
this.node.style.right = '';
|
374 |
this.node.style.bottom = '';
|
375 |
|
@@ -386,7 +387,7 @@ export default class Popover extends Element {
|
|
386 |
const popoverMargin = this.options.padding + 10; // adding 10 to give it a little distance from the element
|
387 |
|
388 |
this.node.style.top = `${elementPosition.bottom + popoverMargin}px`;
|
389 |
-
this.node.style.left = `${elementPosition.left - this.options.padding}px`;
|
390 |
this.node.style.right = '';
|
391 |
this.node.style.bottom = '';
|
392 |
|
@@ -400,8 +401,8 @@ export default class Popover extends Element {
|
|
400 |
*/
|
401 |
positionOnBottomCenter(elementPosition) {
|
402 |
const popoverWidth = this.getSize().width / 2;
|
403 |
-
const nodeCenter = elementPosition.left + ((elementPosition.right - elementPosition.left) / 2);
|
404 |
const popoverMargin = this.options.padding + 10; // adding 10 to give it a little distance from the element
|
|
|
405 |
|
406 |
this.node.style.top = `${elementPosition.bottom + popoverMargin}px`;
|
407 |
this.node.style.left = `${nodeCenter - popoverWidth - this.options.padding}px`;
|
@@ -422,7 +423,7 @@ export default class Popover extends Element {
|
|
422 |
const popoverMargin = this.options.padding + 10; // adding 10 to give it a little distance from the element
|
423 |
|
424 |
this.node.style.top = `${elementPosition.bottom + popoverMargin}px`;
|
425 |
-
this.node.style.left = `${(elementPosition.right + this.options.padding) - dimensions.width}px`;
|
426 |
this.node.style.right = '';
|
427 |
this.node.style.bottom = '';
|
428 |
|
|
|
30 |
isLast: true,
|
31 |
totalCount: 1,
|
32 |
currentIndex: 0,
|
33 |
+
offset: 0,
|
34 |
showButtons: true,
|
35 |
closeBtnText: 'Close',
|
36 |
doneBtnText: 'Done',
|
|
|
215 |
const popoverMargin = this.options.padding + 10; // adding 10 to give it a little distance from the element
|
216 |
|
217 |
this.node.style.left = `${elementPosition.left - popoverWidth - popoverMargin}px`;
|
218 |
+
this.node.style.top = `${(elementPosition.top + this.options.offset) - this.options.padding}px`;
|
219 |
this.node.style.right = '';
|
220 |
this.node.style.bottom = '';
|
221 |
|
|
|
234 |
const popoverMargin = this.options.padding + 10; // adding 10 to give it a little distance from the element
|
235 |
|
236 |
this.node.style.left = `${elementPosition.left - popoverWidth - popoverMargin}px`;
|
237 |
+
this.node.style.top = `${(elementPosition.bottom + this.options.padding + this.options.offset) - popoverDimensions.height}px`;
|
238 |
this.node.style.bottom = '';
|
239 |
this.node.style.right = '';
|
240 |
|
|
|
255 |
|
256 |
const popoverMargin = this.options.padding + 10; // adding 10 to give it a little distance from the element
|
257 |
const elementCenter = (elementPosition.bottom - elementPosition.top) / 2;
|
258 |
+
const topCenterPosition = (elementPosition.top - popoverCenter) + elementCenter + this.options.offset;
|
259 |
|
260 |
this.node.style.left = `${elementPosition.left - popoverWidth - popoverMargin}px`;
|
261 |
+
this.node.style.top = `${topCenterPosition}px`;
|
262 |
this.node.style.right = '';
|
263 |
this.node.style.bottom = '';
|
264 |
|
|
|
274 |
const popoverMargin = this.options.padding + 10; // adding 10 to give it a little distance from the element
|
275 |
|
276 |
this.node.style.left = `${elementPosition.right + popoverMargin}px`;
|
277 |
+
this.node.style.top = `${(elementPosition.top + this.options.offset) - this.options.padding}px`;
|
278 |
this.node.style.right = '';
|
279 |
this.node.style.bottom = '';
|
280 |
|
|
|
293 |
const popoverHeight = popoverDimensions.height;
|
294 |
const popoverCenter = popoverHeight / 2;
|
295 |
const elementCenter = (elementPosition.bottom - elementPosition.top) / 2;
|
296 |
+
const topCenterPosition = (elementPosition.top - popoverCenter) + elementCenter + this.options.offset;
|
297 |
|
298 |
this.node.style.left = `${elementPosition.right + popoverMargin}px`;
|
299 |
+
this.node.style.top = `${topCenterPosition}px`;
|
300 |
this.node.style.right = '';
|
301 |
this.node.style.bottom = '';
|
302 |
|
|
|
313 |
const popoverDimensions = this.getSize();
|
314 |
|
315 |
this.node.style.left = `${elementPosition.right + popoverMargin}px`;
|
316 |
+
this.node.style.top = `${(elementPosition.bottom + this.options.padding + this.options.offset) - popoverDimensions.height}px`;
|
317 |
this.node.style.bottom = '';
|
318 |
this.node.style.right = '';
|
319 |
|
|
|
330 |
const popoverMargin = this.options.padding + 10; // adding 10 to give it a little distance from the element
|
331 |
|
332 |
this.node.style.top = `${elementPosition.top - popoverHeight - popoverMargin}px`;
|
333 |
+
this.node.style.left = `${(elementPosition.left - this.options.padding) + this.options.offset}px`;
|
334 |
this.node.style.right = '';
|
335 |
this.node.style.bottom = '';
|
336 |
|
|
|
348 |
const popoverWidth = dimensions.width / 2;
|
349 |
|
350 |
const popoverMargin = this.options.padding + 10; // adding 10 to give it a little distance from the element
|
351 |
+
const nodeCenter = this.options.offset + elementPosition.left + ((elementPosition.right - elementPosition.left) / 2);
|
352 |
|
353 |
this.node.style.top = `${elementPosition.top - popoverHeight - popoverMargin}px`;
|
354 |
this.node.style.left = `${nodeCenter - popoverWidth - this.options.padding}px`;
|
|
|
370 |
const popoverMargin = this.options.padding + 10; // adding 10 to give it a little distance from the element
|
371 |
|
372 |
this.node.style.top = `${elementPosition.top - popoverHeight - popoverMargin}px`;
|
373 |
+
this.node.style.left = `${(elementPosition.right + this.options.padding + this.options.offset) - dimensions.width}px`;
|
374 |
this.node.style.right = '';
|
375 |
this.node.style.bottom = '';
|
376 |
|
|
|
387 |
const popoverMargin = this.options.padding + 10; // adding 10 to give it a little distance from the element
|
388 |
|
389 |
this.node.style.top = `${elementPosition.bottom + popoverMargin}px`;
|
390 |
+
this.node.style.left = `${(elementPosition.left - this.options.padding) + this.options.offset}px`;
|
391 |
this.node.style.right = '';
|
392 |
this.node.style.bottom = '';
|
393 |
|
|
|
401 |
*/
|
402 |
positionOnBottomCenter(elementPosition) {
|
403 |
const popoverWidth = this.getSize().width / 2;
|
|
|
404 |
const popoverMargin = this.options.padding + 10; // adding 10 to give it a little distance from the element
|
405 |
+
const nodeCenter = this.options.offset + elementPosition.left + ((elementPosition.right - elementPosition.left) / 2);
|
406 |
|
407 |
this.node.style.top = `${elementPosition.bottom + popoverMargin}px`;
|
408 |
this.node.style.left = `${nodeCenter - popoverWidth - this.options.padding}px`;
|
|
|
423 |
const popoverMargin = this.options.padding + 10; // adding 10 to give it a little distance from the element
|
424 |
|
425 |
this.node.style.top = `${elementPosition.bottom + popoverMargin}px`;
|
426 |
+
this.node.style.left = `${(elementPosition.right + this.options.padding + this.options.offset) - dimensions.width}px`;
|
427 |
this.node.style.right = '';
|
428 |
this.node.style.bottom = '';
|
429 |
|
types/index.d.ts
CHANGED
@@ -684,6 +684,12 @@ declare module 'driver.js' {
|
|
684 |
*/
|
685 |
totalCount?: number;
|
686 |
|
|
|
|
|
|
|
|
|
|
|
|
|
687 |
/**
|
688 |
* Counter for the current popover
|
689 |
* @default 0
|
|
|
684 |
*/
|
685 |
totalCount?: number;
|
686 |
|
687 |
+
/**
|
688 |
+
* Additional offset of the popover
|
689 |
+
* @default 0
|
690 |
+
*/
|
691 |
+
offset?: number;
|
692 |
+
|
693 |
/**
|
694 |
* Counter for the current popover
|
695 |
* @default 0
|