@momentum-design/components 0.131.0 → 0.131.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,7 +1,8 @@
1
+ import { OffsetOptions } from '@floating-ui/dom';
1
2
  import { CSSResult, PropertyValues } from 'lit';
2
3
  import { Component } from '../../models';
3
4
  import { DepthManager, StackChange } from '../../utils/controllers/DepthManager';
4
- import type { PopoverBoundaryRoot, PopoverColor, PopoverPlacement, PopoverStrategy, PopoverTrigger } from './popover.types';
5
+ import { PopoverBoundaryRoot, PopoverColor, PopoverPlacement, PopoverStrategy, PopoverTrigger } from './popover.types';
5
6
  declare const Popover_base: import("../../utils/mixins/index.types").Constructor<import("../../utils/mixins/KeyDownHandledMixin").KeyDownHandledMixinInterface> & import("../../utils/mixins/index.types").Constructor<import("../../utils/mixins/KeyToActionMixin").KeyToActionInterface> & import("../../utils/mixins/index.types").Constructor<Component & import("../../utils/mixins/BackdropMixin").BackdropMixinInterface> & import("../../utils/mixins/index.types").Constructor<Component & import("../../utils/mixins/PreventScrollMixin").PreventScrollMixinInterface> & import("../../utils/mixins/index.types").Constructor<Component & import("../../utils/mixins/focus/FocusTrapMixin").FocusTrapClassInterface> & typeof Component;
6
7
  /**
7
8
  * Popover is generic overlay which can be triggered by any actionable element.
@@ -134,9 +135,22 @@ declare class Popover extends Popover_base {
134
135
  visible: boolean;
135
136
  /**
136
137
  * The offset of the popover.
138
+ *
139
+ * By default, offset is just a number which represents the distance on the main axis in pixels
140
+ * between the reference element and the popover. Main axis is determined by the placement of the popover.
141
+ * For example, if the placement is top or bottom, the main axis is vertical, and
142
+ * if the placement is left or right, the main axis is horizontal.
143
+ *
144
+ * Alternatively the offset property accepts other values as well:
145
+ * - with an object value, `crossAxis` and `alignmentAxis` can be changed as well
146
+ * - with a function value, it provides the opportunity to fully control the offset logic
147
+ *
148
+ * Note: only the number value reflected in the `offset` attribute
149
+ *
137
150
  * @default 4
151
+ * @see [Floating UI - offset](https://floating-ui.com/docs/offset)
138
152
  */
139
- offset: number;
153
+ offset: OffsetOptions;
140
154
  /**
141
155
  * This describes the clipping element(s) or area that overflow will be checked relative to.
142
156
  * The default is 'clippingAncestors', which are the overflow ancestors which will cause the
@@ -351,6 +365,7 @@ declare class Popover extends Popover_base {
351
365
  * @default null
352
366
  */
353
367
  elementIndexToReceiveFocus: number | null;
368
+ /** @internal */
354
369
  arrowElement: HTMLElement | null;
355
370
  /** @internal */
356
371
  private isHovered;
