@aquera/nile-elements 0.1.32-beta-1.1 → 0.1.32-beta-1.3
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 +7 -21
- package/demo/index.html +9 -5
- package/dist/axe.min-2b379f29.cjs.js +12 -0
- package/dist/axe.min-2b379f29.cjs.js.map +1 -0
- package/dist/axe.min-c2cd8733.esm.js +12 -0
- package/dist/{fixture-3acb409b.cjs.js → fixture-161dee0b.cjs.js} +2 -2
- package/dist/{fixture-3acb409b.cjs.js.map → fixture-161dee0b.cjs.js.map} +1 -1
- package/dist/{fixture-db35a8ae.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-accordion/nile-accordion.cjs.js +1 -1
- package/dist/nile-accordion/nile-accordion.cjs.js.map +1 -1
- package/dist/nile-accordion/nile-accordion.css.cjs.js +1 -1
- package/dist/nile-accordion/nile-accordion.css.cjs.js.map +1 -1
- package/dist/nile-accordion/nile-accordion.css.esm.js +1 -1
- package/dist/nile-accordion/nile-accordion.esm.js +4 -4
- 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-circular-progressbar/nile-circular-progressbar.css.cjs.js +1 -1
- package/dist/nile-circular-progressbar/nile-circular-progressbar.css.cjs.js.map +1 -1
- package/dist/nile-circular-progressbar/nile-circular-progressbar.css.esm.js +49 -49
- package/dist/nile-code-editor/extensionSetup.cjs.js +7 -7
- package/dist/nile-code-editor/extensionSetup.cjs.js.map +1 -1
- package/dist/nile-code-editor/extensionSetup.esm.js +1 -1
- package/dist/nile-code-editor/nile-code-editor.cjs.js +2 -2
- package/dist/nile-code-editor/nile-code-editor.cjs.js.map +1 -1
- package/dist/nile-code-editor/nile-code-editor.esm.js +2 -2
- 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.test.cjs.js +1 -1
- package/dist/nile-error-message/nile-error-message.test.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.css.cjs.js +1 -1
- package/dist/nile-input/nile-input.css.cjs.js.map +1 -1
- package/dist/nile-input/nile-input.css.esm.js +8 -0
- 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.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-body/nile-table-body.cjs.js +1 -1
- package/dist/nile-table-body/nile-table-body.cjs.js.map +1 -1
- package/dist/nile-table-body/nile-table-body.esm.js +2 -2
- package/dist/nile-table-cell-item/nile-table-cell-item.css.cjs.js +1 -1
- package/dist/nile-table-cell-item/nile-table-cell-item.css.cjs.js.map +1 -1
- package/dist/nile-table-cell-item/nile-table-cell-item.css.esm.js +2 -4
- package/dist/nile-table-header-item/nile-table-header-item.css.cjs.js +1 -1
- package/dist/nile-table-header-item/nile-table-header-item.css.cjs.js.map +1 -1
- package/dist/nile-table-header-item/nile-table-header-item.css.esm.js +0 -2
- package/dist/nile-table-row/nile-table-row.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 +56 -115
- package/dist/nile-tooltip/nile-tooltip.esm.js +30 -13
- package/dist/src/index.d.ts +0 -1
- package/dist/src/index.js +0 -1
- package/dist/src/index.js.map +1 -1
- package/dist/src/nile-accordion/nile-accordion.css.js +1 -1
- package/dist/src/nile-accordion/nile-accordion.css.js.map +1 -1
- package/dist/src/nile-accordion/nile-accordion.d.ts +5 -6
- package/dist/src/nile-accordion/nile-accordion.js +8 -21
- package/dist/src/nile-accordion/nile-accordion.js.map +1 -1
- package/dist/src/nile-circular-progressbar/nile-circular-progressbar.css.js +49 -49
- package/dist/src/nile-circular-progressbar/nile-circular-progressbar.css.js.map +1 -1
- package/dist/src/nile-input/nile-input.css.js +8 -0
- package/dist/src/nile-input/nile-input.css.js.map +1 -1
- package/dist/src/nile-table-body/nile-table-body.d.ts +1 -3
- package/dist/src/nile-table-body/nile-table-body.js +1 -9
- package/dist/src/nile-table-body/nile-table-body.js.map +1 -1
- package/dist/src/nile-table-cell-item/nile-table-cell-item.css.js +2 -4
- package/dist/src/nile-table-cell-item/nile-table-cell-item.css.js.map +1 -1
- package/dist/src/nile-table-header-item/nile-table-header-item.css.js +0 -2
- package/dist/src/nile-table-header-item/nile-table-header-item.css.js.map +1 -1
- package/dist/src/nile-table-row/nile-table-row.js.map +1 -1
- package/dist/src/nile-tooltip/nile-tooltip.css.js +54 -113
- package/dist/src/nile-tooltip/nile-tooltip.css.js.map +1 -1
- package/dist/src/nile-tooltip/nile-tooltip.d.ts +62 -22
- package/dist/src/nile-tooltip/nile-tooltip.js +244 -180
- package/dist/src/nile-tooltip/nile-tooltip.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +3 -3
- package/src/index.ts +1 -2
- package/src/nile-accordion/nile-accordion.css.ts +1 -1
- package/src/nile-accordion/nile-accordion.ts +4 -15
- package/src/nile-circular-progressbar/nile-circular-progressbar.css.ts +56 -55
- package/src/nile-input/nile-input.css.ts +8 -0
- package/src/nile-table-body/nile-table-body.ts +2 -8
- package/src/nile-table-cell-item/nile-table-cell-item.css.ts +2 -4
- package/src/nile-table-header-item/nile-table-header-item.css.ts +0 -2
- package/src/nile-table-row/nile-table-row.ts +2 -1
- package/src/nile-tooltip/nile-tooltip.css.ts +54 -113
- package/src/nile-tooltip/nile-tooltip.ts +269 -207
- package/vscode-html-custom-data.json +18 -36
- package/dist/axe.min-5bf06036.esm.js +0 -12
- package/dist/axe.min-ff35bfba.cjs.js +0 -12
- package/dist/axe.min-ff35bfba.cjs.js.map +0 -1
- package/dist/nile-table/index.cjs.js +0 -2
- package/dist/nile-table/index.cjs.js.map +0 -1
- package/dist/nile-table/index.esm.js +0 -1
- package/dist/nile-table/nile-table.cjs.js +0 -2
- package/dist/nile-table/nile-table.cjs.js.map +0 -1
- package/dist/nile-table/nile-table.css.cjs.js +0 -2
- package/dist/nile-table/nile-table.css.cjs.js.map +0 -1
- package/dist/nile-table/nile-table.css.esm.js +0 -6
- package/dist/nile-table/nile-table.esm.js +0 -3
- package/dist/src/nile-table/index.d.ts +0 -1
- package/dist/src/nile-table/index.js +0 -2
- package/dist/src/nile-table/index.js.map +0 -1
- package/dist/src/nile-table/nile-table.css.d.ts +0 -12
- package/dist/src/nile-table/nile-table.css.js +0 -18
- package/dist/src/nile-table/nile-table.css.js.map +0 -1
- package/dist/src/nile-table/nile-table.d.ts +0 -47
- package/dist/src/nile-table/nile-table.js +0 -137
- package/dist/src/nile-table/nile-table.js.map +0 -1
- package/src/nile-table/index.ts +0 -1
- package/src/nile-table/nile-table.css.ts +0 -20
- package/src/nile-table/nile-table.ts +0 -154
@@ -1,262 +1,324 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
1
|
+
/**
|
2
|
+
* Copyright Aquera Inc 2023
|
3
|
+
*
|
4
|
+
* This source code is licensed under the BSD-3-Clause license found in the
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
6
|
+
*/
|
7
|
+
|
8
|
+
import { LitElement, CSSResultArray, TemplateResult } from 'lit';
|
4
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';
|
5
22
|
import NileElement from '../internal/nile-element';
|
6
|
-
|
7
|
-
type
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
23
|
+
import type { CSSResultGroup } from 'lit';
|
24
|
+
import type NilePopup from '../nile-popup/nile-popup';
|
25
|
+
/**
|
26
|
+
* Nile icon component.
|
27
|
+
*
|
28
|
+
* @tag nile-tooltip
|
29
|
+
*
|
30
|
+
*/
|
14
31
|
@customElement('nile-tooltip')
|
15
32
|
export class NileTooltip extends NileElement {
|
16
|
-
|
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 */
|
17
52
|
@property({ reflect: true }) size: 'small' | 'large' = 'small';
|
18
|
-
|
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:
|
59
|
+
| 'top'
|
60
|
+
| 'top-start'
|
61
|
+
| 'top-end'
|
62
|
+
| 'right'
|
63
|
+
| 'right-start'
|
64
|
+
| 'right-end'
|
65
|
+
| 'bottom'
|
66
|
+
| 'bottom-start'
|
67
|
+
| 'bottom-end'
|
68
|
+
| 'left'
|
69
|
+
| 'left-start'
|
70
|
+
| 'left-end' = 'top';
|
71
|
+
|
72
|
+
/** Disables the tooltip so it won't show when triggered. */
|
19
73
|
@property({ type: Boolean, reflect: true }) disabled = false;
|
20
|
-
|
21
|
-
|
74
|
+
|
75
|
+
/** The distance in pixels from which to offset the tooltip away from its target. */
|
22
76
|
@property({ type: Number }) distance = 8;
|
23
|
-
@property({ type: Number }) skidding = 0;
|
24
|
-
@property({ type: Boolean }) hoist = false;
|
25
77
|
|
26
|
-
|
27
|
-
@
|
78
|
+
/** Indicates whether or not the tooltip is open. You can use this in lieu of the show/hide methods. */
|
79
|
+
@property({ type: Boolean, reflect: true }) open = false;
|
28
80
|
|
29
|
-
|
81
|
+
/** The distance in pixels from which to offset the tooltip along its target. */
|
82
|
+
@property({ type: Number }) skidding = 0;
|
30
83
|
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
84
|
+
/**
|
85
|
+
* Controls how the tooltip is activated. Possible options include `click`, `hover`, `focus`, and `manual`. Multiple
|
86
|
+
* options can be passed by separating them with a space. When manual is used, the tooltip must be activated
|
87
|
+
* programmatically.
|
88
|
+
*/
|
89
|
+
@property() trigger = 'hover focus';
|
90
|
+
|
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;
|
35
97
|
|
36
|
-
|
37
|
-
|
38
98
|
connectedCallback() {
|
39
99
|
super.connectedCallback();
|
40
|
-
|
41
|
-
|
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
|
+
});
|
115
|
+
}
|
116
|
+
|
117
|
+
firstUpdated() {
|
118
|
+
this.body.hidden = !this.open;
|
119
|
+
|
120
|
+
// If the tooltip is visible on init, update its position
|
121
|
+
if (this.open) {
|
122
|
+
this.popup.active = true;
|
123
|
+
this.popup.reposition();
|
124
|
+
}
|
42
125
|
}
|
43
126
|
|
44
127
|
disconnectedCallback() {
|
45
128
|
super.disconnectedCallback();
|
46
|
-
|
47
|
-
|
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);
|
48
135
|
}
|
49
136
|
|
50
|
-
private
|
51
|
-
|
137
|
+
private handleBlur() {
|
138
|
+
if (this.hasTrigger('focus')) {
|
139
|
+
this.hide();
|
140
|
+
}
|
52
141
|
}
|
53
142
|
|
54
|
-
private
|
55
|
-
|
56
|
-
|
143
|
+
private handleClick() {
|
144
|
+
if (this.hasTrigger('click')) {
|
145
|
+
if (this.open) {
|
146
|
+
this.hide();
|
147
|
+
} else {
|
148
|
+
this.show();
|
149
|
+
}
|
150
|
+
}
|
57
151
|
}
|
58
152
|
|
59
|
-
private
|
60
|
-
if (
|
61
|
-
|
62
|
-
const triggerEl = this.slotElement.assignedElements()[0] as HTMLElement;
|
63
|
-
if (!triggerEl) return;
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
const triggerRect = triggerEl.getBoundingClientRect();
|
68
|
-
const tooltipRect = this.tooltip.getBoundingClientRect();
|
69
|
-
const viewportWidth = window.innerWidth;
|
70
|
-
const viewportHeight = window.innerHeight;
|
71
|
-
|
72
|
-
let top = 0, left = 0;
|
73
|
-
let finalPlacement = this.placement;
|
74
|
-
const basePlacement = this.getBasePlacement(this.placement);
|
75
|
-
const alignment = this.getAlignmentModifier(this.placement);
|
76
|
-
|
77
|
-
|
78
|
-
const fitsLeft = triggerRect.left - tooltipRect.width - this.distance > 0;
|
79
|
-
const fitsRight = triggerRect.right + tooltipRect.width + this.distance < viewportWidth;
|
80
|
-
const fitsBottom = triggerRect.bottom + tooltipRect.height + this.distance < viewportHeight;
|
81
|
-
const fitsTop = triggerRect.top - tooltipRect.height - this.distance > 0;
|
82
|
-
|
83
|
-
|
84
|
-
let finalBasePlacement = basePlacement;
|
85
|
-
|
86
|
-
|
87
|
-
if ((basePlacement === 'left' && !fitsLeft) || (basePlacement === 'right' && !fitsRight)) {
|
88
|
-
finalBasePlacement = fitsBottom ? 'bottom' : (fitsTop ? 'top' : 'bottom');
|
89
|
-
}
|
90
|
-
|
91
|
-
else if (basePlacement === 'top' && !fitsTop) {
|
92
|
-
finalBasePlacement = fitsBottom ? 'bottom' : (fitsLeft ? 'left' : 'right');
|
93
|
-
} else if (basePlacement === 'bottom' && !fitsBottom) {
|
94
|
-
finalBasePlacement = fitsTop ? 'top' : (fitsLeft ? 'left' : 'right');
|
153
|
+
private handleFocus() {
|
154
|
+
if (this.hasTrigger('focus')) {
|
155
|
+
this.show();
|
95
156
|
}
|
157
|
+
}
|
96
158
|
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
(finalBasePlacement === 'top' || finalBasePlacement === 'bottom')) {
|
103
|
-
|
104
|
-
if (alignment === 'start') {
|
105
|
-
finalAlignment = 'start';
|
106
|
-
} else if (alignment === 'end') {
|
107
|
-
finalAlignment = 'end';
|
108
|
-
}
|
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();
|
109
164
|
}
|
165
|
+
}
|
110
166
|
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
top = triggerRect.top + (triggerRect.height - tooltipRect.height) / 2 + this.skidding;
|
119
|
-
left = triggerRect.right + this.distance;
|
120
|
-
break;
|
121
|
-
case 'top':
|
122
|
-
top = triggerRect.top - tooltipRect.height - this.distance;
|
123
|
-
left = triggerRect.left + (triggerRect.width - tooltipRect.width) / 2 + this.skidding;
|
124
|
-
break;
|
125
|
-
case 'bottom':
|
126
|
-
top = triggerRect.bottom + this.distance;
|
127
|
-
left = triggerRect.left + (triggerRect.width - tooltipRect.width) / 2 + this.skidding;
|
128
|
-
break;
|
167
|
+
private handleMouseOver() {
|
168
|
+
if (this.hasTrigger('hover')) {
|
169
|
+
const delay = parseDuration(
|
170
|
+
getComputedStyle(this).getPropertyValue('--show-delay')
|
171
|
+
);
|
172
|
+
clearTimeout(this.hoverTimeout);
|
173
|
+
this.hoverTimeout = window.setTimeout(() => this.show(), delay);
|
129
174
|
}
|
175
|
+
}
|
130
176
|
|
131
|
-
|
132
|
-
if ((
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
177
|
+
private handleMouseOut() {
|
178
|
+
if (this.hasTrigger('hover')) {
|
179
|
+
const delay = parseDuration(
|
180
|
+
getComputedStyle(this).getPropertyValue('--hide-delay')
|
181
|
+
);
|
182
|
+
clearTimeout(this.hoverTimeout);
|
183
|
+
this.hoverTimeout = window.setTimeout(() => this.hide(), delay);
|
138
184
|
}
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
185
|
+
}
|
186
|
+
|
187
|
+
private hasTrigger(triggerType: string) {
|
188
|
+
const triggers = this.trigger.split(' ');
|
189
|
+
return triggers.includes(triggerType);
|
190
|
+
}
|
191
|
+
|
192
|
+
@watch('open', { waitUntilFirstUpdate: true })
|
193
|
+
async handleOpenChange() {
|
194
|
+
if (this.open) {
|
195
|
+
if (this.disabled) {
|
196
|
+
return;
|
146
197
|
}
|
147
|
-
}
|
148
198
|
|
149
|
-
|
150
|
-
finalPlacement = finalAlignment ? `${finalBasePlacement}-${finalAlignment}` : finalBasePlacement;
|
151
|
-
|
152
|
-
|
153
|
-
if (left < 0) left = 5;
|
154
|
-
if (left + tooltipRect.width > viewportWidth) left = viewportWidth - tooltipRect.width - 5;
|
155
|
-
if (top < 0) top = 5;
|
156
|
-
if (top + tooltipRect.height > viewportHeight) top = viewportHeight - tooltipRect.height - 5;
|
157
|
-
|
158
|
-
|
159
|
-
this.tooltip.style.top = `${top}px`;
|
160
|
-
this.tooltip.style.left = `${left}px`;
|
161
|
-
this.tooltip.setAttribute('data-placement', finalPlacement as string);
|
162
|
-
};
|
163
|
-
|
164
|
-
private showTooltip = () => {
|
165
|
-
if (!this.disabled &&
|
166
|
-
this.content.trim() !== '') {
|
167
|
-
this.open = true;
|
199
|
+
// Show
|
168
200
|
this.emit('nile-show');
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
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: '',
|
174
207
|
});
|
175
|
-
|
176
|
-
};
|
177
|
-
|
178
|
-
private handleAfterShow = () => {
|
179
|
-
this.emit('nile-after-show');
|
180
|
-
};
|
181
|
-
|
182
|
-
|
183
|
-
private hideTooltip = () => {
|
184
|
-
if (!this.open) return;
|
185
|
-
|
186
|
-
this.emit('nile-hide');
|
187
|
-
this.open = false;
|
188
|
-
|
189
|
-
this.tooltip.addEventListener('transitionend', this.handleAfterHide, { once: true });
|
190
|
-
};
|
191
|
-
|
192
|
-
private handleAfterHide = () => {
|
193
|
-
this.emit('nile-after-hide');
|
194
|
-
};
|
195
|
-
|
196
|
-
private handleMouseOver = () => {
|
197
|
-
if (this.trigger.includes('hover')) {
|
198
|
-
clearTimeout(this.hoverTimeout);
|
199
|
-
this.hoverTimeout = window.setTimeout(() => this.showTooltip(), 150);
|
200
|
-
}
|
201
|
-
};
|
208
|
+
await animateTo(this.popup.popup, keyframes, options);
|
202
209
|
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
this.
|
210
|
+
this.emit('nile-after-show');
|
211
|
+
} else {
|
212
|
+
// Hide
|
213
|
+
this.emit('nile-hide');
|
214
|
+
|
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;
|
222
|
+
|
223
|
+
this.emit('nile-after-hide');
|
207
224
|
}
|
208
|
-
}
|
225
|
+
}
|
209
226
|
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
this.
|
214
|
-
this.
|
227
|
+
@watch(['content', 'distance', 'hoist', 'placement', 'skidding'])
|
228
|
+
async handleOptionsChange() {
|
229
|
+
if (this.hasUpdated) {
|
230
|
+
await this.updateComplete;
|
231
|
+
this.popup.reposition();
|
215
232
|
}
|
216
|
-
}
|
217
|
-
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
|
222
|
-
if (changedProperties.has('open') || changedProperties.has('hoist')) {
|
223
|
-
if (this.open && this.hoist) {
|
224
|
-
|
225
|
-
}
|
233
|
+
}
|
234
|
+
|
235
|
+
@watch('disabled')
|
236
|
+
handleDisabledChange() {
|
237
|
+
if (this.disabled && this.open) {
|
238
|
+
this.hide();
|
226
239
|
}
|
227
240
|
}
|
228
241
|
|
229
|
-
|
230
|
-
|
231
|
-
|
242
|
+
/** Shows the tooltip. */
|
243
|
+
async show() {
|
244
|
+
if (this.open || !this.content?.trim().length) {
|
245
|
+
return undefined;
|
232
246
|
}
|
233
|
-
};
|
234
247
|
|
235
|
-
|
236
|
-
|
237
|
-
|
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;
|
238
256
|
}
|
239
|
-
|
257
|
+
|
258
|
+
this.open = false;
|
259
|
+
return waitForEvent(this, 'nile-after-hide');
|
260
|
+
}
|
240
261
|
|
241
262
|
render() {
|
242
263
|
return html`
|
243
|
-
<
|
244
|
-
|
245
|
-
|
246
|
-
|
247
|
-
|
248
|
-
|
249
|
-
|
250
|
-
|
251
|
-
|
252
|
-
|
253
|
-
|
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
|
281
|
+
>
|
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>
|
254
298
|
`;
|
255
299
|
}
|
256
300
|
}
|
257
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
|
+
|
258
320
|
declare global {
|
259
321
|
interface HTMLElementTagNameMap {
|
260
322
|
'nile-tooltip': NileTooltip;
|
261
323
|
}
|
262
|
-
}
|
324
|
+
}
|