@vaadin/tooltip 24.3.0-alpha1 → 24.3.0-alpha3

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.
@@ -0,0 +1,86 @@
1
+ /**
2
+ * @license
3
+ * Copyright (c) 2022 - 2023 Vaadin Ltd.
4
+ * This program is available under Apache License Version 2.0, available at https://vaadin.com/license/
5
+ */
6
+ import { OverlayMixin } from '@vaadin/overlay/src/vaadin-overlay-mixin.js';
7
+ import { PositionMixin } from '@vaadin/overlay/src/vaadin-overlay-position-mixin.js';
8
+
9
+ /**
10
+ * A mixin providing common tooltip overlay functionality.
11
+ *
12
+ * @polymerMixin
13
+ * @mixes PositionMixin
14
+ * @mixes OverlayMixin
15
+ */
16
+ export const TooltipOverlayMixin = (superClass) =>
17
+ class TooltipOverlayMixinClass extends PositionMixin(OverlayMixin(superClass)) {
18
+ static get properties() {
19
+ return {
20
+ position: {
21
+ type: String,
22
+ reflectToAttribute: true,
23
+ },
24
+ };
25
+ }
26
+
27
+ requestContentUpdate() {
28
+ super.requestContentUpdate();
29
+
30
+ this.toggleAttribute('hidden', this.textContent.trim() === '');
31
+
32
+ // Copy custom properties from the tooltip
33
+ if (this.positionTarget && this.owner) {
34
+ const style = getComputedStyle(this.owner);
35
+ ['top', 'bottom', 'start', 'end'].forEach((prop) => {
36
+ this.style.setProperty(
37
+ `--vaadin-tooltip-offset-${prop}`,
38
+ style.getPropertyValue(`--vaadin-tooltip-offset-${prop}`),
39
+ );
40
+ });
41
+ }
42
+ }
43
+
44
+ /**
45
+ * @protected
46
+ * @override
47
+ */
48
+ _updatePosition() {
49
+ super._updatePosition();
50
+
51
+ if (!this.positionTarget) {
52
+ return;
53
+ }
54
+
55
+ // Center the tooltip overlay horizontally
56
+ if (this.position === 'bottom' || this.position === 'top') {
57
+ const targetRect = this.positionTarget.getBoundingClientRect();
58
+ const overlayRect = this.$.overlay.getBoundingClientRect();
59
+
60
+ const offset = targetRect.width / 2 - overlayRect.width / 2;
61
+
62
+ if (this.style.left) {
63
+ const left = overlayRect.left + offset;
64
+ if (left > 0) {
65
+ this.style.left = `${left}px`;
66
+ }
67
+ }
68
+
69
+ if (this.style.right) {
70
+ const right = parseFloat(this.style.right) + offset;
71
+ if (right > 0) {
72
+ this.style.right = `${right}px`;
73
+ }
74
+ }
75
+ }
76
+
77
+ // Center the tooltip overlay vertically
78
+ if (this.position === 'start' || this.position === 'end') {
79
+ const targetRect = this.positionTarget.getBoundingClientRect();
80
+ const overlayRect = this.$.overlay.getBoundingClientRect();
81
+
82
+ const offset = targetRect.height / 2 - overlayRect.height / 2;
83
+ this.style.top = `${overlayRect.top + offset}px`;
84
+ }
85
+ }
86
+ };
@@ -0,0 +1,8 @@
1
+ /**
2
+ * @license
3
+ * Copyright (c) 2022 - 2023 Vaadin Ltd.
4
+ * This program is available under Apache License Version 2.0, available at https://vaadin.com/license/
5
+ */
6
+ import type { CSSResult } from 'lit';
7
+
8
+ export const tooltipOverlayStyles: CSSResult;
@@ -0,0 +1,42 @@
1
+ /**
2
+ * @license
3
+ * Copyright (c) 2022 - 2023 Vaadin Ltd.
4
+ * This program is available under Apache License Version 2.0, available at https://vaadin.com/license/
5
+ */
6
+ import { css } from '@vaadin/vaadin-themable-mixin/vaadin-themable-mixin.js';
7
+
8
+ export const tooltipOverlayStyles = css`
9
+ :host {
10
+ z-index: 1100;
11
+ }
12
+
13
+ [part='overlay'] {
14
+ max-width: 40ch;
15
+ }
16
+
17
+ :host([position^='top'][top-aligned]) [part='overlay'],
18
+ :host([position^='bottom'][top-aligned]) [part='overlay'] {
19
+ margin-top: var(--vaadin-tooltip-offset-top, 0);
20
+ }
21
+
22
+ :host([position^='top'][bottom-aligned]) [part='overlay'],
23
+ :host([position^='bottom'][bottom-aligned]) [part='overlay'] {
24
+ margin-bottom: var(--vaadin-tooltip-offset-bottom, 0);
25
+ }
26
+
27
+ :host([position^='start'][start-aligned]) [part='overlay'],
28
+ :host([position^='end'][start-aligned]) [part='overlay'] {
29
+ margin-inline-start: var(--vaadin-tooltip-offset-start, 0);
30
+ }
31
+
32
+ :host([position^='start'][end-aligned]) [part='overlay'],
33
+ :host([position^='end'][end-aligned]) [part='overlay'] {
34
+ margin-inline-end: var(--vaadin-tooltip-offset-end, 0);
35
+ }
36
+
37
+ @media (forced-colors: active) {
38
+ [part='overlay'] {
39
+ outline: 1px dashed;
40
+ }
41
+ }
42
+ `;
@@ -6,46 +6,10 @@
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';
11
9
  import { overlayStyles } from '@vaadin/overlay/src/vaadin-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
