@spectrum-web-components/tooltip 0.35.0 → 0.35.1-rc.24
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/package.json +5 -4
- package/src/Tooltip.d.ts +14 -37
- package/src/Tooltip.dev.js +118 -166
- package/src/Tooltip.dev.js.map +3 -3
- package/src/Tooltip.js +26 -5
- package/src/Tooltip.js.map +3 -3
- package/src/spectrum-config.js +120 -17
- package/src/spectrum-tooltip.css.dev.js +19 -19
- package/src/spectrum-tooltip.css.dev.js.map +1 -1
- package/src/spectrum-tooltip.css.js +19 -19
- package/src/spectrum-tooltip.css.js.map +1 -1
- package/src/tooltip.css.dev.js +23 -20
- package/src/tooltip.css.dev.js.map +2 -2
- package/src/tooltip.css.js +23 -20
- package/src/tooltip.css.js.map +2 -2
- package/stories/tooltip.stories.js +15 -16
- package/stories/tooltip.stories.js.map +2 -2
- package/test/tooltip.test.js +24 -58
- package/test/tooltip.test.js.map +2 -2
- package/custom-elements.json +0 -376
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@spectrum-web-components/tooltip",
|
|
3
|
-
"version": "0.35.
|
|
3
|
+
"version": "0.35.1-rc.24+e3649e123",
|
|
4
4
|
"publishConfig": {
|
|
5
5
|
"access": "public"
|
|
6
6
|
},
|
|
@@ -57,8 +57,9 @@
|
|
|
57
57
|
"lit-html"
|
|
58
58
|
],
|
|
59
59
|
"dependencies": {
|
|
60
|
-
"@spectrum-web-components/base": "^0.35.
|
|
61
|
-
"@spectrum-web-components/overlay": "^0.35.
|
|
60
|
+
"@spectrum-web-components/base": "^0.35.1-rc.24+e3649e123",
|
|
61
|
+
"@spectrum-web-components/overlay": "^0.35.1-rc.24+e3649e123",
|
|
62
|
+
"@spectrum-web-components/shared": "^0.35.1-rc.24+e3649e123"
|
|
62
63
|
},
|
|
63
64
|
"devDependencies": {
|
|
64
65
|
"@spectrum-css/tooltip": "^5.0.42"
|
|
@@ -69,5 +70,5 @@
|
|
|
69
70
|
"./sp-*.js",
|
|
70
71
|
"./**/*.dev.js"
|
|
71
72
|
],
|
|
72
|
-
"gitHead": "
|
|
73
|
+
"gitHead": "e3649e1230ed727048988a452969c38ced5467ac"
|
|
73
74
|
}
|
package/src/Tooltip.d.ts
CHANGED
|
@@ -1,8 +1,6 @@
|
|
|
1
|
-
import { CSSResultArray,
|
|
2
|
-
import type {
|
|
3
|
-
|
|
4
|
-
disconnectedCallback(): void;
|
|
5
|
-
}
|
|
1
|
+
import { CSSResultArray, SpectrumElement, TemplateResult } from '@spectrum-web-components/base';
|
|
2
|
+
import type { Placement } from '@spectrum-web-components/overlay';
|
|
3
|
+
import '@spectrum-web-components/overlay/sp-overlay.js';
|
|
6
4
|
/**
|
|
7
5
|
* @element sp-tooltip
|
|
8
6
|
*
|
|
@@ -12,47 +10,26 @@ export declare class TooltipProxy extends HTMLElement {
|
|
|
12
10
|
export declare class Tooltip extends SpectrumElement {
|
|
13
11
|
static get styles(): CSSResultArray;
|
|
14
12
|
/**
|
|
15
|
-
*
|
|
16
|
-
|
|
17
|
-
static instanceCount: number;
|
|
18
|
-
private _tooltipId;
|
|
19
|
-
/**
|
|
20
|
-
* Automatically bind to the parent element's hover interaction. Without this, you must provide your own `overlay-trigger`.
|
|
13
|
+
* Automatically bind to the parent element of the assigned `slot` or the parent element of the `sp-tooltip`.
|
|
14
|
+
* Without this, you must provide your own `overlay-trigger`.
|
|
21
15
|
*/
|
|
22
16
|
selfManaged: boolean;
|
|
23
17
|
offset: number;
|
|
24
|
-
private hadTooltipId;
|
|
25
18
|
open: boolean;
|
|
26
19
|
/**
|
|
27
|
-
* @type {"auto" | "auto-start" | "auto-end" | "top" | "bottom" | "right" | "left" | "top-start" | "top-end" | "bottom-start" | "bottom-end" | "right-start" | "right-end" | "left-start" | "left-end"
|
|
20
|
+
* @type {"auto" | "auto-start" | "auto-end" | "top" | "bottom" | "right" | "left" | "top-start" | "top-end" | "bottom-start" | "bottom-end" | "right-start" | "right-end" | "left-start" | "left-end"}
|
|
28
21
|
* @attr
|
|
29
22
|
*/
|
|
30
|
-
placement
|
|
31
|
-
|
|
23
|
+
placement?: Placement;
|
|
24
|
+
tipElement: HTMLSpanElement;
|
|
25
|
+
tipPadding?: number;
|
|
32
26
|
private _variant;
|
|
33
27
|
get variant(): string;
|
|
34
28
|
set variant(variant: string);
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
trigger: HTMLElement;
|
|
41
|
-
}): void;
|
|
42
|
-
overlayOpenCancelledCallback({ trigger, }: {
|
|
43
|
-
trigger: HTMLElement;
|
|
44
|
-
}): void;
|
|
45
|
-
overlayCloseCallback({ trigger }: {
|
|
46
|
-
trigger: HTMLElement;
|
|
47
|
-
}): void;
|
|
48
|
-
private removeProxy;
|
|
49
|
-
private closeOverlayCallback?;
|
|
50
|
-
private abortOverlay;
|
|
51
|
-
private openOverlay;
|
|
52
|
-
private closeOverlay;
|
|
53
|
-
private previousSlot?;
|
|
54
|
-
private manageTooltip;
|
|
29
|
+
private handleOpenOverlay;
|
|
30
|
+
protected handleCloseOverlay: () => void;
|
|
31
|
+
protected handleTransitionrun(event: TransitionEvent): void;
|
|
32
|
+
protected handleTransitionend(event: TransitionEvent): void;
|
|
33
|
+
private get triggerElement();
|
|
55
34
|
render(): TemplateResult;
|
|
56
|
-
protected update(changed: PropertyValues<this>): Promise<void>;
|
|
57
|
-
protected updated(changed: PropertyValues<this>): void;
|
|
58
35
|
}
|
package/src/Tooltip.dev.js
CHANGED
|
@@ -18,70 +18,75 @@ import {
|
|
|
18
18
|
property,
|
|
19
19
|
query
|
|
20
20
|
} from "@spectrum-web-components/base/src/decorators.js";
|
|
21
|
-
import
|
|
22
|
-
import { openOverlay } from "@spectrum-web-components/overlay/src/loader.js";
|
|
21
|
+
import "@spectrum-web-components/overlay/sp-overlay.js";
|
|
23
22
|
import tooltipStyles from "./tooltip.css.js";
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
23
|
+
import { ifDefined } from "lit/directives/if-defined.js";
|
|
24
|
+
import { focusableSelector } from "@spectrum-web-components/shared/src/focusable-selectors.js";
|
|
25
|
+
class TooltipOpenable extends HTMLElement {
|
|
26
|
+
constructor() {
|
|
27
|
+
super(...arguments);
|
|
28
|
+
this._open = false;
|
|
29
|
+
this._placement = "top";
|
|
30
|
+
}
|
|
31
|
+
static get observedAttributes() {
|
|
32
|
+
return ["open", "placement"];
|
|
33
|
+
}
|
|
34
|
+
attributeChangedCallback(name, _oldValue, newValue) {
|
|
35
|
+
switch (name) {
|
|
36
|
+
case "open":
|
|
37
|
+
this.open = newValue !== null;
|
|
38
|
+
break;
|
|
39
|
+
case "placement":
|
|
40
|
+
this.placement = newValue;
|
|
41
|
+
break;
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
set open(open) {
|
|
45
|
+
this._open = open;
|
|
46
|
+
const tooltip = this.getRootNode().host;
|
|
47
|
+
if (tooltip) {
|
|
48
|
+
tooltip.open = open;
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
get open() {
|
|
52
|
+
return this._open;
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* @type {"auto" | "auto-start" | "auto-end" | "top" | "bottom" | "right" | "left" | "top-start" | "top-end" | "bottom-start" | "bottom-end" | "right-start" | "right-end" | "left-start" | "left-end"}
|
|
56
|
+
* @attr
|
|
57
|
+
*/
|
|
58
|
+
set placement(placement) {
|
|
59
|
+
this._placement = placement;
|
|
60
|
+
const tooltip = this.getRootNode().host;
|
|
61
|
+
if (tooltip) {
|
|
62
|
+
tooltip.placement = placement;
|
|
63
|
+
}
|
|
27
64
|
}
|
|
65
|
+
get placement() {
|
|
66
|
+
return this._placement;
|
|
67
|
+
}
|
|
68
|
+
get tipElement() {
|
|
69
|
+
const tooltip = this.getRootNode().host;
|
|
70
|
+
return tooltip.tipElement;
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
if (!customElements.get("sp-tooltip-openable")) {
|
|
74
|
+
customElements.define("sp-tooltip-openable", TooltipOpenable);
|
|
28
75
|
}
|
|
29
|
-
|
|
30
|
-
const _Tooltip = class extends SpectrumElement {
|
|
76
|
+
export class Tooltip extends SpectrumElement {
|
|
31
77
|
constructor() {
|
|
32
|
-
super();
|
|
33
|
-
this._tooltipId = `sp-tooltip-describedby-helper-${_Tooltip.instanceCount++}`;
|
|
78
|
+
super(...arguments);
|
|
34
79
|
this.selfManaged = false;
|
|
35
|
-
this.offset =
|
|
36
|
-
this.hadTooltipId = false;
|
|
80
|
+
this.offset = 0;
|
|
37
81
|
this.open = false;
|
|
38
|
-
this.placement = "top";
|
|
39
82
|
/* Ensure that a '' value for `variant` removes the attribute instead of a blank value */
|
|
40
83
|
this._variant = "";
|
|
41
|
-
this.
|
|
42
|
-
|
|
43
|
-
};
|
|
44
|
-
this.openOverlay = () => {
|
|
45
|
-
const parentElement = this.parentElement;
|
|
46
|
-
const abortPromise = new Promise((res) => {
|
|
47
|
-
this.abortOverlay = res;
|
|
48
|
-
});
|
|
49
|
-
if (true) {
|
|
50
|
-
window.__swc.ignoreWarningLevels.deprecation = true;
|
|
51
|
-
}
|
|
52
|
-
this.closeOverlayCallback = openOverlay(parentElement, "hover", this, {
|
|
53
|
-
abortPromise,
|
|
54
|
-
offset: this.offset,
|
|
55
|
-
placement: this.placement
|
|
56
|
-
});
|
|
57
|
-
if (true) {
|
|
58
|
-
window.__swc.ignoreWarningLevels.deprecation = false;
|
|
59
|
-
}
|
|
84
|
+
this.handleOpenOverlay = () => {
|
|
85
|
+
this.open = true;
|
|
60
86
|
};
|
|
61
|
-
this.
|
|
62
|
-
|
|
63
|
-
if (pointerIsEnteringTooltip) {
|
|
64
|
-
this.addEventListener(
|
|
65
|
-
"pointerleave",
|
|
66
|
-
(event2) => {
|
|
67
|
-
const pointerIsEnteringParnet = event2.relatedTarget === this.parentElement;
|
|
68
|
-
if (pointerIsEnteringParnet) {
|
|
69
|
-
return;
|
|
70
|
-
}
|
|
71
|
-
this.closeOverlay(event2);
|
|
72
|
-
},
|
|
73
|
-
{ once: true }
|
|
74
|
-
);
|
|
75
|
-
return;
|
|
76
|
-
}
|
|
77
|
-
if (this.abortOverlay)
|
|
78
|
-
this.abortOverlay(true);
|
|
79
|
-
if (!this.closeOverlayCallback)
|
|
80
|
-
return;
|
|
81
|
-
(await this.closeOverlayCallback)();
|
|
82
|
-
delete this.closeOverlayCallback;
|
|
87
|
+
this.handleCloseOverlay = () => {
|
|
88
|
+
this.open = false;
|
|
83
89
|
};
|
|
84
|
-
this.addEventListener("sp-overlay-query", this.onOverlayQuery);
|
|
85
90
|
}
|
|
86
91
|
static get styles() {
|
|
87
92
|
return [tooltipStyles];
|
|
@@ -101,130 +106,74 @@ const _Tooltip = class extends SpectrumElement {
|
|
|
101
106
|
this.removeAttribute("variant");
|
|
102
107
|
this._variant = "";
|
|
103
108
|
}
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
generateProxy() {
|
|
113
|
-
if (this._proxy) {
|
|
114
|
-
return;
|
|
115
|
-
}
|
|
116
|
-
this._proxy = document.createElement("tooltip-proxy");
|
|
117
|
-
this._proxy.id = this._tooltipId;
|
|
118
|
-
this._proxy.hidden = true;
|
|
119
|
-
this._proxy.slot = "hidden-tooltip-content";
|
|
120
|
-
this._proxy.setAttribute("role", "tooltip");
|
|
121
|
-
this._proxy.addEventListener("disconnected", this.closeOverlay);
|
|
122
|
-
}
|
|
123
|
-
overlayWillOpenCallback({
|
|
124
|
-
trigger
|
|
125
|
-
}) {
|
|
126
|
-
this.setAttribute("aria-hidden", "true");
|
|
127
|
-
this.generateProxy();
|
|
128
|
-
this._proxy.textContent = this.textContent;
|
|
129
|
-
const ariaDescribedby = trigger.getAttribute("aria-describedby") || "";
|
|
130
|
-
this.hadTooltipId = ariaDescribedby.search(this._tooltipId) > -1;
|
|
131
|
-
this.insertAdjacentElement("beforebegin", this._proxy);
|
|
132
|
-
if (this.hadTooltipId)
|
|
133
|
-
return;
|
|
134
|
-
if (ariaDescribedby) {
|
|
135
|
-
trigger.setAttribute(
|
|
136
|
-
"aria-describedby",
|
|
137
|
-
`${ariaDescribedby} ${this._tooltipId}`
|
|
138
|
-
);
|
|
139
|
-
} else {
|
|
140
|
-
trigger.setAttribute("aria-describedby", `${this._tooltipId}`);
|
|
141
|
-
}
|
|
142
|
-
}
|
|
143
|
-
overlayOpenCancelledCallback({
|
|
144
|
-
trigger
|
|
145
|
-
}) {
|
|
146
|
-
this.overlayCloseCallback({ trigger });
|
|
147
|
-
}
|
|
148
|
-
overlayCloseCallback({ trigger }) {
|
|
149
|
-
const ariaDescribedby = trigger.getAttribute("aria-describedby") || "";
|
|
150
|
-
let descriptors = ariaDescribedby.split(/\s+/);
|
|
151
|
-
if (!this.hadTooltipId) {
|
|
152
|
-
descriptors = descriptors.filter(
|
|
153
|
-
(descriptor) => descriptor !== this._tooltipId
|
|
154
|
-
);
|
|
155
|
-
}
|
|
156
|
-
if (descriptors.length) {
|
|
157
|
-
trigger.setAttribute("aria-describedby", descriptors.join(" "));
|
|
158
|
-
} else {
|
|
159
|
-
trigger.removeAttribute("aria-describedby");
|
|
160
|
-
}
|
|
161
|
-
this.removeAttribute("aria-hidden");
|
|
162
|
-
this.removeProxy();
|
|
109
|
+
handleTransitionrun(event) {
|
|
110
|
+
this.dispatchEvent(
|
|
111
|
+
new TransitionEvent("transitionrun", {
|
|
112
|
+
bubbles: true,
|
|
113
|
+
composed: true,
|
|
114
|
+
propertyName: event.propertyName
|
|
115
|
+
})
|
|
116
|
+
);
|
|
163
117
|
}
|
|
164
|
-
|
|
165
|
-
this.
|
|
118
|
+
handleTransitionend(event) {
|
|
119
|
+
this.dispatchEvent(
|
|
120
|
+
new TransitionEvent("transitionend", {
|
|
121
|
+
bubbles: true,
|
|
122
|
+
composed: true,
|
|
123
|
+
propertyName: event.propertyName
|
|
124
|
+
})
|
|
125
|
+
);
|
|
166
126
|
}
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
parentElement.
|
|
175
|
-
parentElement.addEventListener("focusin", this.openOverlay);
|
|
176
|
-
parentElement.addEventListener("pointerleave", this.closeOverlay);
|
|
177
|
-
parentElement.addEventListener("focusout", this.closeOverlay);
|
|
178
|
-
} else {
|
|
179
|
-
if (this.previousSlot) {
|
|
180
|
-
this.slot = this.previousSlot;
|
|
181
|
-
} else if (this.slot === "self-managed-tooltip") {
|
|
182
|
-
this.removeAttribute("slot");
|
|
183
|
-
}
|
|
184
|
-
parentElement.removeEventListener("pointerenter", this.openOverlay);
|
|
185
|
-
parentElement.removeEventListener("focusin", this.openOverlay);
|
|
186
|
-
parentElement.removeEventListener(
|
|
187
|
-
"pointerleave",
|
|
188
|
-
this.closeOverlay
|
|
189
|
-
);
|
|
190
|
-
parentElement.removeEventListener("focusout", this.closeOverlay);
|
|
127
|
+
get triggerElement() {
|
|
128
|
+
let start = this.assignedSlot || this;
|
|
129
|
+
let root = start.getRootNode();
|
|
130
|
+
let triggerElement = start.parentElement || root.host || root;
|
|
131
|
+
while (!(triggerElement == null ? void 0 : triggerElement.matches(focusableSelector))) {
|
|
132
|
+
start = triggerElement.assignedSlot || triggerElement;
|
|
133
|
+
root = start.getRootNode();
|
|
134
|
+
triggerElement = start.parentElement || root.host || root;
|
|
191
135
|
}
|
|
136
|
+
return triggerElement;
|
|
192
137
|
}
|
|
193
138
|
render() {
|
|
194
|
-
|
|
195
|
-
<
|
|
196
|
-
|
|
197
|
-
|
|
139
|
+
const tooltip = html`
|
|
140
|
+
<sp-tooltip-openable
|
|
141
|
+
id="tooltip"
|
|
142
|
+
placement=${ifDefined(this.placement)}
|
|
143
|
+
@transitionrun=${this.handleTransitionrun}
|
|
144
|
+
@transitionend=${this.handleTransitionend}
|
|
145
|
+
>
|
|
146
|
+
<slot name="icon"></slot>
|
|
147
|
+
<span id="label"><slot></slot></span>
|
|
148
|
+
<span id="tip"></span>
|
|
149
|
+
</sp-tooltip-openable>
|
|
198
150
|
`;
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
151
|
+
if (this.selfManaged) {
|
|
152
|
+
return html`
|
|
153
|
+
<sp-overlay
|
|
154
|
+
?open=${this.open}
|
|
155
|
+
offset=${this.offset}
|
|
156
|
+
.placement=${this.placement}
|
|
157
|
+
type="hint"
|
|
158
|
+
.tipPadding=${this.tipPadding}
|
|
159
|
+
.triggerElement=${this.triggerElement}
|
|
160
|
+
.triggerInteraction=${"hover"}
|
|
161
|
+
@sp-opened=${this.handleOpenOverlay}
|
|
162
|
+
@sp-closed=${this.handleCloseOverlay}
|
|
163
|
+
>
|
|
164
|
+
${tooltip}
|
|
165
|
+
</sp-overlay>
|
|
166
|
+
`;
|
|
167
|
+
} else {
|
|
168
|
+
return tooltip;
|
|
215
169
|
}
|
|
216
170
|
}
|
|
217
|
-
}
|
|
218
|
-
export let Tooltip = _Tooltip;
|
|
219
|
-
/**
|
|
220
|
-
* @private
|
|
221
|
-
*/
|
|
222
|
-
Tooltip.instanceCount = 0;
|
|
171
|
+
}
|
|
223
172
|
__decorateClass([
|
|
224
173
|
property({ type: Boolean, attribute: "self-managed" })
|
|
225
174
|
], Tooltip.prototype, "selfManaged", 2);
|
|
226
175
|
__decorateClass([
|
|
227
|
-
property({ type: Number
|
|
176
|
+
property({ type: Number })
|
|
228
177
|
], Tooltip.prototype, "offset", 2);
|
|
229
178
|
__decorateClass([
|
|
230
179
|
property({ type: Boolean, reflect: true })
|
|
@@ -235,6 +184,9 @@ __decorateClass([
|
|
|
235
184
|
__decorateClass([
|
|
236
185
|
query("#tip")
|
|
237
186
|
], Tooltip.prototype, "tipElement", 2);
|
|
187
|
+
__decorateClass([
|
|
188
|
+
property({ type: Number })
|
|
189
|
+
], Tooltip.prototype, "tipPadding", 2);
|
|
238
190
|
__decorateClass([
|
|
239
191
|
property({ type: String })
|
|
240
192
|
], Tooltip.prototype, "variant", 1);
|
package/src/Tooltip.dev.js.map
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["Tooltip.ts"],
|
|
4
|
-
"sourcesContent": ["/*\nCopyright 2020 Adobe. All rights reserved.\nThis file is licensed to you under the Apache License, Version 2.0 (the \"License\");\nyou may not use this file except in compliance with the License. You may obtain a copy\nof the License at http://www.apache.org/licenses/LICENSE-2.0\n\nUnless required by applicable law or agreed to in writing, software distributed under\nthe License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\nOF ANY KIND, either express or implied. See the License for the specific language\ngoverning permissions and limitations under the License.\n*/\n\nimport {\n CSSResultArray,\n html,\n
|
|
5
|
-
"mappings": ";;;;;;;;;;;;AAYA;AAAA,EAEI;AAAA,
|
|
6
|
-
"names": [
|
|
4
|
+
"sourcesContent": ["/*\nCopyright 2020 Adobe. All rights reserved.\nThis file is licensed to you under the Apache License, Version 2.0 (the \"License\");\nyou may not use this file except in compliance with the License. You may obtain a copy\nof the License at http://www.apache.org/licenses/LICENSE-2.0\n\nUnless required by applicable law or agreed to in writing, software distributed under\nthe License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\nOF ANY KIND, either express or implied. See the License for the specific language\ngoverning permissions and limitations under the License.\n*/\n\nimport {\n CSSResultArray,\n html,\n SpectrumElement,\n TemplateResult,\n} from '@spectrum-web-components/base';\nimport {\n property,\n query,\n} from '@spectrum-web-components/base/src/decorators.js';\nimport type { Placement } from '@spectrum-web-components/overlay';\nimport '@spectrum-web-components/overlay/sp-overlay.js';\n\nimport tooltipStyles from './tooltip.css.js';\nimport { ifDefined } from 'lit/directives/if-defined.js';\nimport { focusableSelector } from '@spectrum-web-components/shared/src/focusable-selectors.js';\n\nclass TooltipOpenable extends HTMLElement {\n static get observedAttributes(): string[] {\n return ['open', 'placement'];\n }\n attributeChangedCallback(\n name: 'open' | 'placement',\n _oldValue: string,\n newValue: 'string'\n ): void {\n switch (name) {\n // API generally sets `open` as a property\n /* c8 ignore next 3 */\n case 'open':\n this.open = newValue !== null;\n break;\n case 'placement':\n this.placement = newValue as Placement;\n break;\n }\n }\n set open(open: boolean) {\n this._open = open;\n const tooltip = (this.getRootNode() as ShadowRoot).host as Tooltip;\n if (tooltip) {\n tooltip.open = open;\n }\n }\n get open(): boolean {\n return this._open;\n }\n private _open = false;\n /**\n * @type {\"auto\" | \"auto-start\" | \"auto-end\" | \"top\" | \"bottom\" | \"right\" | \"left\" | \"top-start\" | \"top-end\" | \"bottom-start\" | \"bottom-end\" | \"right-start\" | \"right-end\" | \"left-start\" | \"left-end\"}\n * @attr\n */\n set placement(placement: Placement) {\n this._placement = placement;\n const tooltip = (this.getRootNode() as ShadowRoot).host as Tooltip;\n if (tooltip) {\n tooltip.placement = placement;\n }\n }\n get placement(): Placement {\n return this._placement;\n }\n private _placement: Placement = 'top';\n get tipElement(): HTMLElement {\n const tooltip = (this.getRootNode() as ShadowRoot).host as Tooltip;\n return tooltip.tipElement;\n }\n}\n\nif (!customElements.get('sp-tooltip-openable')) {\n customElements.define('sp-tooltip-openable', TooltipOpenable);\n}\n\n/**\n * @element sp-tooltip\n *\n * @slot icon - the icon element appearing at the start of the label\n * @slot - the text label of the Tooltip\n */\nexport class Tooltip extends SpectrumElement {\n public static override get styles(): CSSResultArray {\n return [tooltipStyles];\n }\n\n /**\n * Automatically bind to the parent element of the assigned `slot` or the parent element of the `sp-tooltip`.\n * Without this, you must provide your own `overlay-trigger`.\n */\n @property({ type: Boolean, attribute: 'self-managed' })\n public selfManaged = false;\n\n @property({ type: Number })\n public offset = 0;\n\n @property({ type: Boolean, reflect: true })\n public open = false;\n\n /**\n * @type {\"auto\" | \"auto-start\" | \"auto-end\" | \"top\" | \"bottom\" | \"right\" | \"left\" | \"top-start\" | \"top-end\" | \"bottom-start\" | \"bottom-end\" | \"right-start\" | \"right-end\" | \"left-start\" | \"left-end\"}\n * @attr\n */\n @property({ reflect: true })\n public placement?: Placement;\n\n @query('#tip')\n public tipElement!: HTMLSpanElement;\n\n @property({ type: Number })\n public tipPadding?: number;\n\n /* Ensure that a '' value for `variant` removes the attribute instead of a blank value */\n private _variant = '';\n\n @property({ type: String })\n public get variant(): string {\n return this._variant;\n }\n public set variant(variant: string) {\n if (variant === this.variant) {\n return;\n }\n if (['info', 'positive', 'negative'].includes(variant)) {\n this.setAttribute('variant', variant);\n this._variant = variant;\n return;\n }\n this.removeAttribute('variant');\n this._variant = '';\n }\n\n private handleOpenOverlay = (): void => {\n this.open = true;\n };\n\n protected handleCloseOverlay = (): void => {\n this.open = false;\n };\n\n protected handleTransitionrun(event: TransitionEvent): void {\n this.dispatchEvent(\n new TransitionEvent('transitionrun', {\n bubbles: true,\n composed: true,\n propertyName: event.propertyName,\n })\n );\n }\n\n protected handleTransitionend(event: TransitionEvent): void {\n this.dispatchEvent(\n new TransitionEvent('transitionend', {\n bubbles: true,\n composed: true,\n propertyName: event.propertyName,\n })\n );\n }\n\n private get triggerElement(): HTMLElement {\n // Resolve the parent element of the assigned slot (if one exists) or of the Tooltip.\n let start: HTMLElement = this.assignedSlot || this;\n let root = start.getRootNode();\n let triggerElement = (start.parentElement ||\n (root as ShadowRoot).host ||\n root) as HTMLElement;\n while (!triggerElement?.matches(focusableSelector)) {\n start =\n triggerElement.assignedSlot || (triggerElement as HTMLElement);\n root = start.getRootNode();\n triggerElement = (start.parentElement ||\n (root as ShadowRoot).host ||\n root) as HTMLElement;\n }\n return triggerElement;\n }\n\n override render(): TemplateResult {\n const tooltip = html`\n <sp-tooltip-openable\n id=\"tooltip\"\n placement=${ifDefined(this.placement)}\n @transitionrun=${this.handleTransitionrun}\n @transitionend=${this.handleTransitionend}\n >\n <slot name=\"icon\"></slot>\n <span id=\"label\"><slot></slot></span>\n <span id=\"tip\"></span>\n </sp-tooltip-openable>\n `;\n if (this.selfManaged) {\n return html`\n <sp-overlay\n ?open=${this.open}\n offset=${this.offset}\n .placement=${this.placement}\n type=\"hint\"\n .tipPadding=${this.tipPadding}\n .triggerElement=${this.triggerElement}\n .triggerInteraction=${'hover'}\n @sp-opened=${this.handleOpenOverlay}\n @sp-closed=${this.handleCloseOverlay}\n >\n ${tooltip}\n </sp-overlay>\n `;\n } else {\n return tooltip;\n }\n }\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;AAYA;AAAA,EAEI;AAAA,EACA;AAAA,OAEG;AACP;AAAA,EACI;AAAA,EACA;AAAA,OACG;AAEP,OAAO;AAEP,OAAO,mBAAmB;AAC1B,SAAS,iBAAiB;AAC1B,SAAS,yBAAyB;AAElC,MAAM,wBAAwB,YAAY;AAAA,EAA1C;AAAA;AA8BI,SAAQ,QAAQ;AAehB,SAAQ,aAAwB;AAAA;AAAA,EA5ChC,WAAW,qBAA+B;AACtC,WAAO,CAAC,QAAQ,WAAW;AAAA,EAC/B;AAAA,EACA,yBACI,MACA,WACA,UACI;AACJ,YAAQ,MAAM;AAAA,MAGV,KAAK;AACD,aAAK,OAAO,aAAa;AACzB;AAAA,MACJ,KAAK;AACD,aAAK,YAAY;AACjB;AAAA,IACR;AAAA,EACJ;AAAA,EACA,IAAI,KAAK,MAAe;AACpB,SAAK,QAAQ;AACb,UAAM,UAAW,KAAK,YAAY,EAAiB;AACnD,QAAI,SAAS;AACT,cAAQ,OAAO;AAAA,IACnB;AAAA,EACJ;AAAA,EACA,IAAI,OAAgB;AAChB,WAAO,KAAK;AAAA,EAChB;AAAA;AAAA;AAAA;AAAA;AAAA,EAMA,IAAI,UAAU,WAAsB;AAChC,SAAK,aAAa;AA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QA6BF;AAMI;AAAA,EADV,SAAS,EAAE,MAAM,OAAO,CAAC;AAAA,GAlCjB,QAmCE;",
|
|
6
|
+
"names": []
|
|
7
7
|
}
|
package/src/Tooltip.js
CHANGED
|
@@ -1,6 +1,27 @@
|
|
|
1
|
-
"use strict";var
|
|
2
|
-
<
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
1
|
+
"use strict";var m=Object.defineProperty;var c=Object.getOwnPropertyDescriptor;var o=(a,i,e,n)=>{for(var t=n>1?void 0:n?c(i,e):i,r=a.length-1,l;r>=0;r--)(l=a[r])&&(t=(n?l(i,e,t):l(t))||t);return n&&t&&m(i,e,t),t};import{html as p,SpectrumElement as d}from"@spectrum-web-components/base";import{property as s,query as h}from"@spectrum-web-components/base/src/decorators.js";import"@spectrum-web-components/overlay/sp-overlay.js";import u from"./tooltip.css.js";import{ifDefined as b}from"lit/directives/if-defined.js";import{focusableSelector as v}from"@spectrum-web-components/shared/src/focusable-selectors.js";class g extends HTMLElement{constructor(){super(...arguments);this._open=!1;this._placement="top"}static get observedAttributes(){return["open","placement"]}attributeChangedCallback(e,n,t){switch(e){case"open":this.open=t!==null;break;case"placement":this.placement=t;break}}set open(e){this._open=e;const n=this.getRootNode().host;n&&(n.open=e)}get open(){return this._open}set placement(e){this._placement=e;const n=this.getRootNode().host;n&&(n.placement=e)}get placement(){return this._placement}get tipElement(){return this.getRootNode().host.tipElement}}customElements.get("sp-tooltip-openable")||customElements.define("sp-tooltip-openable",g);export class Tooltip extends d{constructor(){super(...arguments);this.selfManaged=!1;this.offset=0;this.open=!1;this._variant="";this.handleOpenOverlay=()=>{this.open=!0};this.handleCloseOverlay=()=>{this.open=!1}}static get styles(){return[u]}get variant(){return this._variant}set variant(e){if(e!==this.variant){if(["info","positive","negative"].includes(e)){this.setAttribute("variant",e),this._variant=e;return}this.removeAttribute("variant"),this._variant=""}}handleTransitionrun(e){this.dispatchEvent(new TransitionEvent("transitionrun",{bubbles:!0,composed:!0,propertyName:e.propertyName}))}handleTransitionend(e){this.dispatchEvent(new TransitionEvent("transitionend",{bubbles:!0,composed:!0,propertyName:e.propertyName}))}get triggerElement(){let e=this.assignedSlot||this,n=e.getRootNode(),t=e.parentElement||n.host||n;for(;!(t!=null&&t.matches(v));)e=t.assignedSlot||t,n=e.getRootNode(),t=e.parentElement||n.host||n;return t}render(){const e=p`
|
|
2
|
+
<sp-tooltip-openable
|
|
3
|
+
id="tooltip"
|
|
4
|
+
placement=${b(this.placement)}
|
|
5
|
+
@transitionrun=${this.handleTransitionrun}
|
|
6
|
+
@transitionend=${this.handleTransitionend}
|
|
7
|
+
>
|
|
8
|
+
<slot name="icon"></slot>
|
|
9
|
+
<span id="label"><slot></slot></span>
|
|
10
|
+
<span id="tip"></span>
|
|
11
|
+
</sp-tooltip-openable>
|
|
12
|
+
`;return this.selfManaged?p`
|
|
13
|
+
<sp-overlay
|
|
14
|
+
?open=${this.open}
|
|
15
|
+
offset=${this.offset}
|
|
16
|
+
.placement=${this.placement}
|
|
17
|
+
type="hint"
|
|
18
|
+
.tipPadding=${this.tipPadding}
|
|
19
|
+
.triggerElement=${this.triggerElement}
|
|
20
|
+
.triggerInteraction=${"hover"}
|
|
21
|
+
@sp-opened=${this.handleOpenOverlay}
|
|
22
|
+
@sp-closed=${this.handleCloseOverlay}
|
|
23
|
+
>
|
|
24
|
+
${e}
|
|
25
|
+
</sp-overlay>
|
|
26
|
+
`:e}}o([s({type:Boolean,attribute:"self-managed"})],Tooltip.prototype,"selfManaged",2),o([s({type:Number})],Tooltip.prototype,"offset",2),o([s({type:Boolean,reflect:!0})],Tooltip.prototype,"open",2),o([s({reflect:!0})],Tooltip.prototype,"placement",2),o([h("#tip")],Tooltip.prototype,"tipElement",2),o([s({type:Number})],Tooltip.prototype,"tipPadding",2),o([s({type:String})],Tooltip.prototype,"variant",1);
|
|
6
27
|
//# sourceMappingURL=Tooltip.js.map
|