@vaadin/tooltip 24.2.0-beta3 → 24.2.0-beta4

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vaadin/tooltip",
3
- "version": "24.2.0-beta3",
3
+ "version": "24.2.0-beta4",
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },
@@ -21,9 +21,6 @@
21
21
  "type": "module",
22
22
  "files": [
23
23
  "src",
24
- "!src/vaadin-lit-tooltip-overlay.js",
25
- "!src/vaadin-lit-tooltip.d.ts",
26
- "!src/vaadin-lit-tooltip.js",
27
24
  "theme",
28
25
  "vaadin-*.d.ts",
29
26
  "vaadin-*.js",
@@ -37,14 +34,13 @@
37
34
  "web-component"
38
35
  ],
39
36
  "dependencies": {
40
- "@open-wc/dedupe-mixin": "^1.3.0",
41
37
  "@polymer/polymer": "^3.0.0",
42
- "@vaadin/a11y-base": "24.2.0-beta3",
43
- "@vaadin/component-base": "24.2.0-beta3",
44
- "@vaadin/overlay": "24.2.0-beta3",
45
- "@vaadin/vaadin-lumo-styles": "24.2.0-beta3",
46
- "@vaadin/vaadin-material-styles": "24.2.0-beta3",
47
- "@vaadin/vaadin-themable-mixin": "24.2.0-beta3"
38
+ "@vaadin/a11y-base": "24.2.0-beta4",
39
+ "@vaadin/component-base": "24.2.0-beta4",
40
+ "@vaadin/overlay": "24.2.0-beta4",
41
+ "@vaadin/vaadin-lumo-styles": "24.2.0-beta4",
42
+ "@vaadin/vaadin-material-styles": "24.2.0-beta4",
43
+ "@vaadin/vaadin-themable-mixin": "24.2.0-beta4"
48
44
  },
49
45
  "devDependencies": {
50
46
  "@esm-bundle/chai": "^4.3.4",
@@ -55,5 +51,5 @@
55
51
  "web-types.json",
56
52
  "web-types.lit.json"
57
53
  ],
58
- "gitHead": "91ea11e7ad706065340acdb93b92316919ce5e69"
54
+ "gitHead": "04da1e1e5c5713ea45e4b7d659dc6ac6b4604f4c"
59
55
  }
@@ -6,10 +6,46 @@
6
6
  import { html, PolymerElement } from '@polymer/polymer/polymer-element.js';
7
7
  import { defineCustomElement } from '@vaadin/component-base/src/define.js';
8
8
  import { DirMixin } from '@vaadin/component-base/src/dir-mixin.js';
9
+ import { OverlayMixin } from '@vaadin/overlay/src/vaadin-overlay-mixin.js';
10
+ import { PositionMixin } from '@vaadin/overlay/src/vaadin-overlay-position-mixin.js';
9
11
  import { overlayStyles } from '@vaadin/overlay/src/vaadin-overlay-styles.js';
10
- import { registerStyles, ThemableMixin } from '@vaadin/vaadin-themable-mixin/vaadin-themable-mixin.js';
11
- import { TooltipOverlayMixin } from './vaadin-tooltip-overlay-mixin.js';
12
- import { tooltipOverlayStyles } from './vaadin-tooltip-overlay-styles.js';
12
+ import { css, registerStyles, ThemableMixin } from '@vaadin/vaadin-themable-mixin/vaadin-themable-mixin.js';
13
+
14
+ const tooltipOverlayStyles = css`
15
+ :host {
16
+ z-index: 1100;
17
+ }
18
+
19
+ [part='overlay'] {
20
+ max-width: 40ch;
21
+ }
22
+
23
+ :host([position^='top'][top-aligned]) [part='overlay'],
24
+ :host([position^='bottom'][top-aligned]) [part='overlay'] {
25
+ margin-top: var(--vaadin-tooltip-offset-top, 0);
26
+ }
27
+
28
+ :host([position^='top'][bottom-aligned]) [part='overlay'],
29
+ :host([position^='bottom'][bottom-aligned]) [part='overlay'] {
30
+ margin-bottom: var(--vaadin-tooltip-offset-bottom, 0);
31
+ }
32
+
33
+ :host([position^='start'][start-aligned]) [part='overlay'],
34
+ :host([position^='end'][start-aligned]) [part='overlay'] {
35
+ margin-inline-start: var(--vaadin-tooltip-offset-start, 0);
36
+ }
37
+
38
+ :host([position^='start'][end-aligned]) [part='overlay'],
39
+ :host([position^='end'][end-aligned]) [part='overlay'] {
40
+ margin-inline-end: var(--vaadin-tooltip-offset-end, 0);
41
+ }
42
+
43
+ @media (forced-colors: active) {
44
+ [part='overlay'] {
45
+ outline: 1px dashed;
46
+ }
47
+ }
48
+ `;
13
49
 