- `;
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';
49
13
 
50
14
  registerStyles('vaadin-tooltip-overlay', [overlayStyles, tooltipOverlayStyles], {
51
15
  moduleId: 'vaadin-tooltip-overlay-styles',
@@ -57,12 +21,11 @@ registerStyles('vaadin-tooltip-overlay', [overlayStyles, tooltipOverlayStyles],
57
21
  * @customElement
58
22
  * @extends HTMLElement
59
23
  * @mixes DirMixin
60
- * @mixes OverlayMixin
61
- * @mixes PositionMixin
62
24
  * @mixes ThemableMixin
25
+ * @mixes TooltipOverlayMixin
63
26
  * @private
64
27
  */
65
- class TooltipOverlay extends PositionMixin(OverlayMixin(DirMixin(ThemableMixin(PolymerElement)))) {
28
+ class TooltipOverlay extends TooltipOverlayMixin(DirMixin(ThemableMixin(PolymerElement))) {
66
29
  static get is() {
67
30
  return 'vaadin-tooltip-overlay';
68
31
  }
@@ -76,15 +39,6 @@ class TooltipOverlay extends PositionMixin(OverlayMixin(DirMixin(ThemableMixin(P
76
39
  `;
77
40
  }
78
41
 
79
- static get properties() {
80
- return {
81
- position: {
82
- type: String,
83
- reflectToAttribute: true,
84
- },
85
- };
86
- }
87
-
88
42
  /** @protected */
89
43
  ready() {
90
44
  super.ready();
@@ -95,66 +49,6 @@ class TooltipOverlay extends PositionMixin(OverlayMixin(DirMixin(ThemableMixin(P
95
49
  this.owner = this.__dataHost;
96
50
  this.owner._overlayElement = this;
97
51
  }
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
- }
158
52
  }
159
53
 
160
54
  defineCustomElement(TooltipOverlay);
@@ -5,22 +5,10 @@
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';
9
8
  import { ThemePropertyMixin } from '@vaadin/vaadin-themable-mixin/vaadin-theme-property-mixin.js';
9
+ import { TooltipMixin } from './vaadin-tooltip-mixin.js';
10
10
 
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';
11
+ export { TooltipPosition } from './vaadin-tooltip-mixin.js';
24
12
 
25
13
  /**
26
14
  * `<vaadin-tooltip>` is a Web Component for creating tooltips.
@@ -60,117 +48,7 @@ export type TooltipPosition =
60
48
  *
61
49
  * See [Styling Components](https://vaadin.com/docs/latest/styling/styling-components) documentation.
62
50
  */
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
- }
51
+ declare class Tooltip extends TooltipMixin(ThemePropertyMixin(ControllerMixin(ElementMixin(HTMLElement)))) {}
174
52
 
175
53
  declare global {
176
54
  interface HTMLElementTagNameMap {