@fluid-topics/ft-tooltip 1.3.31 → 1.3.32
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/build/ft-tooltip.d.ts +10 -1
- package/build/ft-tooltip.js +86 -51
- package/build/ft-tooltip.light.js +35 -40
- package/build/ft-tooltip.min.js +57 -62
- package/package.json +4 -4
package/build/ft-tooltip.d.ts
CHANGED
|
@@ -9,6 +9,7 @@ export declare class FtTooltip extends FtLitElement implements FtTooltipProperti
|
|
|
9
9
|
inline: boolean;
|
|
10
10
|
delay: number;
|
|
11
11
|
position: Position;
|
|
12
|
+
ignoreMatchingElements: string[];
|
|
12
13
|
private slotNodes?;
|
|
13
14
|
private container?;
|
|
14
15
|
private tooltip?;
|
|
@@ -17,20 +18,28 @@ export declare class FtTooltip extends FtLitElement implements FtTooltipProperti
|
|
|
17
18
|
private readonly validPositions;
|
|
18
19
|
private get validPosition();
|
|
19
20
|
protected render(): import("lit-html").TemplateResult<1>;
|
|
21
|
+
private eventsTarget?;
|
|
22
|
+
setupFor(eventsTarget: HTMLElement): void;
|
|
23
|
+
removeHandlers(): void;
|
|
24
|
+
defaultSetup(): void;
|
|
20
25
|
protected updated(props: PropertyValues): void;
|
|
21
26
|
protected contentAvailableCallback(props: PropertyValues): void;
|
|
27
|
+
connectedCallback(): void;
|
|
28
|
+
disconnectedCallback(): void;
|
|
22
29
|
private hideDebounce;
|
|
23
30
|
show(duration?: number): Promise<void>;
|
|
24
31
|
showTemporaryText(text: string, duration: number): Promise<void>;
|
|
25
32
|
hide(): void;
|
|
26
33
|
toggle(): void;
|
|
34
|
+
isVisible(): boolean;
|
|
27
35
|
private get slottedElement();
|
|
28
36
|
private resetTooltipContent;
|
|
29
37
|
private revealDebouncer;
|
|
30
38
|
private positionTooltip;
|
|
31
39
|
private onTouch;
|
|
32
40
|
private onHover;
|
|
41
|
+
private onFocusIn;
|
|
33
42
|
private onOut;
|
|
34
43
|
private onClick;
|
|
35
|
-
|
|
44
|
+
protected isIgnored(e: Event): boolean;
|
|
36
45
|
}
|
package/build/ft-tooltip.js
CHANGED
|
@@ -5,8 +5,8 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
|
|
|
5
5
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
6
6
|
};
|
|
7
7
|
import { html } from "lit";
|
|
8
|
-
import {
|
|
9
|
-
import { Debouncer, designSystemVariables, FtLitElement } from "@fluid-topics/ft-wc-utils";
|
|
8
|
+
import { property, query, queryAssignedNodes, state } from "lit/decorators.js";
|
|
9
|
+
import { Debouncer, designSystemVariables, eventPathContainsMatchingElement, FtLitElement, jsonProperty, numberProperty } from "@fluid-topics/ft-wc-utils";
|
|
10
10
|
import { FtTypography } from "@fluid-topics/ft-typography";
|
|
11
11
|
import { styles } from "./ft-tooltip.styles";
|
|
12
12
|
import { computeOffsetPosition } from "@fluid-topics/ft-wc-utils/build/floating";
|
|
@@ -18,10 +18,43 @@ class FtTooltip extends FtLitElement {
|
|
|
18
18
|
this.inline = false;
|
|
19
19
|
this.delay = 500;
|
|
20
20
|
this.position = "bottom";
|
|
21
|
+
this.ignoreMatchingElements = [];
|
|
21
22
|
this.visible = false;
|
|
22
23
|
this.validPositions = new Set(["top", "bottom", "left", "right"]);
|
|
23
24
|
this.hideDebounce = new Debouncer();
|
|
24
25
|
this.revealDebouncer = new Debouncer();
|
|
26
|
+
this.onTouch = (e) => {
|
|
27
|
+
if (!this.isIgnored(e)) {
|
|
28
|
+
this.show();
|
|
29
|
+
setTimeout(() => window.addEventListener("touchstart", (e) => {
|
|
30
|
+
if (!e.composedPath().includes(this.container)) {
|
|
31
|
+
this.onOut(e);
|
|
32
|
+
}
|
|
33
|
+
}, { once: true }), 100);
|
|
34
|
+
}
|
|
35
|
+
};
|
|
36
|
+
this.onHover = (e) => {
|
|
37
|
+
if (!this.isIgnored(e)) {
|
|
38
|
+
this.show();
|
|
39
|
+
}
|
|
40
|
+
};
|
|
41
|
+
this.onFocusIn = (e) => {
|
|
42
|
+
if (!this.isIgnored(e) && window.FluidTopicsA11yHints.isKeyboardNavigation && window.FluidTopicsA11yHints.lastPressedKey === "Tab") {
|
|
43
|
+
this.show();
|
|
44
|
+
}
|
|
45
|
+
};
|
|
46
|
+
this.onOut = (e) => {
|
|
47
|
+
if (!this.isIgnored(e)) {
|
|
48
|
+
this.revealDebouncer.cancel();
|
|
49
|
+
this.hide();
|
|
50
|
+
}
|
|
51
|
+
};
|
|
52
|
+
this.onClick = (e) => {
|
|
53
|
+
if (!this.isIgnored(e)) {
|
|
54
|
+
this.revealDebouncer.cancel();
|
|
55
|
+
this.hide();
|
|
56
|
+
}
|
|
57
|
+
};
|
|
25
58
|
}
|
|
26
59
|
get validPosition() {
|
|
27
60
|
return this.validPositions.has(this.position) ? this.position : "bottom";
|
|
@@ -29,13 +62,8 @@ class FtTooltip extends FtLitElement {
|
|
|
29
62
|
render() {
|
|
30
63
|
return html `
|
|
31
64
|
<div part="container"
|
|
32
|
-
class="ft-tooltip--container ${this.inline ? "ft-tooltip--inline" : ""}"
|
|
33
|
-
|
|
34
|
-
@mouseleave=${this.onOut}
|
|
35
|
-
@focusin=${this.onHover}
|
|
36
|
-
@focusout=${this.onOut}
|
|
37
|
-
@touchstart=${this.onTouch}>
|
|
38
|
-
<slot part="slot" @click=${this.onClick}></slot>
|
|
65
|
+
class="ft-tooltip--container ${this.inline ? "ft-tooltip--inline" : ""}">
|
|
66
|
+
<slot part="slot"></slot>
|
|
39
67
|
<div part="tooltip" role="tooltip" inert
|
|
40
68
|
class="ft-tooltip ft-tooltip--${this.validPosition}"
|
|
41
69
|
?hidden=${!this.visible}>
|
|
@@ -47,6 +75,34 @@ class FtTooltip extends FtLitElement {
|
|
|
47
75
|
</div>
|
|
48
76
|
`;
|
|
49
77
|
}
|
|
78
|
+
setupFor(eventsTarget) {
|
|
79
|
+
if (this.eventsTarget !== eventsTarget) {
|
|
80
|
+
this.removeHandlers();
|
|
81
|
+
this.eventsTarget = eventsTarget;
|
|
82
|
+
this.eventsTarget.addEventListener("mouseenter", this.onHover, { passive: true });
|
|
83
|
+
this.eventsTarget.addEventListener("mouseleave", this.onOut, { passive: true });
|
|
84
|
+
this.eventsTarget.addEventListener("focusin", this.onFocusIn, { passive: true });
|
|
85
|
+
this.eventsTarget.addEventListener("focusout", this.onOut, { passive: true });
|
|
86
|
+
this.eventsTarget.addEventListener("touchstart", this.onTouch, { passive: true });
|
|
87
|
+
this.eventsTarget.addEventListener("click", this.onClick, { passive: true });
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
removeHandlers() {
|
|
91
|
+
if (this.eventsTarget) {
|
|
92
|
+
this.eventsTarget.removeEventListener("mouseenter", this.onHover);
|
|
93
|
+
this.eventsTarget.removeEventListener("mouseleave", this.onOut);
|
|
94
|
+
this.eventsTarget.removeEventListener("focusin", this.onFocusIn);
|
|
95
|
+
this.eventsTarget.removeEventListener("focusout", this.onOut);
|
|
96
|
+
this.eventsTarget.removeEventListener("touchstart", this.onTouch);
|
|
97
|
+
this.eventsTarget.removeEventListener("click", this.onClick);
|
|
98
|
+
this.eventsTarget = undefined;
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
defaultSetup() {
|
|
102
|
+
if (this.container) {
|
|
103
|
+
this.setupFor(this.container);
|
|
104
|
+
}
|
|
105
|
+
}
|
|
50
106
|
updated(props) {
|
|
51
107
|
if (props.has("visible") && this.visible) {
|
|
52
108
|
this.resetTooltipContent();
|
|
@@ -59,6 +115,18 @@ class FtTooltip extends FtLitElement {
|
|
|
59
115
|
this.positionTooltip();
|
|
60
116
|
}
|
|
61
117
|
}
|
|
118
|
+
connectedCallback() {
|
|
119
|
+
super.connectedCallback();
|
|
120
|
+
this.updateComplete.then(() => {
|
|
121
|
+
if (this.eventsTarget == undefined) {
|
|
122
|
+
this.defaultSetup();
|
|
123
|
+
}
|
|
124
|
+
});
|
|
125
|
+
}
|
|
126
|
+
disconnectedCallback() {
|
|
127
|
+
super.disconnectedCallback();
|
|
128
|
+
this.removeHandlers();
|
|
129
|
+
}
|
|
62
130
|
async show(duration) {
|
|
63
131
|
this.visible = true;
|
|
64
132
|
if (duration != null) {
|
|
@@ -82,6 +150,9 @@ class FtTooltip extends FtLitElement {
|
|
|
82
150
|
toggle() {
|
|
83
151
|
this.visible = !this.visible;
|
|
84
152
|
}
|
|
153
|
+
isVisible() {
|
|
154
|
+
return this.visible;
|
|
155
|
+
}
|
|
85
156
|
get slottedElement() {
|
|
86
157
|
var _a;
|
|
87
158
|
return ((_a = this.slotNodes) !== null && _a !== void 0 ? _a : []).filter((node) => node.nodeType == Node.ELEMENT_NODE)[0];
|
|
@@ -131,35 +202,8 @@ class FtTooltip extends FtLitElement {
|
|
|
131
202
|
}
|
|
132
203
|
}, this.manual ? 0 : this.delay);
|
|
133
204
|
}
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
this.show();
|
|
137
|
-
setTimeout(() => window.addEventListener("touchstart", (e) => {
|
|
138
|
-
if (!e.composedPath().includes(this.container)) {
|
|
139
|
-
this.onOut();
|
|
140
|
-
}
|
|
141
|
-
}, { once: true }), 100);
|
|
142
|
-
}
|
|
143
|
-
}
|
|
144
|
-
onHover() {
|
|
145
|
-
if (!this.manual) {
|
|
146
|
-
this.show();
|
|
147
|
-
}
|
|
148
|
-
}
|
|
149
|
-
onOut() {
|
|
150
|
-
if (!this.manual) {
|
|
151
|
-
this.revealDebouncer.cancel();
|
|
152
|
-
this.hide();
|
|
153
|
-
}
|
|
154
|
-
}
|
|
155
|
-
onClick() {
|
|
156
|
-
if (!this.manual) {
|
|
157
|
-
this.revealDebouncer.cancel();
|
|
158
|
-
this.hide();
|
|
159
|
-
}
|
|
160
|
-
}
|
|
161
|
-
correctOutOfWindowPixels(leftOrTopOutOfWindowPixels, rightOrBottomOutOfWindowPixels) {
|
|
162
|
-
return Math.max(leftOrTopOutOfWindowPixels, Math.min(0, -rightOrBottomOutOfWindowPixels));
|
|
205
|
+
isIgnored(e) {
|
|
206
|
+
return this.manual || eventPathContainsMatchingElement(e, this.ignoreMatchingElements, this.eventsTarget);
|
|
163
207
|
}
|
|
164
208
|
}
|
|
165
209
|
FtTooltip.elementDefinitions = {
|
|
@@ -176,11 +220,14 @@ __decorate([
|
|
|
176
220
|
property({ type: Boolean })
|
|
177
221
|
], FtTooltip.prototype, "inline", void 0);
|
|
178
222
|
__decorate([
|
|
179
|
-
|
|
223
|
+
numberProperty()
|
|
180
224
|
], FtTooltip.prototype, "delay", void 0);
|
|
181
225
|
__decorate([
|
|
182
226
|
property()
|
|
183
227
|
], FtTooltip.prototype, "position", void 0);
|
|
228
|
+
__decorate([
|
|
229
|
+
jsonProperty([])
|
|
230
|
+
], FtTooltip.prototype, "ignoreMatchingElements", void 0);
|
|
184
231
|
__decorate([
|
|
185
232
|
queryAssignedNodes()
|
|
186
233
|
], FtTooltip.prototype, "slotNodes", void 0);
|
|
@@ -196,16 +243,4 @@ __decorate([
|
|
|
196
243
|
__decorate([
|
|
197
244
|
state()
|
|
198
245
|
], FtTooltip.prototype, "visible", void 0);
|
|
199
|
-
__decorate([
|
|
200
|
-
eventOptions({ passive: true })
|
|
201
|
-
], FtTooltip.prototype, "onTouch", null);
|
|
202
|
-
__decorate([
|
|
203
|
-
eventOptions({ passive: true })
|
|
204
|
-
], FtTooltip.prototype, "onHover", null);
|
|
205
|
-
__decorate([
|
|
206
|
-
eventOptions({ passive: true })
|
|
207
|
-
], FtTooltip.prototype, "onOut", null);
|
|
208
|
-
__decorate([
|
|
209
|
-
eventOptions({ passive: true })
|
|
210
|
-
], FtTooltip.prototype, "onClick", null);
|
|
211
246
|
export { FtTooltip };
|