@aquera/nile-elements 0.1.35-beta-1.0 → 0.1.35
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/README.md +10 -21
- package/demo/index.css +4 -7
- package/demo/index.html +36 -20
- package/dist/{fixture-d5b55278.cjs.js → fixture-161dee0b.cjs.js} +3 -3
- package/dist/fixture-161dee0b.cjs.js.map +1 -0
- package/dist/{fixture-df8b52d7.esm.js → fixture-372df3b0.esm.js} +1 -1
- package/dist/index.cjs.js +1 -1
- package/dist/index.esm.js +1 -1
- package/dist/internal/animate.cjs.js +1 -1
- package/dist/internal/animate.cjs.js.map +1 -1
- package/dist/internal/animate.esm.js +1 -1
- package/dist/nile-accordion/nile-accordian.test.cjs.js +1 -1
- package/dist/nile-accordion/nile-accordian.test.esm.js +1 -1
- package/dist/nile-auto-complete/nile-auto-complete.test.cjs.js +1 -1
- package/dist/nile-auto-complete/nile-auto-complete.test.esm.js +1 -1
- package/dist/nile-avatar/nile-avatar.test.cjs.js +1 -1
- package/dist/nile-avatar/nile-avatar.test.esm.js +1 -1
- package/dist/nile-badge/nile-badge.test.cjs.js +1 -1
- package/dist/nile-badge/nile-badge.test.esm.js +1 -1
- package/dist/nile-button/nile-button.test.cjs.js +1 -1
- package/dist/nile-button/nile-button.test.esm.js +1 -1
- package/dist/nile-button-toggle-group/nile-button-toggle-group.test.cjs.js +1 -1
- package/dist/nile-button-toggle-group/nile-button-toggle-group.test.esm.js +1 -1
- package/dist/nile-calendar/nile-calendar.test.cjs.js +1 -1
- package/dist/nile-calendar/nile-calendar.test.esm.js +1 -1
- package/dist/nile-card/nile-card.test.cjs.js +1 -1
- package/dist/nile-card/nile-card.test.esm.js +1 -1
- package/dist/nile-checkbox/nile-checkbox.test.cjs.js +1 -1
- package/dist/nile-checkbox/nile-checkbox.test.esm.js +1 -1
- package/dist/nile-chip/nile-chip.test.cjs.js +1 -1
- package/dist/nile-chip/nile-chip.test.esm.js +1 -1
- package/dist/nile-dialog/nile-dialog.test.cjs.js +1 -1
- package/dist/nile-dialog/nile-dialog.test.esm.js +1 -1
- package/dist/nile-drawer/nile-drawer.test.cjs.js +1 -1
- package/dist/nile-drawer/nile-drawer.test.esm.js +1 -1
- package/dist/nile-dropdown/nile-dropdown.test.cjs.js +1 -1
- package/dist/nile-dropdown/nile-dropdown.test.esm.js +1 -1
- package/dist/nile-empty-state/nile-empty-state.test.cjs.js +1 -1
- package/dist/nile-empty-state/nile-empty-state.test.esm.js +1 -1
- package/dist/nile-error-message/nile-error-message.cjs.js +1 -1
- package/dist/nile-error-message/nile-error-message.cjs.js.map +1 -1
- package/dist/nile-error-message/nile-error-message.css.cjs.js +1 -1
- package/dist/nile-error-message/nile-error-message.css.cjs.js.map +1 -1
- package/dist/nile-error-message/nile-error-message.css.esm.js +4 -6
- package/dist/nile-error-message/nile-error-message.esm.js +4 -4
- package/dist/nile-error-message/nile-error-message.test.cjs.js +1 -1
- package/dist/nile-error-message/nile-error-message.test.esm.js +1 -1
- package/dist/nile-error-notification/nile-error-notification.css.cjs.js +1 -1
- package/dist/nile-error-notification/nile-error-notification.css.cjs.js.map +1 -1
- package/dist/nile-error-notification/nile-error-notification.css.esm.js +1 -1
- package/dist/nile-form-group/nile-form-group.test.cjs.js +1 -1
- package/dist/nile-form-group/nile-form-group.test.esm.js +1 -1
- package/dist/nile-form-help-text/nile-form-help-text.test.cjs.js +1 -1
- package/dist/nile-form-help-text/nile-form-help-text.test.esm.js +1 -1
- package/dist/nile-hero/nile-hero.test.cjs.js +1 -1
- package/dist/nile-hero/nile-hero.test.esm.js +1 -1
- package/dist/nile-icon/nile-icon.test.cjs.js +1 -1
- package/dist/nile-icon/nile-icon.test.esm.js +1 -1
- package/dist/nile-input/nile-input.test.cjs.js +1 -1
- package/dist/nile-input/nile-input.test.esm.js +1 -1
- package/dist/nile-link/nile-link.test.cjs.js +1 -1
- package/dist/nile-link/nile-link.test.esm.js +1 -1
- package/dist/nile-loader/nile-loader.test.cjs.js +1 -1
- package/dist/nile-loader/nile-loader.test.esm.js +1 -1
- package/dist/nile-popover/nile-popover.test.cjs.js +1 -1
- package/dist/nile-popover/nile-popover.test.esm.js +1 -1
- package/dist/nile-popup/nile-popup.test.cjs.js +1 -1
- package/dist/nile-popup/nile-popup.test.esm.js +1 -1
- package/dist/nile-progress-bar/nile-progress-bar.css.cjs.js +1 -1
- package/dist/nile-progress-bar/nile-progress-bar.css.cjs.js.map +1 -1
- package/dist/nile-progress-bar/nile-progress-bar.css.esm.js +0 -1
- package/dist/nile-progress-bar/nile-progress-bar.test.cjs.js +1 -1
- package/dist/nile-progress-bar/nile-progress-bar.test.esm.js +1 -1
- package/dist/nile-radio/nile-radio.test.cjs.js +1 -1
- package/dist/nile-radio/nile-radio.test.esm.js +1 -1
- package/dist/nile-radio-group/nile-radio-group.test.cjs.js +1 -1
- package/dist/nile-radio-group/nile-radio-group.test.esm.js +1 -1
- package/dist/nile-select/nile-select.test.cjs.js +1 -1
- package/dist/nile-select/nile-select.test.esm.js +1 -1
- package/dist/nile-slide-toggle/nile-slide-toggle.test.cjs.js +1 -1
- package/dist/nile-slide-toggle/nile-slide-toggle.test.esm.js +1 -1
- package/dist/nile-tab-group/nile-tab-group.test.cjs.js +1 -1
- package/dist/nile-tab-group/nile-tab-group.test.esm.js +1 -1
- package/dist/nile-table/nile-table.cjs.js.map +1 -1
- package/dist/nile-textarea/nile-textarea.test.cjs.js +1 -1
- package/dist/nile-textarea/nile-textarea.test.esm.js +1 -1
- package/dist/nile-tooltip/index.cjs.js +1 -1
- package/dist/nile-tooltip/index.esm.js +1 -1
- package/dist/nile-tooltip/nile-tooltip.cjs.js +1 -1
- package/dist/nile-tooltip/nile-tooltip.cjs.js.map +1 -1
- package/dist/nile-tooltip/nile-tooltip.css.cjs.js +1 -1
- package/dist/nile-tooltip/nile-tooltip.css.cjs.js.map +1 -1
- package/dist/nile-tooltip/nile-tooltip.css.esm.js +45 -78
- package/dist/nile-tooltip/nile-tooltip.esm.js +28 -23
- package/dist/src/nile-error-message/nile-error-message.css.js +4 -6
- package/dist/src/nile-error-message/nile-error-message.css.js.map +1 -1
- package/dist/src/nile-error-message/nile-error-message.d.ts +0 -4
- package/dist/src/nile-error-message/nile-error-message.js +0 -20
- package/dist/src/nile-error-message/nile-error-message.js.map +1 -1
- package/dist/src/nile-error-notification/nile-error-notification.css.js +1 -1
- package/dist/src/nile-error-notification/nile-error-notification.css.js.map +1 -1
- package/dist/src/nile-progress-bar/nile-progress-bar.css.js +0 -1
- package/dist/src/nile-progress-bar/nile-progress-bar.css.js.map +1 -1
- package/dist/src/nile-table/nile-table.js.map +1 -1
- package/dist/src/nile-tooltip/nile-tooltip.css.js +43 -76
- package/dist/src/nile-tooltip/nile-tooltip.css.js.map +1 -1
- package/dist/src/nile-tooltip/nile-tooltip.d.ts +46 -24
- package/dist/src/nile-tooltip/nile-tooltip.js +232 -235
- package/dist/src/nile-tooltip/nile-tooltip.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +1 -1
- package/src/nile-error-message/nile-error-message.css.ts +4 -6
- package/src/nile-error-message/nile-error-message.ts +0 -18
- package/src/nile-error-notification/nile-error-notification.css.ts +1 -1
- package/src/nile-progress-bar/nile-progress-bar.css.ts +0 -1
- package/src/nile-table/nile-table.ts +2 -2
- package/src/nile-tooltip/nile-tooltip.css.ts +44 -77
- package/src/nile-tooltip/nile-tooltip.ts +230 -268
- package/vscode-html-custom-data.json +92 -92
- package/dist/fixture-d5b55278.cjs.js.map +0 -1
- package/dist/nile-tooltip/nile-tooltip-utils.cjs.js +0 -2
- package/dist/nile-tooltip/nile-tooltip-utils.cjs.js.map +0 -1
- package/dist/nile-tooltip/nile-tooltip-utils.esm.js +0 -1
- package/dist/nile-tooltip/nile-tooltip.test.cjs.js +0 -2
- package/dist/nile-tooltip/nile-tooltip.test.cjs.js.map +0 -1
- package/dist/nile-tooltip/nile-tooltip.test.esm.js +0 -47
- package/dist/src/nile-tooltip/nile-tooltip-utils.d.ts +0 -18
- package/dist/src/nile-tooltip/nile-tooltip-utils.js +0 -216
- package/dist/src/nile-tooltip/nile-tooltip-utils.js.map +0 -1
- package/dist/src/nile-tooltip/nile-tooltip.test.d.ts +0 -1
- package/dist/src/nile-tooltip/nile-tooltip.test.js +0 -148
- package/dist/src/nile-tooltip/nile-tooltip.test.js.map +0 -1
- package/src/nile-tooltip/nile-tooltip-utils.ts +0 -271
- package/src/nile-tooltip/nile-tooltip.test.ts +0 -168
@@ -1,28 +1,61 @@
|
|
1
|
-
|
2
1
|
/**
|
3
2
|
* Copyright Aquera Inc 2023
|
4
3
|
*
|
5
4
|
* This source code is licensed under the BSD-3-Clause license found in the
|
6
5
|
* LICENSE file in the root directory of this source tree.
|
7
6
|
*/
|
8
|
-
|
9
|
-
import {
|
10
|
-
import { classMap } from 'lit/directives/class-map.js';
|
7
|
+
|
8
|
+
import { LitElement, CSSResultArray, TemplateResult } from 'lit';
|
11
9
|
import { styles } from './nile-tooltip.css';
|
10
|
+
import '../nile-popup/nile-popup';
|
11
|
+
import { animateTo, parseDuration, stopAnimations } from '../internal/animate';
|
12
|
+
import { classMap } from 'lit/directives/class-map.js';
|
13
|
+
import { customElement, property, query } from 'lit/decorators.js';
|
14
|
+
import {
|
15
|
+
getAnimation,
|
16
|
+
setDefaultAnimation,
|
17
|
+
} from '../utilities/animation-registry';
|
18
|
+
import { html } from 'lit';
|
19
|
+
// import { LocalizeController } from '../utilities/localize';
|
20
|
+
import { waitForEvent } from '../internal/event';
|
21
|
+
import { watch } from '../internal/watch';
|
12
22
|
import NileElement from '../internal/nile-element';
|
13
|
-
import {
|
14
|
-
|
23
|
+
import type { CSSResultGroup } from 'lit';
|
24
|
+
import type NilePopup from '../nile-popup/nile-popup';
|
15
25
|
/**
|
16
|
-
* Nile
|
26
|
+
* Nile icon component.
|
17
27
|
*
|
18
28
|
* @tag nile-tooltip
|
19
29
|
*
|
20
30
|
*/
|
21
31
|
@customElement('nile-tooltip')
|
22
32
|
export class NileTooltip extends NileElement {
|
23
|
-
|
24
|
-
|
25
|
-
|
33
|
+
/**
|
34
|
+
* The styles for Tooltip
|
35
|
+
* @remarks If you are extending this class you can extend the base styles with super. Eg `return [super(), myCustomStyles]`
|
36
|
+
*/
|
37
|
+
public static get styles(): CSSResultArray {
|
38
|
+
return [styles];
|
39
|
+
}
|
40
|
+
|
41
|
+
private hoverTimeout: number;
|
42
|
+
// private readonly localize = new LocalizeController(this);
|
43
|
+
|
44
|
+
@query('slot:not([name])') defaultSlot: HTMLSlotElement;
|
45
|
+
@query('.tooltip__body') body: HTMLElement;
|
46
|
+
@query('nile-popup') popup: NilePopup;
|
47
|
+
|
48
|
+
/** The tooltip's content. If you need to display HTML, use the `content` slot instead. */
|
49
|
+
@property({ type: String, reflect: true }) content = '';
|
50
|
+
|
51
|
+
/** Size Property to decide the tool tip size */
|
52
|
+
@property({ reflect: true }) size: 'small' | 'large' = 'small';
|
53
|
+
|
54
|
+
/**
|
55
|
+
* The preferred placement of the tooltip. Note that the actual placement may vary as needed to keep the tooltip
|
56
|
+
* inside of the viewport.
|
57
|
+
*/
|
58
|
+
@property() placement:
|
26
59
|
| 'top'
|
27
60
|
| 'top-start'
|
28
61
|
| 'top-end'
|
@@ -35,326 +68,255 @@ export class NileTooltip extends NileElement {
|
|
35
68
|
| 'left'
|
36
69
|
| 'left-start'
|
37
70
|
| 'left-end' = 'top';
|
71
|
+
|
72
|
+
/** Disables the tooltip so it won't show when triggered. */
|
38
73
|
@property({ type: Boolean, reflect: true }) disabled = false;
|
74
|
+
|
75
|
+
/** The distance in pixels from which to offset the tooltip away from its target. */
|
76
|
+
@property({ type: Number }) distance = 8;
|
77
|
+
|
78
|
+
/** Indicates whether or not the tooltip is open. You can use this in lieu of the show/hide methods. */
|
39
79
|
@property({ type: Boolean, reflect: true }) open = false;
|
80
|
+
|
81
|
+
/** The distance in pixels from which to offset the tooltip along its target. */
|
82
|
+
@property({ type: Number }) skidding = 0;
|
83
|
+
|
40
84
|
/**
|
41
85
|
* Controls how the tooltip is activated. Possible options include `click`, `hover`, `focus`, and `manual`. Multiple
|
42
86
|
* options can be passed by separating them with a space. When manual is used, the tooltip must be activated
|
43
87
|
* programmatically.
|
44
88
|
*/
|
45
89
|
@property() trigger = 'hover focus';
|
46
|
-
@property({ type: Number }) distance = 8;
|
47
|
-
private readonly SHIFT_OFFSET = 16;
|
48
|
-
/** The distance in pixels from which to offset the tooltip along its target. */
|
49
|
-
@property({ type: Number }) skidding = 0;
|
50
|
-
@property({ type: Boolean, reflect: true }) hoist = false;
|
51
|
-
|
52
|
-
@query('.tooltip') tooltip!: HTMLElement;
|
53
|
-
@query('.trigger-container') triggerContainer!: HTMLElement;
|
54
|
-
@query('.tooltip-caret') caret!: HTMLElement;
|
55
|
-
@query('slot[name="content"]') tooltipSlot!: HTMLSlotElement;
|
56
90
|
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
return [styles];
|
64
|
-
}
|
91
|
+
/**
|
92
|
+
* Enable this option to prevent the tooltip from being clipped when the component is placed inside a container with
|
93
|
+
* `overflow: auto|hidden|scroll`. Hoisting uses a fixed positioning strategy that works in many, but not all,
|
94
|
+
* scenarios.
|
95
|
+
*/
|
96
|
+
@property({ type: Boolean }) hoist = false;
|
65
97
|
|
66
98
|
connectedCallback() {
|
67
99
|
super.connectedCallback();
|
68
|
-
this.
|
69
|
-
|
70
|
-
|
100
|
+
this.handleBlur = this.handleBlur.bind(this);
|
101
|
+
this.handleClick = this.handleClick.bind(this);
|
102
|
+
this.handleFocus = this.handleFocus.bind(this);
|
103
|
+
this.handleKeyDown = this.handleKeyDown.bind(this);
|
104
|
+
this.handleMouseOver = this.handleMouseOver.bind(this);
|
105
|
+
this.handleMouseOut = this.handleMouseOut.bind(this);
|
106
|
+
|
107
|
+
this.updateComplete.then(() => {
|
108
|
+
this.addEventListener('blur', this.handleBlur, true);
|
109
|
+
this.addEventListener('focus', this.handleFocus, true);
|
110
|
+
this.addEventListener('click', this.handleClick);
|
111
|
+
this.addEventListener('keydown', this.handleKeyDown);
|
112
|
+
this.addEventListener('mouseover', this.handleMouseOver);
|
113
|
+
this.addEventListener('mouseout', this.handleMouseOut);
|
114
|
+
});
|
71
115
|
}
|
72
116
|
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
const validPlacements = [
|
77
|
-
'top', 'top-start', 'top-end',
|
78
|
-
'right', 'right-start', 'right-end',
|
79
|
-
'bottom', 'bottom-start', 'bottom-end',
|
80
|
-
'left', 'left-start', 'left-end'
|
81
|
-
];
|
82
|
-
|
83
|
-
if (!validPlacements.includes(this.placement)) {
|
84
|
-
console.warn(`[nile-tooltip] Invalid placement "${this.placement}", defaulting to "bottom".`);
|
85
|
-
this.placement = 'top';
|
86
|
-
}
|
117
|
+
firstUpdated() {
|
118
|
+
this.body.hidden = !this.open;
|
87
119
|
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
if (changedProps.has('open') && this.open) {
|
93
|
-
this.updateComplete.then(() => {
|
94
|
-
requestAnimationFrame(() => {
|
95
|
-
this.updateTooltipPosition();
|
96
|
-
});
|
97
|
-
});
|
120
|
+
// If the tooltip is visible on init, update its position
|
121
|
+
if (this.open) {
|
122
|
+
this.popup.active = true;
|
123
|
+
this.popup.reposition();
|
98
124
|
}
|
99
125
|
}
|
100
126
|
|
101
127
|
disconnectedCallback() {
|
102
128
|
super.disconnectedCallback();
|
103
|
-
|
104
|
-
|
129
|
+
this.removeEventListener('blur', this.handleBlur, true);
|
130
|
+
this.removeEventListener('focus', this.handleFocus, true);
|
131
|
+
this.removeEventListener('click', this.handleClick);
|
132
|
+
this.removeEventListener('keydown', this.handleKeyDown);
|
133
|
+
this.removeEventListener('mouseover', this.handleMouseOver);
|
134
|
+
this.removeEventListener('mouseout', this.handleMouseOut);
|
105
135
|
}
|
106
136
|
|
107
|
-
private
|
108
|
-
|
109
|
-
|
110
|
-
|
137
|
+
private handleBlur() {
|
138
|
+
if (this.hasTrigger('focus')) {
|
139
|
+
this.hide();
|
140
|
+
}
|
111
141
|
}
|
112
142
|
|
113
|
-
private
|
114
|
-
if (
|
115
|
-
this.open
|
116
|
-
|
143
|
+
private handleClick() {
|
144
|
+
if (this.hasTrigger('click')) {
|
145
|
+
if (this.open) {
|
146
|
+
this.hide();
|
147
|
+
} else {
|
148
|
+
this.show();
|
149
|
+
}
|
117
150
|
}
|
151
|
+
}
|
118
152
|
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
const viewportHeight = window.innerHeight;
|
123
|
-
|
124
|
-
|
125
|
-
let { top, left, placement } = getValidTooltipPosition(
|
126
|
-
triggerRect,
|
127
|
-
tooltipRect,
|
128
|
-
this.originalPlacement,
|
129
|
-
this.distance,
|
130
|
-
this.skidding,
|
131
|
-
this.caretSize,
|
132
|
-
viewportWidth,
|
133
|
-
viewportHeight
|
134
|
-
);
|
135
|
-
|
136
|
-
// FallBack Positions
|
137
|
-
|
138
|
-
// Bottom
|
139
|
-
if (this.originalPlacement.startsWith('bottom')) {
|
140
|
-
const availableSpaceBelow = viewportHeight - triggerRect.bottom;
|
141
|
-
if (availableSpaceBelow < tooltipRect.height + this.distance) {
|
142
|
-
let newPlacement: typeof this.originalPlacement = 'top';
|
143
|
-
if (this.originalPlacement === 'bottom-start') {
|
144
|
-
newPlacement = 'top';
|
145
|
-
} else if (this.originalPlacement === 'bottom-end') {
|
146
|
-
newPlacement = 'top';
|
147
|
-
}
|
148
|
-
|
149
|
-
const newPosition = getValidTooltipPosition(
|
150
|
-
triggerRect,
|
151
|
-
tooltipRect,
|
152
|
-
newPlacement,
|
153
|
-
this.distance,
|
154
|
-
this.skidding,
|
155
|
-
this.caretSize,
|
156
|
-
viewportWidth,
|
157
|
-
viewportHeight
|
158
|
-
);
|
159
|
-
top = newPosition.top;
|
160
|
-
left = newPosition.left;
|
161
|
-
placement = newPosition.placement;
|
162
|
-
}
|
153
|
+
private handleFocus() {
|
154
|
+
if (this.hasTrigger('focus')) {
|
155
|
+
this.show();
|
163
156
|
}
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
if (
|
169
|
-
|
170
|
-
|
171
|
-
newPlacement = 'bottom-start';
|
172
|
-
} else if (this.originalPlacement === 'top-end') {
|
173
|
-
newPlacement = 'bottom-end';
|
174
|
-
}
|
175
|
-
|
176
|
-
const newPosition = getValidTooltipPosition(
|
177
|
-
triggerRect,
|
178
|
-
tooltipRect,
|
179
|
-
newPlacement,
|
180
|
-
this.distance,
|
181
|
-
this.skidding,
|
182
|
-
this.caretSize,
|
183
|
-
viewportWidth,
|
184
|
-
viewportHeight
|
185
|
-
);
|
186
|
-
top = newPosition.top;
|
187
|
-
left = newPosition.left;
|
188
|
-
placement = newPosition.placement;
|
157
|
+
}
|
158
|
+
|
159
|
+
private handleKeyDown(event: KeyboardEvent) {
|
160
|
+
// Pressing escape when the target element has focus should dismiss the tooltip
|
161
|
+
if (this.open && event.key === 'Escape') {
|
162
|
+
event.stopPropagation();
|
163
|
+
this.hide();
|
189
164
|
}
|
190
165
|
}
|
191
166
|
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
if (availableSpaceLeft < tooltipRect.width + this.distance && availableSpaceRight >= tooltipRect.width + this.distance) {
|
197
|
-
let newPlacement: typeof this.originalPlacement = 'right';
|
198
|
-
if (this.originalPlacement === 'left-start') {
|
199
|
-
newPlacement = 'right-start';
|
200
|
-
} else if (this.originalPlacement === 'left-end') {
|
201
|
-
newPlacement = 'right-end';
|
202
|
-
}
|
203
|
-
|
204
|
-
const newPosition = getValidTooltipPosition(
|
205
|
-
triggerRect,
|
206
|
-
tooltipRect,
|
207
|
-
newPlacement,
|
208
|
-
this.distance,
|
209
|
-
this.skidding,
|
210
|
-
this.caretSize,
|
211
|
-
viewportWidth,
|
212
|
-
viewportHeight
|
167
|
+
private handleMouseOver() {
|
168
|
+
if (this.hasTrigger('hover')) {
|
169
|
+
const delay = parseDuration(
|
170
|
+
getComputedStyle(this).getPropertyValue('--show-delay')
|
213
171
|
);
|
214
|
-
|
215
|
-
|
216
|
-
placement = newPosition.placement;
|
172
|
+
clearTimeout(this.hoverTimeout);
|
173
|
+
this.hoverTimeout = window.setTimeout(() => this.show(), delay);
|
217
174
|
}
|
218
175
|
}
|
219
176
|
|
220
|
-
|
221
|
-
|
222
|
-
|
223
|
-
|
224
|
-
if (availableSpaceRight < tooltipRect.width + this.distance && availableSpaceLeft >= tooltipRect.width + this.distance) {
|
225
|
-
let newPlacement: typeof this.originalPlacement = 'left';
|
226
|
-
if (this.originalPlacement === 'right-start') {
|
227
|
-
newPlacement = 'left-start';
|
228
|
-
} else if (this.originalPlacement === 'right-end') {
|
229
|
-
newPlacement = 'left-end';
|
230
|
-
}
|
231
|
-
|
232
|
-
const newPosition = getValidTooltipPosition(
|
233
|
-
triggerRect,
|
234
|
-
tooltipRect,
|
235
|
-
newPlacement,
|
236
|
-
this.distance,
|
237
|
-
this.skidding,
|
238
|
-
this.caretSize,
|
239
|
-
viewportWidth,
|
240
|
-
viewportHeight
|
177
|
+
private handleMouseOut() {
|
178
|
+
if (this.hasTrigger('hover')) {
|
179
|
+
const delay = parseDuration(
|
180
|
+
getComputedStyle(this).getPropertyValue('--hide-delay')
|
241
181
|
);
|
242
|
-
|
243
|
-
|
244
|
-
placement = newPosition.placement;
|
182
|
+
clearTimeout(this.hoverTimeout);
|
183
|
+
this.hoverTimeout = window.setTimeout(() => this.hide(), delay);
|
245
184
|
}
|
246
185
|
}
|
247
186
|
|
248
|
-
|
249
|
-
this.
|
250
|
-
|
251
|
-
|
252
|
-
const { caretLeft, caretTop } = getCaretPosition({
|
253
|
-
placement,
|
254
|
-
tooltipRect,
|
255
|
-
triggerRect,
|
256
|
-
caretSize: this.caretSize,
|
257
|
-
left,
|
258
|
-
top
|
259
|
-
});
|
187
|
+
private hasTrigger(triggerType: string) {
|
188
|
+
const triggers = this.trigger.split(' ');
|
189
|
+
return triggers.includes(triggerType);
|
190
|
+
}
|
260
191
|
|
261
|
-
|
262
|
-
|
263
|
-
|
192
|
+
@watch('open', { waitUntilFirstUpdate: true })
|
193
|
+
async handleOpenChange() {
|
194
|
+
if (this.open) {
|
195
|
+
if (this.disabled) {
|
196
|
+
return;
|
197
|
+
}
|
264
198
|
|
265
|
-
|
266
|
-
const trimmedContent = this.content.trim();
|
267
|
-
if (!trimmedContent && !this.hasTooltipSlot) {
|
268
|
-
return;
|
269
|
-
}
|
270
|
-
if (!this.disabled && isInViewport(this.triggerContainer)) {
|
199
|
+
// Show
|
271
200
|
this.emit('nile-show');
|
272
|
-
|
273
|
-
this.
|
274
|
-
|
275
|
-
|
276
|
-
|
277
|
-
|
201
|
+
|
202
|
+
await stopAnimations(this.body);
|
203
|
+
this.body.hidden = false;
|
204
|
+
this.popup.active = true;
|
205
|
+
const { keyframes, options } = getAnimation(this, 'tooltip.show', {
|
206
|
+
dir: '',
|
278
207
|
});
|
208
|
+
await animateTo(this.popup.popup, keyframes, options);
|
209
|
+
|
210
|
+
this.emit('nile-after-show');
|
279
211
|
} else {
|
280
|
-
|
281
|
-
|
282
|
-
};
|
212
|
+
// Hide
|
213
|
+
this.emit('nile-hide');
|
283
214
|
|
284
|
-
|
285
|
-
|
286
|
-
|
287
|
-
|
288
|
-
this.
|
289
|
-
|
290
|
-
|
215
|
+
await stopAnimations(this.body);
|
216
|
+
const { keyframes, options } = getAnimation(this, 'tooltip.hide', {
|
217
|
+
dir: '',
|
218
|
+
});
|
219
|
+
await animateTo(this.popup.popup, keyframes, options);
|
220
|
+
this.popup.active = false;
|
221
|
+
this.body.hidden = true;
|
291
222
|
|
292
|
-
|
293
|
-
if (this.trigger.includes('hover')) {
|
294
|
-
clearTimeout(this.hoverTimeout);
|
295
|
-
this.hoverTimeout = window.setTimeout(() => this.showTooltip(), 300);
|
223
|
+
this.emit('nile-after-hide');
|
296
224
|
}
|
297
|
-
}
|
225
|
+
}
|
298
226
|
|
299
|
-
|
300
|
-
|
301
|
-
|
302
|
-
|
227
|
+
@watch(['content', 'distance', 'hoist', 'placement', 'skidding'])
|
228
|
+
async handleOptionsChange() {
|
229
|
+
if (this.hasUpdated) {
|
230
|
+
await this.updateComplete;
|
231
|
+
this.popup.reposition();
|
303
232
|
}
|
304
|
-
}
|
233
|
+
}
|
305
234
|
|
306
|
-
|
307
|
-
|
308
|
-
|
309
|
-
|
310
|
-
} else {
|
311
|
-
this.hideTooltip();
|
312
|
-
}
|
235
|
+
@watch('disabled')
|
236
|
+
handleDisabledChange() {
|
237
|
+
if (this.disabled && this.open) {
|
238
|
+
this.hide();
|
313
239
|
}
|
314
|
-
}
|
240
|
+
}
|
315
241
|
|
316
|
-
|
317
|
-
|
318
|
-
|
242
|
+
/** Shows the tooltip. */
|
243
|
+
async show() {
|
244
|
+
if (this.open || !this.content?.trim().length) {
|
245
|
+
return undefined;
|
319
246
|
}
|
320
|
-
};
|
321
|
-
|
322
247
|
|
323
|
-
|
324
|
-
|
325
|
-
|
248
|
+
this.open = true;
|
249
|
+
return waitForEvent(this, 'nile-after-show');
|
250
|
+
}
|
251
|
+
|
252
|
+
/** Hides the tooltip */
|
253
|
+
async hide() {
|
254
|
+
if (!this.open) {
|
255
|
+
return undefined;
|
326
256
|
}
|
327
|
-
|
257
|
+
|
258
|
+
this.open = false;
|
259
|
+
return waitForEvent(this, 'nile-after-hide');
|
260
|
+
}
|
328
261
|
|
329
262
|
render() {
|
330
263
|
return html`
|
331
|
-
<
|
332
|
-
|
333
|
-
|
264
|
+
<nile-popup
|
265
|
+
part="base"
|
266
|
+
exportparts="
|
267
|
+
popup:base__popup,
|
268
|
+
arrow:base__arrow
|
269
|
+
"
|
270
|
+
class=${classMap({
|
271
|
+
tooltip: true,
|
272
|
+
'tooltip--open': this.open,
|
273
|
+
})}
|
274
|
+
placement=${this.placement}
|
275
|
+
distance=${this.distance}
|
276
|
+
skidding=${this.skidding}
|
277
|
+
strategy=${this.hoist ? 'fixed' : 'absolute'}
|
278
|
+
flip
|
279
|
+
shift
|
280
|
+
arrow
|
334
281
|
>
|
335
|
-
<
|
336
|
-
|
337
|
-
|
338
|
-
|
339
|
-
|
340
|
-
|
341
|
-
|
342
|
-
|
343
|
-
|
344
|
-
|
345
|
-
|
346
|
-
|
347
|
-
|
348
|
-
|
349
|
-
|
350
|
-
|
351
|
-
>
|
352
|
-
<slot></slot>
|
353
|
-
</div>
|
282
|
+
<slot slot="anchor" aria-describedby="tooltip"></slot>
|
283
|
+
|
284
|
+
<slot
|
285
|
+
name="content"
|
286
|
+
part="body"
|
287
|
+
id="tooltip"
|
288
|
+
class=${classMap({
|
289
|
+
tooltip__body: true,
|
290
|
+
'tooltip__body--large': this.size === 'large',
|
291
|
+
})}
|
292
|
+
role="tooltip"
|
293
|
+
aria-live=${this.open ? 'polite' : 'off'}
|
294
|
+
>
|
295
|
+
${this.content}
|
296
|
+
</slot>
|
297
|
+
</nile-popup>
|
354
298
|
`;
|
355
299
|
}
|
356
300
|
}
|
357
301
|
|
302
|
+
setDefaultAnimation('tooltip.show', {
|
303
|
+
keyframes: [
|
304
|
+
{ opacity: 0, scale: 0.8 },
|
305
|
+
{ opacity: 1, scale: 1 },
|
306
|
+
],
|
307
|
+
options: { duration: 150, easing: 'ease' },
|
308
|
+
});
|
309
|
+
|
310
|
+
setDefaultAnimation('tooltip.hide', {
|
311
|
+
keyframes: [
|
312
|
+
{ opacity: 1, scale: 1 },
|
313
|
+
{ opacity: 0, scale: 0.8 },
|
314
|
+
],
|
315
|
+
options: { duration: 150, easing: 'ease' },
|
316
|
+
});
|
317
|
+
|
318
|
+
export default NileTooltip;
|
319
|
+
|
358
320
|
declare global {
|
359
321
|
interface HTMLElementTagNameMap {
|
360
322
|
'nile-tooltip': NileTooltip;
|