@momentum-design/components 0.30.1 → 0.31.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.
- package/dist/browser/index.js +150 -205
- package/dist/browser/index.js.map +4 -4
- package/dist/components/popover/index.d.ts +0 -1
- package/dist/components/popover/index.js +0 -1
- package/dist/components/popover/popover.component.d.ts +18 -9
- package/dist/components/popover/popover.component.js +71 -70
- package/dist/components/popover/popover.constants.d.ts +5 -1
- package/dist/components/popover/popover.constants.js +5 -2
- package/dist/components/popover/popover.styles.js +22 -25
- package/dist/components/popover/popover.types.d.ts +2 -1
- package/dist/components/popover/popover.utils.d.ts +1 -0
- package/dist/components/popover/popover.utils.js +30 -11
- package/dist/custom-elements.json +44 -436
- package/dist/react/index.d.ts +0 -1
- package/dist/react/index.js +0 -1
- package/dist/react/popover/index.d.ts +3 -2
- package/dist/react/popover/index.js +3 -2
- package/package.json +1 -1
- package/dist/components/modalcontainer/index.d.ts +0 -7
- package/dist/components/modalcontainer/index.js +0 -4
- package/dist/components/modalcontainer/modalcontainer.component.d.ts +0 -50
- package/dist/components/modalcontainer/modalcontainer.component.js +0 -96
- package/dist/components/modalcontainer/modalcontainer.constants.d.ts +0 -20
- package/dist/components/modalcontainer/modalcontainer.constants.js +0 -21
- package/dist/components/modalcontainer/modalcontainer.styles.d.ts +0 -2
- package/dist/components/modalcontainer/modalcontainer.styles.js +0 -45
- package/dist/components/modalcontainer/modalcontainer.types.d.ts +0 -4
- package/dist/components/modalcontainer/modalcontainer.types.js +0 -1
- package/dist/react/modalcontainer/index.d.ts +0 -17
- package/dist/react/modalcontainer/index.js +0 -26
- package/dist/utils/mixins/DataAriaDescribedbyMixin.d.ts +0 -6
- package/dist/utils/mixins/DataAriaDescribedbyMixin.js +0 -30
- package/dist/utils/mixins/DataAriaLabelledbyMixin.d.ts +0 -6
- package/dist/utils/mixins/DataAriaLabelledbyMixin.js +0 -29
@@ -1,8 +1,7 @@
|
|
1
1
|
import { CSSResult, PropertyValues } from 'lit';
|
2
2
|
import { Component } from '../../models';
|
3
|
-
import type { PopoverPlacement, PopoverTrigger } from './popover.types';
|
4
|
-
|
5
|
-
declare const Popover_base: import("../../utils/mixins/index.types").Constructor<import("../../utils/mixins/DataAriaLabelMixin").DataAriaLabelMixinInterface> & import("../../utils/mixins/index.types").Constructor<import("../../utils/mixins/DataAriaLabelledbyMixin").DataAriaLabelledbyMixinInterface> & import("../../utils/mixins/index.types").Constructor<import("../../utils/mixins/DataAriaDescribedbyMixin").DataAriaDescribedbyMixinInterface> & import("../../utils/mixins/index.types").Constructor<HTMLElement & import("../../utils/mixins/FocusTrapMixin").FocusTrapClassInterface> & typeof Component;
|
3
|
+
import type { PopoverPlacement, PopoverTrigger, PopoverColor } from './popover.types';
|
4
|
+
declare const Popover_base: import("../../utils/mixins/index.types").Constructor<HTMLElement & import("../../utils/mixins/FocusTrapMixin").FocusTrapClassInterface> & typeof Component;
|
6
5
|
/**
|
7
6
|
* Popover component is a lightweight floating UI element that displays additional content when triggered.
|
8
7
|
* It can be used for tooltips, dropdowns, or contextual menus.
|
@@ -10,18 +9,19 @@ declare const Popover_base: import("../../utils/mixins/index.types").Constructor
|
|
10
9
|
* supports dynamic height adjustments with scrollable content when needed。
|
11
10
|
*
|
12
11
|
* @dependency mdc-button
|
13
|
-
* @dependency mdc-modalcontainer
|
14
12
|
*
|
15
13
|
* @tagname mdc-popover
|
16
14
|
*
|
17
15
|
* @cssproperty --mdc-popover-arrow-border-radius - radius of the arrow border
|
18
16
|
* @cssproperty --mdc-popover-arrow-border - border of the arrow
|
19
17
|
* @cssproperty --mdc-popover-primary-background-color - primary background color of the popover
|
18
|
+
* @cssproperty --mdc-popover-border-color - border color of the popover
|
20
19
|
* @cssproperty --mdc-popover-inverted-background-color - inverted background color of the popover
|
21
20
|
* @cssproperty --mdc-popover-inverted-border-color - inverted border color of the popover
|
22
21
|
* @cssproperty --mdc-popover-inverted-text-color - inverted text color of the popover
|
22
|
+
* @cssproperty --mdc-popover-elevation-3 - elevation of the popover
|
23
23
|
*
|
24
|
-
* @slot - Default slot for
|
24
|
+
* @slot - Default slot for the popover content
|
25
25
|
*
|
26
26
|
*/
|
27
27
|
declare class Popover extends Popover_base {
|
@@ -68,7 +68,7 @@ declare class Popover extends Popover_base {
|
|
68
68
|
* - **contrast**
|
69
69
|
* @default tonal
|
70
70
|
*/
|
71
|
-
color:
|
71
|
+
color: PopoverColor;
|
72
72
|
/**
|
73
73
|
* The visibility of the popover.
|
74
74
|
* @default false
|
@@ -165,13 +165,20 @@ declare class Popover extends Popover_base {
|
|
165
165
|
* Role of the popover
|
166
166
|
* @default dialog
|
167
167
|
*/
|
168
|
-
|
168
|
+
role: HTMLElement['role'];
|
169
|
+
/**
|
170
|
+
* aria-labelledby for an interactive popover only, defaults to the trigger component id.
|
171
|
+
* Used in nested cases where the triggerComponent isn't the actual button.
|
172
|
+
*/
|
173
|
+
ariaLabelledby: string | null;
|
174
|
+
/**
|
175
|
+
* aria-describedby of the popover.
|
176
|
+
*/
|
177
|
+
ariaDescribedby: string | null;
|
169
178
|
arrowElement: HTMLElement | null;
|
170
179
|
/** @internal */
|
171
180
|
triggerElement: HTMLElement | null;
|
172
181
|
/** @internal */
|
173
|
-
containerElement: HTMLElement | null;
|
174
|
-
/** @internal */
|
175
182
|
private hoverTimer;
|
176
183
|
/** @internal */
|
177
184
|
private isTriggerClicked;
|
@@ -181,6 +188,8 @@ declare class Popover extends Popover_base {
|
|
181
188
|
private closeDelay;
|
182
189
|
/** @internal */
|
183
190
|
private utils;
|
191
|
+
/** @internal */
|
192
|
+
backdropElement: HTMLElement | null;
|
184
193
|
constructor();
|
185
194
|
protected firstUpdated(changedProperties: PropertyValues): Promise<void>;
|
186
195
|
disconnectedCallback(): Promise<void>;
|
@@ -15,11 +15,7 @@ import styles from './popover.styles';
|
|
15
15
|
import { Component } from '../../models';
|
16
16
|
import { FocusTrapMixin } from '../../utils/mixins/FocusTrapMixin';
|
17
17
|
import { popoverStack } from './popover.stack';
|
18
|
-
import { COLOR } from '
|
19
|
-
import { DEFAULTS, POPOVER_PLACEMENT, TRIGGER } from './popover.constants';
|
20
|
-
import { DataAriaLabelMixin } from '../../utils/mixins/DataAriaLabelMixin';
|
21
|
-
import { DataAriaDescribedbyMixin } from '../../utils/mixins/DataAriaDescribedbyMixin';
|
22
|
-
import { DataAriaLabelledbyMixin } from '../../utils/mixins/DataAriaLabelledbyMixin';
|
18
|
+
import { DEFAULTS, POPOVER_PLACEMENT, TRIGGER, COLOR } from './popover.constants';
|
23
19
|
import { PopoverEventManager } from './popover.events';
|
24
20
|
import { PopoverUtils } from './popover.utils';
|
25
21
|
/**
|
@@ -29,21 +25,22 @@ import { PopoverUtils } from './popover.utils';
|
|
29
25
|
* supports dynamic height adjustments with scrollable content when needed。
|
30
26
|
*
|
31
27
|
* @dependency mdc-button
|
32
|
-
* @dependency mdc-modalcontainer
|
33
28
|
*
|
34
29
|
* @tagname mdc-popover
|
35
30
|
*
|
36
31
|
* @cssproperty --mdc-popover-arrow-border-radius - radius of the arrow border
|
37
32
|
* @cssproperty --mdc-popover-arrow-border - border of the arrow
|
38
33
|
* @cssproperty --mdc-popover-primary-background-color - primary background color of the popover
|
34
|
+
* @cssproperty --mdc-popover-border-color - border color of the popover
|
39
35
|
* @cssproperty --mdc-popover-inverted-background-color - inverted background color of the popover
|
40
36
|
* @cssproperty --mdc-popover-inverted-border-color - inverted border color of the popover
|
41
37
|
* @cssproperty --mdc-popover-inverted-text-color - inverted text color of the popover
|
38
|
+
* @cssproperty --mdc-popover-elevation-3 - elevation of the popover
|
42
39
|
*
|
43
|
-
* @slot - Default slot for
|
40
|
+
* @slot - Default slot for the popover content
|
44
41
|
*
|
45
42
|
*/
|
46
|
-
class Popover extends
|
43
|
+
class Popover extends FocusTrapMixin(Component) {
|
47
44
|
constructor() {
|
48
45
|
super();
|
49
46
|
/**
|
@@ -186,13 +183,20 @@ class Popover extends DataAriaLabelMixin(DataAriaLabelledbyMixin(DataAriaDescrib
|
|
186
183
|
* Role of the popover
|
187
184
|
* @default dialog
|
188
185
|
*/
|
189
|
-
this.
|
186
|
+
this.role = DEFAULTS.ROLE;
|
187
|
+
/**
|
188
|
+
* aria-labelledby for an interactive popover only, defaults to the trigger component id.
|
189
|
+
* Used in nested cases where the triggerComponent isn't the actual button.
|
190
|
+
*/
|
191
|
+
this.ariaLabelledby = null;
|
192
|
+
/**
|
193
|
+
* aria-describedby of the popover.
|
194
|
+
*/
|
195
|
+
this.ariaDescribedby = null;
|
190
196
|
this.arrowElement = null;
|
191
197
|
/** @internal */
|
192
198
|
this.triggerElement = null;
|
193
199
|
/** @internal */
|
194
|
-
this.containerElement = null;
|
195
|
-
/** @internal */
|
196
200
|
this.hoverTimer = null;
|
197
201
|
/** @internal */
|
198
202
|
this.isTriggerClicked = false;
|
@@ -200,6 +204,8 @@ class Popover extends DataAriaLabelMixin(DataAriaLabelledbyMixin(DataAriaDescrib
|
|
200
204
|
this.openDelay = 0;
|
201
205
|
/** @internal */
|
202
206
|
this.closeDelay = 0;
|
207
|
+
/** @internal */
|
208
|
+
this.backdropElement = null;
|
203
209
|
/**
|
204
210
|
* Handles the outside click event to close the popover.
|
205
211
|
*
|
@@ -211,8 +217,7 @@ class Popover extends DataAriaLabelMixin(DataAriaLabelledbyMixin(DataAriaDescrib
|
|
211
217
|
let insidePopoverClick = false;
|
212
218
|
const path = event.composedPath();
|
213
219
|
insidePopoverClick = this.contains(event.target) || path.includes(this.triggerElement);
|
214
|
-
const
|
215
|
-
const clickedOnBackdrop = backdropElement ? path.includes(backdropElement) : false;
|
220
|
+
const clickedOnBackdrop = this.backdropElement ? path.includes(this.backdropElement) : false;
|
216
221
|
if (!insidePopoverClick || clickedOnBackdrop) {
|
217
222
|
this.hidePopover();
|
218
223
|
}
|
@@ -271,11 +276,7 @@ class Popover extends DataAriaLabelMixin(DataAriaLabelledbyMixin(DataAriaDescrib
|
|
271
276
|
this.cancelCloseDelay();
|
272
277
|
setTimeout(() => {
|
273
278
|
this.visible = true;
|
274
|
-
PopoverEventManager.onShowPopover(this);
|
275
279
|
}, this.openDelay);
|
276
|
-
if (popoverStack.peek() !== this) {
|
277
|
-
popoverStack.push(this);
|
278
|
-
}
|
279
280
|
};
|
280
281
|
/**
|
281
282
|
* Hides the popover.
|
@@ -284,10 +285,8 @@ class Popover extends DataAriaLabelMixin(DataAriaLabelledbyMixin(DataAriaDescrib
|
|
284
285
|
if (popoverStack.peek() === this) {
|
285
286
|
setTimeout(() => {
|
286
287
|
this.visible = false;
|
287
|
-
PopoverEventManager.onHidePopover(this);
|
288
288
|
this.isTriggerClicked = false;
|
289
289
|
}, this.closeDelay);
|
290
|
-
popoverStack.pop();
|
291
290
|
}
|
292
291
|
};
|
293
292
|
/**
|
@@ -306,20 +305,20 @@ class Popover extends DataAriaLabelMixin(DataAriaLabelledbyMixin(DataAriaDescrib
|
|
306
305
|
}
|
307
306
|
async firstUpdated(changedProperties) {
|
308
307
|
super.firstUpdated(changedProperties);
|
309
|
-
this.containerElement = this.renderRoot.querySelector('.popover-container');
|
310
308
|
this.utils.setupAppendTo();
|
311
309
|
[this.openDelay, this.closeDelay] = this.utils.setupDelay();
|
312
310
|
this.setupTriggerListener();
|
313
311
|
this.utils.setupAccessibility();
|
312
|
+
this.style.zIndex = `${this.zIndex}`;
|
314
313
|
PopoverEventManager.onCreatedPopover(this);
|
315
314
|
if (this.visible) {
|
316
|
-
|
315
|
+
this.positionPopover();
|
317
316
|
await this.handleCreatePopoverFirstUpdate();
|
318
317
|
}
|
319
318
|
}
|
320
319
|
async disconnectedCallback() {
|
321
320
|
super.disconnectedCallback();
|
322
|
-
|
321
|
+
this.removeEventListeners();
|
323
322
|
PopoverEventManager.onDestroyedPopover(this);
|
324
323
|
popoverStack.remove(this);
|
325
324
|
}
|
@@ -327,7 +326,6 @@ class Popover extends DataAriaLabelMixin(DataAriaLabelledbyMixin(DataAriaDescrib
|
|
327
326
|
* Sets up the trigger event listeners based on the trigger type.
|
328
327
|
*/
|
329
328
|
setupTriggerListener() {
|
330
|
-
var _a, _b;
|
331
329
|
if (!this.triggerID)
|
332
330
|
return;
|
333
331
|
this.triggerElement = document.getElementById(this.triggerID);
|
@@ -353,8 +351,8 @@ class Popover extends DataAriaLabelMixin(DataAriaLabelledbyMixin(DataAriaDescrib
|
|
353
351
|
const hoverBridge = this.renderRoot.querySelector('.popover-hover-bridge');
|
354
352
|
this.triggerElement.addEventListener('mouseenter', this.showPopover);
|
355
353
|
this.triggerElement.addEventListener('mouseleave', this.startCloseDelay);
|
356
|
-
|
357
|
-
|
354
|
+
this.addEventListener('mouseenter', this.cancelCloseDelay);
|
355
|
+
this.addEventListener('mouseleave', this.startCloseDelay);
|
358
356
|
hoverBridge === null || hoverBridge === void 0 ? void 0 : hoverBridge.addEventListener('mouseenter', this.cancelCloseDelay);
|
359
357
|
}
|
360
358
|
if (this.trigger.includes('focusin')) {
|
@@ -369,15 +367,14 @@ class Popover extends DataAriaLabelMixin(DataAriaLabelledbyMixin(DataAriaDescrib
|
|
369
367
|
* Removes the trigger event listeners.
|
370
368
|
*/
|
371
369
|
removeEventListeners() {
|
372
|
-
var _a, _b;
|
373
370
|
if (!this.triggerElement)
|
374
371
|
return;
|
375
372
|
const hoverBridge = this.renderRoot.querySelector('.popover-hover-bridge');
|
376
373
|
this.triggerElement.removeEventListener('click', this.togglePopoverVisible);
|
377
374
|
this.triggerElement.removeEventListener('mouseenter', this.showPopover);
|
378
375
|
this.triggerElement.removeEventListener('mouseleave', this.hidePopover);
|
379
|
-
|
380
|
-
|
376
|
+
this.removeEventListener('mouseenter', this.cancelCloseDelay);
|
377
|
+
this.removeEventListener('mouseleave', this.startCloseDelay);
|
381
378
|
this.triggerElement.removeEventListener('focusin', this.showPopover);
|
382
379
|
this.triggerElement.removeEventListener('focusout', this.hidePopover);
|
383
380
|
hoverBridge === null || hoverBridge === void 0 ? void 0 : hoverBridge.removeEventListener('mouseenter', this.cancelCloseDelay);
|
@@ -412,8 +409,8 @@ class Popover extends DataAriaLabelMixin(DataAriaLabelledbyMixin(DataAriaDescrib
|
|
412
409
|
this.utils.setupAppendTo();
|
413
410
|
}
|
414
411
|
if (changedProperties.has('interactive')
|
415
|
-
|| changedProperties.has('
|
416
|
-
|| changedProperties.has('
|
412
|
+
|| changedProperties.has('aria-label')
|
413
|
+
|| changedProperties.has('aria-labelledby')) {
|
417
414
|
this.utils.setupAccessibility();
|
418
415
|
}
|
419
416
|
}
|
@@ -425,22 +422,24 @@ class Popover extends DataAriaLabelMixin(DataAriaLabelledbyMixin(DataAriaDescrib
|
|
425
422
|
* @param newValue - The new value of the visible property.
|
426
423
|
*/
|
427
424
|
async isOpenUpdated(oldValue, newValue) {
|
428
|
-
var _a, _b, _c
|
425
|
+
var _a, _b, _c;
|
429
426
|
if (oldValue === newValue || !this.triggerElement) {
|
430
427
|
return;
|
431
428
|
}
|
432
429
|
if (newValue) {
|
430
|
+
if (popoverStack.peek() !== this) {
|
431
|
+
popoverStack.push(this);
|
432
|
+
}
|
433
433
|
this.enabledFocusTrap = this.focusTrap;
|
434
434
|
this.enabledPreventScroll = this.preventScroll;
|
435
435
|
if (this.backdrop) {
|
436
|
-
|
437
|
-
popoverBackdrop.style.zIndex = `${this.zIndex - 1}`;
|
436
|
+
this.utils.createBackdrop();
|
438
437
|
this.triggerElement.style.zIndex = `${this.zIndex}`;
|
439
438
|
}
|
440
439
|
this.positionPopover();
|
441
440
|
await this.handleCreatePopoverFirstUpdate();
|
442
441
|
if (this.hideOnBlur) {
|
443
|
-
|
442
|
+
this.addEventListener('focusout', this.onPopoverFocusOut);
|
444
443
|
if (this.trigger === 'click') {
|
445
444
|
this.triggerElement.style.pointerEvents = 'none';
|
446
445
|
}
|
@@ -455,10 +454,16 @@ class Popover extends DataAriaLabelMixin(DataAriaLabelledbyMixin(DataAriaDescrib
|
|
455
454
|
if (this.interactive) {
|
456
455
|
this.triggerElement.setAttribute('aria-haspopup', this.triggerElement.getAttribute('aria-haspopup') || 'dialog');
|
457
456
|
}
|
457
|
+
PopoverEventManager.onShowPopover(this);
|
458
458
|
}
|
459
459
|
else {
|
460
|
+
popoverStack.pop();
|
461
|
+
if (this.backdropElement) {
|
462
|
+
(_a = this.backdropElement) === null || _a === void 0 ? void 0 : _a.remove();
|
463
|
+
this.backdropElement = null;
|
464
|
+
}
|
460
465
|
if (this.hideOnBlur) {
|
461
|
-
|
466
|
+
this.removeEventListener('focusout', this.onPopoverFocusOut);
|
462
467
|
if (this.trigger === 'click') {
|
463
468
|
this.triggerElement.style.pointerEvents = '';
|
464
469
|
}
|
@@ -469,14 +474,15 @@ class Popover extends DataAriaLabelMixin(DataAriaLabelledbyMixin(DataAriaDescrib
|
|
469
474
|
if (this.hideOnEscape) {
|
470
475
|
document.removeEventListener('keydown', this.onEscapeKeydown);
|
471
476
|
}
|
472
|
-
(
|
477
|
+
(_b = this.deactivateFocusTrap) === null || _b === void 0 ? void 0 : _b.call(this);
|
473
478
|
this.triggerElement.removeAttribute('aria-expanded');
|
474
479
|
if (this.interactive) {
|
475
480
|
this.triggerElement.removeAttribute('aria-haspopup');
|
476
481
|
}
|
477
482
|
if (this.focusBackToTrigger) {
|
478
|
-
(
|
483
|
+
(_c = this.triggerElement) === null || _c === void 0 ? void 0 : _c.focus();
|
479
484
|
}
|
485
|
+
PopoverEventManager.onHidePopover(this);
|
480
486
|
}
|
481
487
|
}
|
482
488
|
/**
|
@@ -496,7 +502,7 @@ class Popover extends DataAriaLabelMixin(DataAriaLabelledbyMixin(DataAriaDescrib
|
|
496
502
|
* It uses the floating-ui/dom library to calculate the position.
|
497
503
|
*/
|
498
504
|
positionPopover() {
|
499
|
-
if (!this.triggerElement
|
505
|
+
if (!this.triggerElement)
|
500
506
|
return;
|
501
507
|
const middleware = [shift()];
|
502
508
|
let popoverOffset = this.offset;
|
@@ -504,7 +510,7 @@ class Popover extends DataAriaLabelMixin(DataAriaLabelledbyMixin(DataAriaDescrib
|
|
504
510
|
middleware.push(flip());
|
505
511
|
}
|
506
512
|
if (this.size) {
|
507
|
-
const popoverContent = this.
|
513
|
+
const popoverContent = this.renderRoot.querySelector('[part="popover-content"]');
|
508
514
|
middleware.push(size({
|
509
515
|
apply({ availableHeight }) {
|
510
516
|
if (!popoverContent)
|
@@ -526,10 +532,10 @@ class Popover extends DataAriaLabelMixin(DataAriaLabelledbyMixin(DataAriaDescrib
|
|
526
532
|
}
|
527
533
|
}
|
528
534
|
middleware.push(offset(popoverOffset));
|
529
|
-
autoUpdate(this.triggerElement, this
|
530
|
-
if (!this.triggerElement
|
535
|
+
autoUpdate(this.triggerElement, this, async () => {
|
536
|
+
if (!this.triggerElement)
|
531
537
|
return;
|
532
|
-
const { x, y, middlewareData, placement } = await computePosition(this.triggerElement, this
|
538
|
+
const { x, y, middlewareData, placement } = await computePosition(this.triggerElement, this, {
|
533
539
|
placement: this.placement,
|
534
540
|
middleware,
|
535
541
|
});
|
@@ -544,34 +550,21 @@ class Popover extends DataAriaLabelMixin(DataAriaLabelledbyMixin(DataAriaDescrib
|
|
544
550
|
}
|
545
551
|
render() {
|
546
552
|
return html `
|
547
|
-
|
548
|
-
|
549
|
-
class="popover-container"
|
550
|
-
elevation="3"
|
551
|
-
color=${this.color}
|
552
|
-
?data-aria-modal=${this.interactive}
|
553
|
-
data-role="${ifDefined(this.dataRole)}"
|
554
|
-
data-aria-label="${ifDefined(this.interactive ? this.dataAriaLabel : undefined)}"
|
555
|
-
data-aria-labelledby="${ifDefined(this.interactive ? this.dataAriaLabelledby : undefined)}"
|
556
|
-
data-aria-describedby="${ifDefined(this.interactive ? this.dataAriaDescribedby : undefined)}"
|
557
|
-
style="z-index: ${this.zIndex};"
|
558
|
-
>
|
559
|
-
<div class="popover-hover-bridge"></div>
|
560
|
-
${this.closeButton
|
553
|
+
<div class="popover-hover-bridge"></div>
|
554
|
+
${this.closeButton
|
561
555
|
? html ` <mdc-button
|
562
|
-
|
563
|
-
|
564
|
-
|
565
|
-
|
566
|
-
|
567
|
-
|
568
|
-
|
556
|
+
class="popover-close"
|
557
|
+
prefix-icon="cancel-bold"
|
558
|
+
variant="tertiary"
|
559
|
+
size="20"
|
560
|
+
aria-label=${ifDefined(this.closeButtonAriaLabel)}
|
561
|
+
@click="${this.hidePopover}"
|
562
|
+
></mdc-button>`
|
569
563
|
: nothing}
|
570
|
-
|
571
|
-
|
572
|
-
|
573
|
-
|
574
|
-
</mdc-modalcontainer>
|
564
|
+
${this.showArrow ? html `<div class="popover-arrow"></div>` : nothing}
|
565
|
+
<div part="popover-content">
|
566
|
+
<slot></slot>
|
567
|
+
</div>
|
575
568
|
`;
|
576
569
|
}
|
577
570
|
}
|
@@ -669,7 +662,15 @@ __decorate([
|
|
669
662
|
__metadata("design:type", Object)
|
670
663
|
], Popover.prototype, "closeButtonAriaLabel", void 0);
|
671
664
|
__decorate([
|
672
|
-
property({ type: String, reflect: true
|
665
|
+
property({ type: String, reflect: true }),
|
666
|
+
__metadata("design:type", Object)
|
667
|
+
], Popover.prototype, "role", void 0);
|
668
|
+
__decorate([
|
669
|
+
property({ type: String, reflect: true, attribute: 'aria-labelledby' }),
|
670
|
+
__metadata("design:type", Object)
|
671
|
+
], Popover.prototype, "ariaLabelledby", void 0);
|
672
|
+
__decorate([
|
673
|
+
property({ type: String, reflect: true, attribute: 'aria-describedby' }),
|
673
674
|
__metadata("design:type", Object)
|
674
|
-
], Popover.prototype, "
|
675
|
+
], Popover.prototype, "ariaDescribedby", void 0);
|
675
676
|
export default Popover;
|
@@ -19,6 +19,10 @@ declare const TRIGGER: {
|
|
19
19
|
readonly FOCUSIN: "focusin";
|
20
20
|
readonly MANUAL: "manual";
|
21
21
|
};
|
22
|
+
declare const COLOR: {
|
23
|
+
readonly TONAL: "tonal";
|
24
|
+
readonly CONTRAST: "contrast";
|
25
|
+
};
|
22
26
|
declare const DEFAULTS: {
|
23
27
|
readonly PLACEMENT: "bottom";
|
24
28
|
readonly TRIGGER: "click";
|
@@ -41,4 +45,4 @@ declare const DEFAULTS: {
|
|
41
45
|
readonly ROLE: "dialog";
|
42
46
|
readonly Z_INDEX: 1000;
|
43
47
|
};
|
44
|
-
export { TAG_NAME, POPOVER_PLACEMENT, TRIGGER, DEFAULTS };
|
48
|
+
export { TAG_NAME, POPOVER_PLACEMENT, COLOR, TRIGGER, DEFAULTS };
|
@@ -1,5 +1,4 @@
|
|
1
1
|
import utils from '../../utils/tag-name';
|
2
|
-
import { COLOR } from '../modalcontainer/modalcontainer.constants';
|
3
2
|
const TAG_NAME = utils.constructTagName('popover');
|
4
3
|
const POPOVER_PLACEMENT = {
|
5
4
|
LEFT_START: 'left-start',
|
@@ -21,6 +20,10 @@ const TRIGGER = {
|
|
21
20
|
FOCUSIN: 'focusin',
|
22
21
|
MANUAL: 'manual',
|
23
22
|
};
|
23
|
+
const COLOR = {
|
24
|
+
TONAL: 'tonal',
|
25
|
+
CONTRAST: 'contrast',
|
26
|
+
};
|
24
27
|
const DEFAULTS = {
|
25
28
|
PLACEMENT: POPOVER_PLACEMENT.BOTTOM,
|
26
29
|
TRIGGER: TRIGGER.CLICK,
|
@@ -43,4 +46,4 @@ const DEFAULTS = {
|
|
43
46
|
ROLE: 'dialog',
|
44
47
|
Z_INDEX: 1000,
|
45
48
|
};
|
46
|
-
export { TAG_NAME, POPOVER_PLACEMENT, TRIGGER, DEFAULTS };
|
49
|
+
export { TAG_NAME, POPOVER_PLACEMENT, COLOR, TRIGGER, DEFAULTS };
|
@@ -5,12 +5,33 @@ const styles = css `
|
|
5
5
|
--mdc-popover-arrow-border: 0.0625rem solid var(--mds-color-theme-outline-secondary-normal);
|
6
6
|
|
7
7
|
--mdc-popover-primary-background-color: var(--mds-color-theme-background-solid-primary-normal);
|
8
|
+
--mdc-popover-border-color: var(--mds-color-theme-outline-secondary-normal);
|
8
9
|
--mdc-popover-inverted-background-color: var(--mds-color-theme-inverted-background-normal);
|
9
10
|
--mdc-popover-inverted-border-color: var(--mds-color-theme-inverted-outline-primary-normal);
|
10
11
|
--mdc-popover-inverted-text-color: var(--mds-color-theme-inverted-text-primary-normal);
|
12
|
+
--mdc-popover-elevation-3: var(--mds-elevation-3);
|
13
|
+
|
14
|
+
display: none;
|
15
|
+
position: absolute;
|
16
|
+
box-sizing: content-box;
|
17
|
+
background-color: var(--mdc-popover-primary-background-color);
|
18
|
+
border-radius: 0.5rem;
|
19
|
+
border: 0.0625rem solid var(--mdc-popover-border-color);
|
20
|
+
filter: var(--mdc-popover-elevation-3);
|
21
|
+
}
|
22
|
+
|
23
|
+
:host([visible]) {
|
24
|
+
display: block;
|
25
|
+
}
|
26
|
+
|
27
|
+
:host([color='contrast']) {
|
28
|
+
background-color: var(--mdc-popover-inverted-background-color);
|
29
|
+
border-color: var(--mdc-popover-inverted-border-color);
|
30
|
+
color: var(--mds-color-theme-inverted-text-primary-normal);
|
11
31
|
}
|
12
32
|
|
13
|
-
:host([color='contrast'])
|
33
|
+
:host([color='contrast']) {
|
34
|
+
|
14
35
|
.popover-arrow {
|
15
36
|
background-color: var(--mdc-popover-inverted-background-color);
|
16
37
|
border-color: var(--mdc-popover-inverted-border-color);
|
@@ -21,20 +42,6 @@ const styles = css `
|
|
21
42
|
}
|
22
43
|
}
|
23
44
|
|
24
|
-
.popover-container {
|
25
|
-
display: none;
|
26
|
-
position: absolute;
|
27
|
-
box-sizing: content-box;
|
28
|
-
}
|
29
|
-
|
30
|
-
:host([visible]) .popover-container {
|
31
|
-
display: block;
|
32
|
-
}
|
33
|
-
|
34
|
-
.popover-container::part(container) {
|
35
|
-
padding: 0;
|
36
|
-
}
|
37
|
-
|
38
45
|
:host::part(popover-content) {
|
39
46
|
position: relative;
|
40
47
|
padding: 0.75rem;
|
@@ -43,16 +50,6 @@ const styles = css `
|
|
43
50
|
z-index: 9998;
|
44
51
|
}
|
45
52
|
|
46
|
-
.popover-backdrop {
|
47
|
-
z-index: 999;
|
48
|
-
position: fixed;
|
49
|
-
top: 0;
|
50
|
-
left: 0;
|
51
|
-
width: 100%;
|
52
|
-
height: 100%;
|
53
|
-
background: transparent;
|
54
|
-
}
|
55
|
-
|
56
53
|
.popover-hover-bridge {
|
57
54
|
position: absolute;
|
58
55
|
transform: translateX(-50%);
|
@@ -1,4 +1,5 @@
|
|
1
1
|
import type { ValueOf } from '../../utils/types';
|
2
|
-
import { POPOVER_PLACEMENT, TRIGGER } from './popover.constants';
|
2
|
+
import { POPOVER_PLACEMENT, TRIGGER, COLOR } from './popover.constants';
|
3
3
|
export type PopoverPlacement = ValueOf<typeof POPOVER_PLACEMENT>;
|
4
|
+
export type PopoverColor = ValueOf<typeof COLOR>;
|
4
5
|
export type PopoverTrigger = ValueOf<typeof TRIGGER> | `${ValueOf<typeof TRIGGER>} ${ValueOf<typeof TRIGGER>}`;
|
@@ -33,7 +33,6 @@ export class PopoverUtils {
|
|
33
33
|
* @param placement - The placement of the popover.
|
34
34
|
*/
|
35
35
|
setupHoverBridge(placement) {
|
36
|
-
var _a;
|
37
36
|
const hoverBridge = this.popover.renderRoot.querySelector('.popover-hover-bridge');
|
38
37
|
Object.assign(hoverBridge.style, {
|
39
38
|
top: '',
|
@@ -42,9 +41,8 @@ export class PopoverUtils {
|
|
42
41
|
bottom: '',
|
43
42
|
});
|
44
43
|
const bridgeSize = `calc(${this.popover.showArrow ? '0.75rem + ' : ''}${this.popover.offset}px)`;
|
45
|
-
const
|
46
|
-
const
|
47
|
-
const popoverWidth = modalContainer.offsetWidth || 0;
|
44
|
+
const popoverHeight = this.popover.offsetHeight || 0;
|
45
|
+
const popoverWidth = this.popover.offsetWidth || 0;
|
48
46
|
if (hoverBridge) {
|
49
47
|
const side = placement.split('-')[0];
|
50
48
|
switch (side) {
|
@@ -91,14 +89,15 @@ export class PopoverUtils {
|
|
91
89
|
*/
|
92
90
|
setupAccessibility() {
|
93
91
|
var _a, _b, _c;
|
92
|
+
this.popover.toggleAttribute('aria-modal', this.popover.interactive);
|
94
93
|
if (this.popover.interactive) {
|
95
|
-
if (!this.popover.
|
96
|
-
this.popover.
|
94
|
+
if (!this.popover.ariaLabel) {
|
95
|
+
this.popover.ariaLabel = ((_a = this.popover.triggerElement) === null || _a === void 0 ? void 0 : _a.ariaLabel)
|
97
96
|
|| ((_b = this.popover.triggerElement) === null || _b === void 0 ? void 0 : _b.textContent)
|
98
97
|
|| '';
|
99
98
|
}
|
100
|
-
if (!this.popover.
|
101
|
-
this.popover.
|
99
|
+
if (!this.popover.ariaLabelledby) {
|
100
|
+
this.popover.ariaLabelledby = ((_c = this.popover.triggerElement) === null || _c === void 0 ? void 0 : _c.id) || '';
|
102
101
|
}
|
103
102
|
}
|
104
103
|
}
|
@@ -146,11 +145,31 @@ export class PopoverUtils {
|
|
146
145
|
* @param y - The y position.
|
147
146
|
*/
|
148
147
|
updatePopoverStyle(x, y) {
|
149
|
-
|
150
|
-
return;
|
151
|
-
Object.assign(this.popover.containerElement.style, {
|
148
|
+
Object.assign(this.popover.style, {
|
152
149
|
left: `${x}px`,
|
153
150
|
top: `${y}px`,
|
154
151
|
});
|
155
152
|
}
|
153
|
+
createBackdrop() {
|
154
|
+
var _a;
|
155
|
+
if (!this.popover.backdropElement) {
|
156
|
+
const backdrop = document.createElement('div');
|
157
|
+
backdrop.classList.add('popover-backdrop');
|
158
|
+
(_a = this.popover.parentElement) === null || _a === void 0 ? void 0 : _a.appendChild(backdrop);
|
159
|
+
const styleElement = document.createElement('style');
|
160
|
+
styleElement.textContent = `
|
161
|
+
.popover-backdrop {
|
162
|
+
position: fixed;
|
163
|
+
top: 0;
|
164
|
+
left: 0;
|
165
|
+
width: 100%;
|
166
|
+
height: 100%;
|
167
|
+
background: transparent;
|
168
|
+
z-index: ${this.popover.zIndex - 1};
|
169
|
+
}
|
170
|
+
`;
|
171
|
+
backdrop.appendChild(styleElement);
|
172
|
+
this.popover.backdropElement = backdrop;
|
173
|
+
}
|
174
|
+
}
|
156
175
|
}
|