@@ -184,7 +184,20 @@ class Popover extends KeyDownHandledMixin(KeyToActionMixin(BackdropMixin(Prevent
184
184
  this.visible = DEFAULTS.VISIBLE;
185
185
  /**
186
186
  * The offset of the popover.
187
+ *
188
+ * By default, offset is just a number which represents the distance on the main axis in pixels
189
+ * between the reference element and the popover. Main axis is determined by the placement of the popover.
190
+ * For example, if the placement is top or bottom, the main axis is vertical, and
191
+ * if the placement is left or right, the main axis is horizontal.
192
+ *
193
+ * Alternatively the offset property accepts other values as well:
194
+ * - with an object value, `crossAxis` and `alignmentAxis` can be changed as well
195
+ * - with a function value, it provides the opportunity to fully control the offset logic
196
+ *
197
+ * Note: only the number value reflected in the `offset` attribute
198
+ *
187
199
  * @default 4
200
+ * @see [Floating UI - offset](https://floating-ui.com/docs/offset)
188
201
  */
189
202
  this.offset = DEFAULTS.OFFSET;
190
203
  /**
@@ -367,6 +380,7 @@ class Popover extends KeyDownHandledMixin(KeyToActionMixin(BackdropMixin(Prevent
367
380
  * @default null
368
381
  */
369
382
  this.elementIndexToReceiveFocus = null;
383
+ /** @internal */
370
384
  this.arrowElement = null;
371
385
  /** @internal */
372
386
  this.isHovered = false;
@@ -653,7 +667,6 @@ class Popover extends KeyDownHandledMixin(KeyToActionMixin(BackdropMixin(Prevent
653
667
  padding: this.boundaryPadding,
654
668
  }),
655
669
  ];
656
- let popoverOffset = this.offset;
657
670
  if (!this.disableFlip) {
658
671
  middleware.push(flip({
659
672
  boundary,
@@ -682,16 +695,16 @@ class Popover extends KeyDownHandledMixin(KeyToActionMixin(BackdropMixin(Prevent
682
695
  padding: 50,
683
696
  }));
684
697
  }
698
+ let arrowOffset = 0;
685
699
  if (this.showArrow) {
686
700
  this.arrowElement = this.renderRoot.querySelector('div[part="popover-arrow"]');
687
701
  if (this.arrowElement) {
688
702
  const arrowLen = this.arrowElement.offsetHeight;
689
- const arrowOffset = Math.sqrt(2 * arrowLen ** 2) / 2;
690
- popoverOffset += arrowOffset;
703
+ arrowOffset = Math.sqrt(2 * arrowLen ** 2) / 2;
691
704
  middleware.push(arrow({ element: this.arrowElement, padding: 12 }));
692
705
  }
693
706
  }
694
- middleware.push(offset(popoverOffset));
707
+ middleware.push(offset(typeof this.offset === 'number' ? this.offset + arrowOffset : this.offset));
695
708
  this.floatingUICleanupFunction = autoUpdate(triggerElement, this, async () => {
696
709
  const { triggerElement } = this;
697
710
  if (!triggerElement)
@@ -1017,8 +1030,16 @@ __decorate([
1017
1030
  __metadata("design:type", Boolean)
1018
1031
  ], Popover.prototype, "visible", void 0);
1019
1032
  __decorate([
1020
- property({ type: Number, reflect: true }),
1021
- __metadata("design:type", Number)
1033
+ property({
1034
+ type: Number,
1035
+ reflect: true,
1036
+ converter: {
1037
+ toAttribute(value) {
1038
+ return typeof value === 'number' ? value.toString() : '';
1039
+ },
1040
+ },
1041
+ }),
1042
+ __metadata("design:type", Object)
1022
1043
  ], Popover.prototype, "offset", void 0);
1023
1044
  __decorate([
1024
1045
  property({ type: String, reflect: true, attribute: 'boundary' }),
@@ -53,32 +53,46 @@ export class PopoverUtils {
53
53
  right: '',
54
54
  bottom: '',
55
55
  });
56
- const bridgeSize = `calc(${this.popover.showArrow ? '0.75rem + ' : ''}${this.popover.offset + 1}px)`;
57
- const popoverHeight = this.popover.offsetHeight || 0;
58
- const popoverWidth = this.popover.offsetWidth || 0;
59
- if (hoverBridge) {
56
+ const triggerEl = this.popover.triggerElement;
57
+ if (hoverBridge && triggerEl) {
58
+ const popoverBBox = this.popover.getBoundingClientRect();
59
+ const triggerBBox = triggerEl.getBoundingClientRect();
60
+ let bridgeSize = 0;
61
+ if (!triggerBBox)
62
+ return;
63
+ const popoverHeight = this.popover.offsetHeight || 0;
64
+ const popoverWidth = this.popover.offsetWidth || 0;
60
65
  const side = placement.split('-')[0];
66
+ // bridgeSize calculated here because, floating UI might flip side on the main axis, also it can be negative if the trigger and popover are overlapping
67
+ if (side === 'top' || side === 'bottom') {
68
+ bridgeSize = Math.max(0, Math.max(popoverBBox.top - triggerBBox.bottom, triggerBBox.top - popoverBBox.bottom));
69
+ }
70
+ else if (side === 'left' || side === 'right') {
71
+ bridgeSize = Math.max(0, Math.max(triggerBBox.left - popoverBBox.right, popoverBBox.left - triggerBBox.right));
72
+ }
73
+ // ensure bridge overlap
74
+ bridgeSize += 1;
61
75
  switch (side) {
62
76
  case 'top':
63
- hoverBridge.style.height = bridgeSize;
64
- hoverBridge.style.bottom = `calc(-1 * (${bridgeSize}))`;
77
+ hoverBridge.style.height = `${bridgeSize}px`;
78
+ hoverBridge.style.bottom = `calc(-1 * (${bridgeSize}px))`;
65
79
  hoverBridge.style.left = '50%';
66
80
  hoverBridge.style.width = `${popoverWidth}px`;
67
81
  break;
68
82
  case 'left':
69
83
  hoverBridge.style.height = `${popoverHeight}px`;
70
- hoverBridge.style.width = bridgeSize;
71
- hoverBridge.style.right = `calc(-1.5 * (${bridgeSize}))`;
84
+ hoverBridge.style.width = `${bridgeSize}px`;
85
+ hoverBridge.style.right = `calc(-1.5 * (${bridgeSize}px))`;
72
86
  break;
73
87
  case 'right':
74
88
  hoverBridge.style.height = `${popoverHeight}px`;
75
- hoverBridge.style.width = bridgeSize;
76
- hoverBridge.style.left = `calc(-0.5 * (${bridgeSize}))`;
89
+ hoverBridge.style.width = `${bridgeSize}px`;
90
+ hoverBridge.style.left = `calc(-0.5 * (${bridgeSize}px))`;
77
91
  break;
78
92
  case 'bottom':
79
93
  default:
80
- hoverBridge.style.height = bridgeSize;
81
- hoverBridge.style.top = `calc(-1 * (${bridgeSize}))`;
94
+ hoverBridge.style.height = `${bridgeSize}px`;
95
+ hoverBridge.style.top = `calc(-1 * (${bridgeSize}px))`;
82
96
  hoverBridge.style.left = '50%';
83
97
  hoverBridge.style.width = `${popoverWidth}px`;
84
98
  break;
@@ -11664,19 +11664,6 @@
11664
11664
  "module": "components/popover/popover.component.js"
11665
11665
  }
11666
11666
  },
11667
- {
11668
- "kind": "field",
11669
- "name": "arrowElement",
11670
- "type": {
11671
- "text": "HTMLElement | null"
11672
- },
11673
- "privacy": "public",
11674
- "default": "null",
11675
- "inheritedFrom": {
11676
- "name": "Popover",
11677
- "module": "components/popover/popover.component.js"
11678
- }
11679
- },
11680
11667
  {
11681
11668
  "kind": "field",
11682
11669
  "name": "backdrop",
@@ -12062,9 +12049,9 @@
12062
12049
  "kind": "field",
12063
12050
  "name": "offset",
12064
12051
  "type": {
12065
- "text": "number"
12052
+ "text": "OffsetOptions"
12066
12053
  },
12067
- "description": "The offset of the popover.",
12054
+ "description": "The offset of the popover.\n\nBy default, offset is just a number which represents the distance on the main axis in pixels\nbetween the reference element and the popover. Main axis is determined by the placement of the popover.\nFor example, if the placement is top or bottom, the main axis is vertical, and\nif the placement is left or right, the main axis is horizontal.\n\nAlternatively the offset property accepts other values as well:\n- with an object value, `crossAxis` and `alignmentAxis` can be changed as well\n- with a function value, it provides the opportunity to fully control the offset logic\n\nNote: only the number value reflected in the `offset` attribute",
12068
12055
  "default": "4",
12069
12056
  "attribute": "offset",
12070
12057
  "reflects": true,
@@ -12440,9 +12427,9 @@
12440
12427
  {
12441
12428
  "name": "offset",
12442
12429
  "type": {
12443
- "text": "number"
12430
+ "text": "OffsetOptions"
12444
12431
  },
12445
- "description": "The offset of the popover.",
12432
+ "description": "The offset of the popover.\n\nBy default, offset is just a number which represents the distance on the main axis in pixels\nbetween the reference element and the popover. Main axis is determined by the placement of the popover.\nFor example, if the placement is top or bottom, the main axis is vertical, and\nif the placement is left or right, the main axis is horizontal.\n\nAlternatively the offset property accepts other values as well:\n- with an object value, `crossAxis` and `alignmentAxis` can be changed as well\n- with a function value, it provides the opportunity to fully control the offset logic\n\nNote: only the number value reflected in the `offset` attribute",
12446
12433
  "default": "4",
12447
12434
  "fieldName": "offset",
12448
12435
  "inheritedFrom": {
@@ -25494,19 +25481,6 @@
25494
25481
  "module": "components/popover/popover.component.js"
25495
25482
  }
25496
25483
  },
25497
- {
25498
- "kind": "field",
25499
- "name": "arrowElement",
25500
- "type": {
25501
- "text": "HTMLElement | null"
25502
- },
25503
- "privacy": "public",
25504
- "default": "null",
25505
- "inheritedFrom": {
25506
- "name": "Popover",
25507
- "module": "components/popover/popover.component.js"
25508
- }
25509
- },
25510
25484
  {
25511
25485
  "kind": "field",
25512
25486
  "name": "backdrop",
@@ -26058,9 +26032,9 @@
26058
26032
  "kind": "field",
26059
26033
  "name": "offset",
26060
26034
  "type": {
26061
- "text": "number"
26035
+ "text": "OffsetOptions"
26062
26036
  },
26063
- "description": "The offset of the popover.",
26037
+ "description": "The offset of the popover.\n\nBy default, offset is just a number which represents the distance on the main axis in pixels\nbetween the reference element and the popover. Main axis is determined by the placement of the popover.\nFor example, if the placement is top or bottom, the main axis is vertical, and\nif the placement is left or right, the main axis is horizontal.\n\nAlternatively the offset property accepts other values as well:\n- with an object value, `crossAxis` and `alignmentAxis` can be changed as well\n- with a function value, it provides the opportunity to fully control the offset logic\n\nNote: only the number value reflected in the `offset` attribute",
26064
26038
  "default": "4",
26065
26039
  "attribute": "offset",
26066
26040
  "reflects": true,
@@ -26470,9 +26444,9 @@
26470
26444
  {
26471
26445
  "name": "offset",
26472
26446
  "type": {
26473
- "text": "number"
26447
+ "text": "OffsetOptions"
26474
26448
  },
26475
- "description": "The offset of the popover.",
26449
+ "description": "The offset of the popover.\n\nBy default, offset is just a number which represents the distance on the main axis in pixels\nbetween the reference element and the popover. Main axis is determined by the placement of the popover.\nFor example, if the placement is top or bottom, the main axis is vertical, and\nif the placement is left or right, the main axis is horizontal.\n\nAlternatively the offset property accepts other values as well:\n- with an object value, `crossAxis` and `alignmentAxis` can be changed as well\n- with a function value, it provides the opportunity to fully control the offset logic\n\nNote: only the number value reflected in the `offset` attribute",
26476
26450
  "default": "4",
26477
26451
  "fieldName": "offset",
26478
26452
  "inheritedFrom": {
@@ -31365,15 +31339,6 @@
31365
31339
  "attribute": "aria-labelledby",
31366
31340
  "reflects": true
31367
31341
  },
31368
- {
31369
- "kind": "field",
31370
- "name": "arrowElement",
31371
- "type": {
31372
- "text": "HTMLElement | null"
31373
- },
31374
- "privacy": "public",
31375
- "default": "null"
31376
- },
31377
31342
  {
31378
31343
  "kind": "field",
31379
31344
  "name": "backdrop",
@@ -31663,9 +31628,9 @@
31663
31628
  "kind": "field",
31664
31629
  "name": "offset",
31665
31630
  "type": {
31666
- "text": "number"
31631
+ "text": "OffsetOptions"
31667
31632
  },
31668
- "description": "The offset of the popover.",
31633
+ "description": "The offset of the popover.\n\nBy default, offset is just a number which represents the distance on the main axis in pixels\nbetween the reference element and the popover. Main axis is determined by the placement of the popover.\nFor example, if the placement is top or bottom, the main axis is vertical, and\nif the placement is left or right, the main axis is horizontal.\n\nAlternatively the offset property accepts other values as well:\n- with an object value, `crossAxis` and `alignmentAxis` can be changed as well\n- with a function value, it provides the opportunity to fully control the offset logic\n\nNote: only the number value reflected in the `offset` attribute",
31669
31634
  "default": "4",
31670
31635
  "attribute": "offset",
31671
31636
  "reflects": true
@@ -31902,9 +31867,9 @@
31902
31867
  {
31903
31868
  "name": "offset",
31904
31869
  "type": {
31905
- "text": "number"
31870
+ "text": "OffsetOptions"
31906
31871
  },
31907
- "description": "The offset of the popover.",
31872
+ "description": "The offset of the popover.\n\nBy default, offset is just a number which represents the distance on the main axis in pixels\nbetween the reference element and the popover. Main axis is determined by the placement of the popover.\nFor example, if the placement is top or bottom, the main axis is vertical, and\nif the placement is left or right, the main axis is horizontal.\n\nAlternatively the offset property accepts other values as well:\n- with an object value, `crossAxis` and `alignmentAxis` can be changed as well\n- with a function value, it provides the opportunity to fully control the offset logic\n\nNote: only the number value reflected in the `offset` attribute",
31908
31873
  "default": "4",
31909
31874
  "fieldName": "offset"
31910
31875
  },
@@ -48057,19 +48022,6 @@
48057
48022
  "module": "components/popover/popover.component.js"
48058
48023
  }
48059
48024
  },
48060
- {
48061
- "kind": "field",
48062
- "name": "arrowElement",
48063
- "type": {
48064
- "text": "HTMLElement | null"
48065
- },
48066
- "privacy": "public",
48067
- "default": "null",
48068
- "inheritedFrom": {
48069
- "name": "Popover",
48070
- "module": "components/popover/popover.component.js"
48071
- }
48072
- },
48073
48025
  {
48074
48026
  "kind": "field",
48075
48027
  "name": "backdrop",
@@ -48473,9 +48425,9 @@
48473
48425
  "kind": "field",
48474
48426
  "name": "offset",
48475
48427
  "type": {
48476
- "text": "number"
48428
+ "text": "OffsetOptions"
48477
48429
  },
48478
- "description": "The offset of the popover.",
48430
+ "description": "The offset of the popover.\n\nBy default, offset is just a number which represents the distance on the main axis in pixels\nbetween the reference element and the popover. Main axis is determined by the placement of the popover.\nFor example, if the placement is top or bottom, the main axis is vertical, and\nif the placement is left or right, the main axis is horizontal.\n\nAlternatively the offset property accepts other values as well:\n- with an object value, `crossAxis` and `alignmentAxis` can be changed as well\n- with a function value, it provides the opportunity to fully control the offset logic\n\nNote: only the number value reflected in the `offset` attribute",
48479
48431
  "default": "4",
48480
48432
  "attribute": "offset",
48481
48433
  "reflects": true,
@@ -48841,9 +48793,9 @@
48841
48793
  {
48842
48794
  "name": "offset",
48843
48795
  "type": {
48844
- "text": "number"
48796
+ "text": "OffsetOptions"
48845
48797
  },
48846
- "description": "The offset of the popover.",
48798
+ "description": "The offset of the popover.\n\nBy default, offset is just a number which represents the distance on the main axis in pixels\nbetween the reference element and the popover. Main axis is determined by the placement of the popover.\nFor example, if the placement is top or bottom, the main axis is vertical, and\nif the placement is left or right, the main axis is horizontal.\n\nAlternatively the offset property accepts other values as well:\n- with an object value, `crossAxis` and `alignmentAxis` can be changed as well\n- with a function value, it provides the opportunity to fully control the offset logic\n\nNote: only the number value reflected in the `offset` attribute",
48847
48799
  "default": "4",
48848
48800
  "fieldName": "offset",
48849
48801
  "inheritedFrom": {
@@ -49474,19 +49426,6 @@
49474
49426
  "module": "components/popover/popover.component.js"
49475
49427
  }
49476
49428
  },
49477
- {
49478
- "kind": "field",
49479
- "name": "arrowElement",
49480
- "type": {
49481
- "text": "HTMLElement | null"
49482
- },
49483
- "privacy": "public",
49484
- "default": "null",
49485
- "inheritedFrom": {
49486
- "name": "Popover",
49487
- "module": "components/popover/popover.component.js"
49488
- }
49489
- },
49490
49429
  {
49491
49430
  "kind": "field",
49492
49431
  "name": "backdrop",
@@ -49870,9 +49809,9 @@
49870
49809
  "kind": "field",
49871
49810
  "name": "offset",
49872
49811
  "type": {
49873
- "text": "number"
49812
+ "text": "OffsetOptions"
49874
49813
  },
49875
- "description": "The offset of the popover.",
49814
+ "description": "The offset of the popover.\n\nBy default, offset is just a number which represents the distance on the main axis in pixels\nbetween the reference element and the popover. Main axis is determined by the placement of the popover.\nFor example, if the placement is top or bottom, the main axis is vertical, and\nif the placement is left or right, the main axis is horizontal.\n\nAlternatively the offset property accepts other values as well:\n- with an object value, `crossAxis` and `alignmentAxis` can be changed as well\n- with a function value, it provides the opportunity to fully control the offset logic\n\nNote: only the number value reflected in the `offset` attribute",
49876
49815
  "default": "4",
49877
49816
  "attribute": "offset",
49878
49817
  "reflects": true,
@@ -50311,9 +50250,9 @@
50311
50250
  {
50312
50251
  "name": "offset",
50313
50252
  "type": {
50314
- "text": "number"
50253
+ "text": "OffsetOptions"
50315
50254
  },
50316
- "description": "The offset of the popover.",
50255
+ "description": "The offset of the popover.\n\nBy default, offset is just a number which represents the distance on the main axis in pixels\nbetween the reference element and the popover. Main axis is determined by the placement of the popover.\nFor example, if the placement is top or bottom, the main axis is vertical, and\nif the placement is left or right, the main axis is horizontal.\n\nAlternatively the offset property accepts other values as well:\n- with an object value, `crossAxis` and `alignmentAxis` can be changed as well\n- with a function value, it provides the opportunity to fully control the offset logic\n\nNote: only the number value reflected in the `offset` attribute",
50317
50256
  "default": "4",
50318
50257
  "fieldName": "offset",
50319
50258
  "inheritedFrom": {
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@momentum-design/components",
3
3
  "packageManager": "yarn@3.2.4",
4
- "version": "0.131.0",
4
+ "version": "0.131.1",
5
5
  "engines": {
6
6
  "node": ">=20.0.0",
7
7
  "npm": ">=8.0.0"