@momentum-design/components 0.34.0 → 0.35.0

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.
@@ -614,7 +614,7 @@ __decorate([
614
614
  __metadata("design:type", Boolean)
615
615
  ], Popover.prototype, "preventScroll", void 0);
616
616
  __decorate([
617
- property({ type: Boolean, attribute: 'show-arrow' }),
617
+ property({ type: Boolean, reflect: true, attribute: 'show-arrow' }),
618
618
  __metadata("design:type", Boolean)
619
619
  ], Popover.prototype, "showArrow", void 0);
620
620
  __decorate([
@@ -27,7 +27,7 @@ const styles = css `
27
27
  :host([color='contrast']) {
28
28
  background-color: var(--mdc-popover-inverted-background-color);
29
29
  border-color: var(--mdc-popover-inverted-border-color);
30
- color: var(--mds-color-theme-inverted-text-primary-normal);
30
+ color: var(--mdc-popover-inverted-text-color);
31
31
  }
32
32
 
33
33
  :host([color='contrast']) {
@@ -0,0 +1,7 @@
1
+ import Tooltip from './tooltip.component';
2
+ declare global {
3
+ interface HTMLElementTagNameMap {
4
+ ['mdc-tooltip']: Tooltip;
5
+ }
6
+ }
7
+ export default Tooltip;
@@ -0,0 +1,4 @@
1
+ import Tooltip from './tooltip.component';
2
+ import { TAG_NAME } from './tooltip.constants';
3
+ Tooltip.register(TAG_NAME);
4
+ export default Tooltip;
@@ -0,0 +1,59 @@
1
+ import type { CSSResult } from 'lit';
2
+ import type { PropertyValues } from '@lit/reactive-element';
3
+ import Popover from '../popover/popover.component';
4
+ import type { TooltipType } from './tooltip.types';
5
+ /**
6
+ * A tooltip is triggered by mouse hover or by keyboard focus
7
+ * and will disappear upon mouse exit or focus change.
8
+ *
9
+ * Note: Tooltips cannot contain content that can be focused or interacted with.
10
+ *
11
+ * @tagname mdc-tooltip
12
+ *
13
+ * @cssproperty --mdc-tooltip-max-width - The maximum width of the tooltip.
14
+ * @cssproperty --mdc-tooltip-padding - The padding of the tooltip.
15
+ * @cssproperty --mdc-tooltip-text-color - The text color of the tooltip.
16
+ * @cssproperty --mdc-tooltip-text-color-contrast - The text color of the tooltip when the color is contrast.
17
+ *
18
+ */
19
+ declare class Tooltip extends Popover {
20
+ /**
21
+ * The type of tooltip.
22
+ * - **description** sets aria-describedby on the trigger component which refers to the tooltip id.
23
+ * - **label** sets aria-labelledby on the trigger component which refers to the tooltip id.
24
+ * - **none** no aria props set on trigger component referring to the tooltip id.
25
+ * @default 'description'
26
+ */
27
+ tooltipType: TooltipType;
28
+ private defaultSlotNodes;
29
+ constructor();
30
+ /**
31
+ * @returns The tooltip text.
32
+ */
33
+ private getTooltipText;
34
+ /**
35
+ * Sets the type attribute for the tooltip component.
36
+ * If the provided type is not included in the TOOLTIP_TYPES,
37
+ * it defaults to the value specified in DEFAULTS.TOOLTIP_TYPE.
38
+ *
39
+ * @param type - The type to set.
40
+ */
41
+ private setTooltipType;
42
+ /**
43
+ * Updates the tooltip id if it is empty.
44
+ */
45
+ private onIdUpdated;
46
+ /**
47
+ * Updates the placement attribute if it is not a valid placement.
48
+ * Overriding the default from Popover
49
+ */
50
+ private onPlacementUpdated;
51
+ /**
52
+ * Updates the tooltip type attribute and sets the appropriate aria props on the trigger component.
53
+ * @param changedProperties - The changed properties.
54
+ */
55
+ private onTooltipTypeUpdated;
56
+ update(changedProperties: PropertyValues): void;
57
+ static styles: Array<CSSResult>;
58
+ }
59
+ export default Tooltip;
@@ -0,0 +1,175 @@
1
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
2
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
3
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
4
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
5
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
6
+ };
7
+ var __metadata = (this && this.__metadata) || function (k, v) {
8
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
9
+ };
10
+ import { property, queryAssignedNodes } from 'lit/decorators.js';
11
+ import { v4 as uuidv4 } from 'uuid';
12
+ import { DEFAULTS, TOOLTIP_TYPES } from './tooltip.constants';
13
+ import Popover from '../popover/popover.component';
14
+ import styles from './tooltip.styles';
15
+ import { POPOVER_PLACEMENT } from '../popover/popover.constants';
16
+ /**
17
+ * A tooltip is triggered by mouse hover or by keyboard focus
18
+ * and will disappear upon mouse exit or focus change.
19
+ *
20
+ * Note: Tooltips cannot contain content that can be focused or interacted with.
21
+ *
22
+ * @tagname mdc-tooltip
23
+ *
24
+ * @cssproperty --mdc-tooltip-max-width - The maximum width of the tooltip.
25
+ * @cssproperty --mdc-tooltip-padding - The padding of the tooltip.
26
+ * @cssproperty --mdc-tooltip-text-color - The text color of the tooltip.
27
+ * @cssproperty --mdc-tooltip-text-color-contrast - The text color of the tooltip when the color is contrast.
28
+ *
29
+ */
30
+ class Tooltip extends Popover {
31
+ constructor() {
32
+ super();
33
+ /**
34
+ * The type of tooltip.
35
+ * - **description** sets aria-describedby on the trigger component which refers to the tooltip id.
36
+ * - **label** sets aria-labelledby on the trigger component which refers to the tooltip id.
37
+ * - **none** no aria props set on trigger component referring to the tooltip id.
38
+ * @default 'description'
39
+ */
40
+ this.tooltipType = DEFAULTS.TOOLTIP_TYPE;
41
+ this.backdrop = false;
42
+ this.color = DEFAULTS.COLOR;
43
+ this.delay = DEFAULTS.DELAY;
44
+ this.focusTrap = false;
45
+ this.hideOnBlur = true;
46
+ this.hideOnEscape = true;
47
+ this.interactive = false;
48
+ this.offset = DEFAULTS.OFFSET;
49
+ this.placement = DEFAULTS.PLACEMENT;
50
+ this.role = 'tooltip';
51
+ this.showArrow = true;
52
+ this.trigger = 'mouseenter focusin';
53
+ this.visible = false;
54
+ this.enabledFocusTrap = false;
55
+ this.enabledPreventScroll = false;
56
+ this.flip = true;
57
+ this.focusTrap = false;
58
+ this.preventScroll = false;
59
+ this.closeButton = false;
60
+ this.hideOnOutsideClick = false;
61
+ this.focusBackToTrigger = false;
62
+ this.size = false;
63
+ this.disableAriaExpanded = true;
64
+ }
65
+ /**
66
+ * @returns The tooltip text.
67
+ */
68
+ getTooltipText() {
69
+ var _a, _b;
70
+ return (((_b = (_a = this.defaultSlotNodes) === null || _a === void 0 ? void 0 : _a.map((node) => node.textContent).join(' ')) === null || _b === void 0 ? void 0 : _b.trim()) || '');
71
+ }
72
+ /**
73
+ * Sets the type attribute for the tooltip component.
74
+ * If the provided type is not included in the TOOLTIP_TYPES,
75
+ * it defaults to the value specified in DEFAULTS.TOOLTIP_TYPE.
76
+ *
77
+ * @param type - The type to set.
78
+ */
79
+ setTooltipType(type) {
80
+ this.setAttribute('tooltip-type', Object.values(TOOLTIP_TYPES).includes(type) ? type : DEFAULTS.TOOLTIP_TYPE);
81
+ }
82
+ /**
83
+ * Updates the tooltip id if it is empty.
84
+ */
85
+ onIdUpdated() {
86
+ // Set tooltip ID if not set.
87
+ if (this.id.length === 0) {
88
+ this.id = `mdc-tooltip-${uuidv4()}`;
89
+ }
90
+ // Update the aria props on the trigger component to updated tooltip id.
91
+ const triggerElement = document.getElementById(this.triggerID);
92
+ if (triggerElement) {
93
+ switch (this.tooltipType) {
94
+ case TOOLTIP_TYPES.DESCRIPTION:
95
+ triggerElement.setAttribute('aria-describedby', this.id);
96
+ break;
97
+ case TOOLTIP_TYPES.LABEL:
98
+ triggerElement.setAttribute('aria-labelledby', this.id);
99
+ break;
100
+ default:
101
+ break;
102
+ }
103
+ }
104
+ }
105
+ /**
106
+ * Updates the placement attribute if it is not a valid placement.
107
+ * Overriding the default from Popover
108
+ */
109
+ onPlacementUpdated() {
110
+ if (!Object.values(POPOVER_PLACEMENT).includes(this.placement)) {
111
+ this.placement = DEFAULTS.PLACEMENT;
112
+ }
113
+ }
114
+ /**
115
+ * Updates the tooltip type attribute and sets the appropriate aria props on the trigger component.
116
+ * @param changedProperties - The changed properties.
117
+ */
118
+ onTooltipTypeUpdated(changedProperties) {
119
+ const previousTooltipType = changedProperties.get('tooltipType');
120
+ if (!Object.values(TOOLTIP_TYPES).includes(this.tooltipType)) {
121
+ this.setTooltipType(DEFAULTS.TOOLTIP_TYPE);
122
+ }
123
+ const triggerElement = document.getElementById(this.triggerID);
124
+ if (triggerElement) {
125
+ const tooltipText = this.getTooltipText();
126
+ switch (this.tooltipType) {
127
+ case TOOLTIP_TYPES.DESCRIPTION:
128
+ if (previousTooltipType === TOOLTIP_TYPES.LABEL) {
129
+ triggerElement.removeAttribute('aria-labelledby');
130
+ }
131
+ triggerElement.setAttribute('aria-describedby', this.id);
132
+ break;
133
+ case TOOLTIP_TYPES.LABEL:
134
+ if (previousTooltipType === TOOLTIP_TYPES.DESCRIPTION) {
135
+ triggerElement.removeAttribute('aria-describedby');
136
+ }
137
+ triggerElement.setAttribute('aria-labelledby', this.id);
138
+ break;
139
+ default:
140
+ if (previousTooltipType === TOOLTIP_TYPES.DESCRIPTION) {
141
+ triggerElement.removeAttribute('aria-describedby');
142
+ }
143
+ else if (previousTooltipType === TOOLTIP_TYPES.LABEL) {
144
+ triggerElement.removeAttribute('aria-labelledby');
145
+ }
146
+ break;
147
+ }
148
+ if (tooltipText.length > 0 && this.tooltipType !== TOOLTIP_TYPES.NONE && !this.ariaLabel) {
149
+ this.ariaLabel = tooltipText;
150
+ }
151
+ }
152
+ }
153
+ update(changedProperties) {
154
+ super.update(changedProperties);
155
+ if (changedProperties.has('id')) {
156
+ this.onIdUpdated();
157
+ }
158
+ if (changedProperties.has('placement')) {
159
+ this.onPlacementUpdated();
160
+ }
161
+ if (changedProperties.has('tooltipType')) {
162
+ this.onTooltipTypeUpdated(changedProperties);
163
+ }
164
+ }
165
+ }
166
+ Tooltip.styles = [...Popover.styles, ...styles];
167
+ __decorate([
168
+ property({ type: String, attribute: 'tooltip-type', reflect: true }),
169
+ __metadata("design:type", String)
170
+ ], Tooltip.prototype, "tooltipType", void 0);
171
+ __decorate([
172
+ queryAssignedNodes(),
173
+ __metadata("design:type", Array)
174
+ ], Tooltip.prototype, "defaultSlotNodes", void 0);
175
+ export default Tooltip;
@@ -0,0 +1,16 @@
1
+ declare const TAG_NAME: "mdc-tooltip";
2
+ declare const TOOLTIP_TYPES: {
3
+ DESCRIPTION: string;
4
+ LABEL: string;
5
+ NONE: string;
6
+ };
7
+ declare const DEFAULTS: {
8
+ BACKDROP: boolean;
9
+ COLOR: "tonal";
10
+ DELAY: string;
11
+ OFFSET: number;
12
+ PLACEMENT: "top";
13
+ SHOW_ARROW: boolean;
14
+ TOOLTIP_TYPE: string;
15
+ };
16
+ export { DEFAULTS, TAG_NAME, TOOLTIP_TYPES };
@@ -0,0 +1,18 @@
1
+ import utils from '../../utils/tag-name';
2
+ import { COLOR, POPOVER_PLACEMENT } from '../popover/popover.constants';
3
+ const TAG_NAME = utils.constructTagName('tooltip');
4
+ const TOOLTIP_TYPES = {
5
+ DESCRIPTION: 'description',
6
+ LABEL: 'label',
7
+ NONE: 'none',
8
+ };
9
+ const DEFAULTS = {
10
+ BACKDROP: false,
11
+ COLOR: COLOR.TONAL,
12
+ DELAY: '0,0',
13
+ OFFSET: 4,
14
+ PLACEMENT: POPOVER_PLACEMENT.TOP,
15
+ SHOW_ARROW: true,
16
+ TOOLTIP_TYPE: TOOLTIP_TYPES.DESCRIPTION,
17
+ };
18
+ export { DEFAULTS, TAG_NAME, TOOLTIP_TYPES };
@@ -0,0 +1,2 @@
1
+ declare const _default: import("lit").CSSResult[];
2
+ export default _default;
@@ -0,0 +1,28 @@
1
+ import { css } from 'lit';
2
+ const styles = css `
3
+
4
+ :host {
5
+ --mdc-tooltip-max-width: 400px;
6
+ --mdc-tooltip-padding: 0.75rem;
7
+ --mdc-tooltip-text-color: var(--mds-color-theme-text-primary-normal);
8
+ --mdc-tooltip-text-color-contrast: var(--mds-color-theme-inverted-text-primary-normal);
9
+ }
10
+
11
+ :host::part(popover-content) {
12
+ padding: var(--mdc-tooltip-padding);
13
+ color: var(--mdc-tooltip-text-color);
14
+ min-width: fit-content;
15
+ max-width: var(--mdc-tooltip-max-width);
16
+
17
+ font-size: var(--mds-font-apps-body-midsize-regular-font-size);
18
+ font-weight: var(--mds-font-apps-body-midsize-regular-font-weight);
19
+ line-height: var(--mds-font-apps-body-midsize-regular-line-height);
20
+ text-decoration: var(--mds-font-apps-body-midsize-regular-text-decoration);
21
+ text-transform: var(--mds-font-apps-body-midsize-regular-text-case);
22
+ }
23
+
24
+ :host([color='contrast'])::part(popover-content) {
25
+ color: var(--mdc-tooltip-text-color-contrast);
26
+ }
27
+ `;
28
+ export default [styles];
@@ -0,0 +1,3 @@
1
+ import { ValueOf } from '../../utils/types';
2
+ import { TOOLTIP_TYPES } from './tooltip.constants';
3
+ export type TooltipType = ValueOf<typeof TOOLTIP_TYPES>;
@@ -0,0 +1 @@
1
+ export {};