14
50
  registerStyles('vaadin-tooltip-overlay', [overlayStyles, tooltipOverlayStyles], {
15
51
  moduleId: 'vaadin-tooltip-overlay-styles',
@@ -21,11 +57,12 @@ registerStyles('vaadin-tooltip-overlay', [overlayStyles, tooltipOverlayStyles],
21
57
  * @customElement
22
58
  * @extends HTMLElement
23
59
  * @mixes DirMixin
60
+ * @mixes OverlayMixin
61
+ * @mixes PositionMixin
24
62
  * @mixes ThemableMixin
25
- * @mixes TooltipOverlayMixin
26
63
  * @private
27
64
  */
28
- class TooltipOverlay extends TooltipOverlayMixin(DirMixin(ThemableMixin(PolymerElement))) {
65
+ class TooltipOverlay extends PositionMixin(OverlayMixin(DirMixin(ThemableMixin(PolymerElement)))) {
29
66
  static get is() {
30
67
  return 'vaadin-tooltip-overlay';
31
68
  }
@@ -39,6 +76,15 @@ class TooltipOverlay extends TooltipOverlayMixin(DirMixin(ThemableMixin(PolymerE
39
76
  `;
40
77
  }
41
78
 
79
+ static get properties() {
80
+ return {
81
+ position: {
82
+ type: String,
83
+ reflectToAttribute: true,
84
+ },
85
+ };
86
+ }
87
+
42
88
  /** @protected */
43
89
  ready() {
44
90
  super.ready();
@@ -49,6 +95,66 @@ class TooltipOverlay extends TooltipOverlayMixin(DirMixin(ThemableMixin(PolymerE
49
95
  this.owner = this.__dataHost;
50
96
  this.owner._overlayElement = this;
51
97
  }
98
+
99
+ requestContentUpdate() {
100
+ super.requestContentUpdate();
101
+
102
+ this.toggleAttribute('hidden', this.textContent.trim() === '');
103
+
104
+ // Copy custom properties from the tooltip
105
+ if (this.positionTarget && this.owner) {
106
+ const style = getComputedStyle(this.owner);
107
+ ['top', 'bottom', 'start', 'end'].forEach((prop) => {
108
+ this.style.setProperty(
109
+ `--vaadin-tooltip-offset-${prop}`,
110
+ style.getPropertyValue(`--vaadin-tooltip-offset-${prop}`),
111
+ );
112
+ });
113
+ }
114
+ }
115
+
116
+ /**
117
+ * @protected
118
+ * @override
119
+ */
120
+ _updatePosition() {
121
+ super._updatePosition();
122
+
123
+ if (!this.positionTarget) {
124
+ return;
125
+ }
126
+
127
+ // Center the tooltip overlay horizontally
128
+ if (this.position === 'bottom' || this.position === 'top') {
129
+ const targetRect = this.positionTarget.getBoundingClientRect();
130
+ const overlayRect = this.$.overlay.getBoundingClientRect();
131
+
132
+ const offset = targetRect.width / 2 - overlayRect.width / 2;
133
+
134
+ if (this.style.left) {
135
+ const left = overlayRect.left + offset;
136
+ if (left > 0) {
137
+ this.style.left = `${left}px`;
138
+ }
139
+ }
140
+
141
+ if (this.style.right) {
142
+ const right = parseFloat(this.style.right) + offset;
143
+ if (right > 0) {
144
+ this.style.right = `${right}px`;
145
+ }
146
+ }
147
+ }
148
+
149
+ // Center the tooltip overlay vertically
150
+ if (this.position === 'start' || this.position === 'end') {
151
+ const targetRect = this.positionTarget.getBoundingClientRect();
152
+ const overlayRect = this.$.overlay.getBoundingClientRect();
153
+
154
+ const offset = targetRect.height / 2 - overlayRect.height / 2;
155
+ this.style.top = `${overlayRect.top + offset}px`;
156
+ }
157
+ }
52
158
  }
53
159
 
54
160
  defineCustomElement(TooltipOverlay);
@@ -5,10 +5,22 @@
5
5
  */
6
6
  import { ControllerMixin } from '@vaadin/component-base/src/controller-mixin.js';
7
7
  import { ElementMixin } from '@vaadin/component-base/src/element-mixin.js';
8
+ import { OverlayClassMixin } from '@vaadin/component-base/src/overlay-class-mixin.js';
8
9
  import { ThemePropertyMixin } from '@vaadin/vaadin-themable-mixin/vaadin-theme-property-mixin.js';
9
- import { TooltipMixin } from './vaadin-tooltip-mixin.js';
10
10
 
11
- export { TooltipPosition } from './vaadin-tooltip-mixin.js';
11
+ export type TooltipPosition =
12
+ | 'bottom-end'
13
+ | 'bottom-start'
14
+ | 'bottom'
15
+ | 'end-bottom'
16
+ | 'end-top'
17
+ | 'end'
18
+ | 'start-bottom'
19
+ | 'start-top'
20
+ | 'start'
21
+ | 'top-end'
22
+ | 'top-start'
23
+ | 'top';
12
24
 
13
25
  /**
14
26
  * `<vaadin-tooltip>` is a Web Component for creating tooltips.
@@ -48,7 +60,117 @@ export { TooltipPosition } from './vaadin-tooltip-mixin.js';
48
60
  *
49
61
  * See [Styling Components](https://vaadin.com/docs/latest/styling/styling-components) documentation.
50
62
  */
51
- declare class Tooltip extends TooltipMixin(ThemePropertyMixin(ControllerMixin(ElementMixin(HTMLElement)))) {}
63
+ declare class Tooltip extends OverlayClassMixin(ThemePropertyMixin(ControllerMixin(ElementMixin(HTMLElement)))) {
64
+ /**
65
+ * Sets the default focus delay to be used by all tooltip instances,
66
+ * except for those that have focus delay configured using property.
67
+ */
68
+ static setDefaultFocusDelay(focusDelay: number): void;
69
+
70
+ /**
71
+ * Sets the default hide delay to be used by all tooltip instances,
72
+ * except for those that have hide delay configured using property.
73
+ */
74
+ static setDefaultHideDelay(hideDelay: number): void;
75
+
76
+ /**
77
+ * Sets the default hover delay to be used by all tooltip instances,
78
+ * except for those that have hover delay configured using property.
79
+ */
80
+ static setDefaultHoverDelay(delay: number): void;
81
+
82
+ /**
83
+ * Element used to link with the `aria-describedby`
84
+ * attribute. Supports array of multiple elements.
85
+ * When not set, defaults to `target`.
86
+ */
87
+ ariaTarget: HTMLElement | HTMLElement[] | undefined;
88
+
89
+ /**
90
+ * Object with properties passed to `generator` and
91
+ * `shouldShow` functions for generating tooltip text
92
+ * or detecting whether to show the tooltip or not.
93
+ */
94
+ context: Record<string, unknown>;
95
+
96
+ /**
97
+ * The delay in milliseconds before the tooltip
98
+ * is opened on keyboard focus, when not in manual mode.
99
+ * @attr {number} focus-delay
100
+ */
101
+ focusDelay: number;
102
+
103
+ /**
104
+ * The id of the element used as a tooltip trigger.
105
+ * The element should be in the DOM by the time when
106
+ * the attribute is set, otherwise a warning is shown.
107
+ */
108
+ for: string | undefined;
109
+
110
+ /**
111
+ * The delay in milliseconds before the tooltip
112
+ * is closed on losing hover, when not in manual mode.
113
+ * On blur, the tooltip is closed immediately.
114
+ * @attr {number} hide-delay
115
+ */
116
+ hideDelay: number;
117
+
118
+ /**
119
+ * The delay in milliseconds before the tooltip
120
+ * is opened on hover, when not in manual mode.
121
+ * @attr {number} hover-delay
122
+ */
123
+ hoverDelay: number;
124
+
125
+ /**
126
+ * When true, the tooltip is controlled programmatically
127
+ * instead of reacting to focus and mouse events.
128
+ */
129
+ manual: boolean;
130
+
131
+ /**
132
+ * When true, the tooltip is opened programmatically.
133
+ * Only works if `manual` is set to `true`.
134
+ */
135
+ opened: boolean;
136
+
137
+ /**
138
+ * Position of the tooltip with respect to its target.
139
+ * Supported values: `top-start`, `top`, `top-end`,
140
+ * `bottom-start`, `bottom`, `bottom-end`, `start-top`,
141
+ * `start`, `start-bottom`, `end-top`, `end`, `end-bottom`.
142
+ */
143
+ position: TooltipPosition;
144
+
145
+ /**
146
+ * Function used to detect whether to show the tooltip based on a condition,
147
+ * called every time the tooltip is about to be shown on hover and focus.
148
+ * The function takes two parameters: `target` and `context`, which contain
149
+ * values of the corresponding tooltip properties at the time of calling.
150
+ * The tooltip is only shown when the function invocation returns `true`.
151
+ */
152
+ shouldShow: (target: HTMLElement, context?: Record<string, unknown>) => boolean;
153
+
154
+ /**
155
+ * Reference to the element used as a tooltip trigger.
156
+ * The target must be placed in the same shadow scope.
157
+ * Defaults to an element referenced with `for`.
158
+ */
159
+ target: HTMLElement | undefined;
160
+
161
+ /**
162
+ * String used as a tooltip content.
163
+ */
164
+ text: string | null | undefined;
165
+
166
+ /**
167
+ * Function used to generate the tooltip content.
168
+ * When provided, it overrides the `text` property.
169
+ * Use the `context` property to provide argument
170
+ * that can be passed to the generator function.
171
+ */
172
+ generator: (context: Record<string, unknown>) => string;
173
+ }
52
174
 
53
175
  declare global {
54
176
  interface HTMLElementTagNameMap {