@vaadin/tooltip 24.2.0-dev.f254716fe → 24.3.0-alpha2

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