@spectrum-web-components/tooltip 0.36.0 → 0.38.0
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/custom-elements.json +127 -167
- package/package.json +5 -4
- package/src/Tooltip.d.ts +14 -37
- package/src/Tooltip.dev.js +173 -170
- 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 +18 -18
- package/src/spectrum-tooltip.css.dev.js.map +1 -1
- package/src/spectrum-tooltip.css.js +18 -18
- package/src/spectrum-tooltip.css.js.map +1 -1
- package/src/tooltip.css.dev.js +22 -19
- package/src/tooltip.css.dev.js.map +2 -2
- package/src/tooltip.css.js +22 -19
- package/src/tooltip.css.js.map +2 -2
- package/stories/tooltip.stories.js +29 -18
- package/stories/tooltip.stories.js.map +2 -2
- package/test/benchmark/test-basic.js +4 -1
- package/test/benchmark/test-basic.js.map +2 -2
- package/test/tooltip.test.js +65 -56
- package/test/tooltip.test.js.map +2 -2
package/src/Tooltip.dev.js
CHANGED
|
@@ -18,70 +18,91 @@ import {
|
|
|
18
18
|
property,
|
|
19
19
|
query
|
|
20
20
|
} from "@spectrum-web-components/base/src/decorators.js";
|
|
21
|
-
import { defineElement } from "@spectrum-web-components/base/src/define-element.js";
|
|
22
|
-
import { openOverlay } from "@spectrum-web-components/overlay/src/loader.js";
|
|
23
21
|
import tooltipStyles from "./tooltip.css.js";
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
22
|
+
import { ifDefined } from "lit/directives/if-defined.js";
|
|
23
|
+
import { focusableSelector } from "@spectrum-web-components/shared/src/focusable-selectors.js";
|
|
24
|
+
class TooltipOpenable extends HTMLElement {
|
|
25
|
+
constructor() {
|
|
26
|
+
super();
|
|
27
|
+
this._open = false;
|
|
28
|
+
this._placement = "top";
|
|
29
|
+
this.addEventListener("sp-opened", this.redispatchEvent);
|
|
30
|
+
this.addEventListener("sp-closed", this.redispatchEvent);
|
|
31
|
+
}
|
|
32
|
+
redispatchEvent(event) {
|
|
33
|
+
event.stopPropagation();
|
|
34
|
+
this.tooltip.dispatchEvent(
|
|
35
|
+
new CustomEvent(event.type, {
|
|
36
|
+
bubbles: event.bubbles,
|
|
37
|
+
composed: event.composed,
|
|
38
|
+
detail: event.detail
|
|
39
|
+
})
|
|
40
|
+
);
|
|
41
|
+
}
|
|
42
|
+
get tooltip() {
|
|
43
|
+
return this.getRootNode().host;
|
|
44
|
+
}
|
|
45
|
+
static get observedAttributes() {
|
|
46
|
+
return ["open", "placement"];
|
|
47
|
+
}
|
|
48
|
+
attributeChangedCallback(name, _oldValue, newValue) {
|
|
49
|
+
switch (name) {
|
|
50
|
+
case "open":
|
|
51
|
+
this.open = newValue !== null;
|
|
52
|
+
break;
|
|
53
|
+
case "placement":
|
|
54
|
+
this.placement = newValue;
|
|
55
|
+
break;
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
set open(open) {
|
|
59
|
+
this._open = open;
|
|
60
|
+
const { tooltip } = this;
|
|
61
|
+
if (!tooltip) {
|
|
62
|
+
return;
|
|
63
|
+
}
|
|
64
|
+
tooltip.open = open;
|
|
65
|
+
}
|
|
66
|
+
get open() {
|
|
67
|
+
return this._open;
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* @type {"top" | "top-start" | "top-end" | "right" | "right-start" | "right-end" | "bottom" | "bottom-start" | "bottom-end" | "left" | "left-start" | "left-end"}
|
|
71
|
+
* @attr
|
|
72
|
+
*/
|
|
73
|
+
set placement(placement) {
|
|
74
|
+
this._placement = placement;
|
|
75
|
+
const { tooltip } = this;
|
|
76
|
+
if (!tooltip) {
|
|
77
|
+
return;
|
|
78
|
+
}
|
|
79
|
+
tooltip.placement = placement;
|
|
80
|
+
}
|
|
81
|
+
/* c8 ignore next 3 */
|
|
82
|
+
get placement() {
|
|
83
|
+
return this._placement;
|
|
27
84
|
}
|
|
85
|
+
get tipElement() {
|
|
86
|
+
return this.tooltip.tipElement;
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
if (!customElements.get("sp-tooltip-openable")) {
|
|
90
|
+
customElements.define("sp-tooltip-openable", TooltipOpenable);
|
|
28
91
|
}
|
|
29
|
-
|
|
30
|
-
const _Tooltip = class _Tooltip extends SpectrumElement {
|
|
92
|
+
export class Tooltip extends SpectrumElement {
|
|
31
93
|
constructor() {
|
|
32
|
-
super();
|
|
33
|
-
this._tooltipId = `sp-tooltip-describedby-helper-${_Tooltip.instanceCount++}`;
|
|
94
|
+
super(...arguments);
|
|
34
95
|
this.selfManaged = false;
|
|
35
|
-
this.offset =
|
|
36
|
-
this.hadTooltipId = false;
|
|
96
|
+
this.offset = 0;
|
|
37
97
|
this.open = false;
|
|
38
|
-
this.placement = "top";
|
|
39
98
|
/* Ensure that a '' value for `variant` removes the attribute instead of a blank value */
|
|
40
99
|
this._variant = "";
|
|
41
|
-
this.
|
|
42
|
-
|
|
100
|
+
this.handleOpenOverlay = () => {
|
|
101
|
+
this.open = true;
|
|
43
102
|
};
|
|
44
|
-
this.
|
|
45
|
-
|
|
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
|
-
}
|
|
103
|
+
this.handleCloseOverlay = () => {
|
|
104
|
+
this.open = false;
|
|
60
105
|
};
|
|
61
|
-
this.closeOverlay = async (event) => {
|
|
62
|
-
const pointerIsEnteringTooltip = event && event.type === "pointerleave" && event.relatedTarget === this;
|
|
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;
|
|
83
|
-
};
|
|
84
|
-
this.addEventListener("sp-overlay-query", this.onOverlayQuery);
|
|
85
106
|
}
|
|
86
107
|
static get styles() {
|
|
87
108
|
return [tooltipStyles];
|
|
@@ -101,141 +122,123 @@ const _Tooltip = class _Tooltip extends SpectrumElement {
|
|
|
101
122
|
this.removeAttribute("variant");
|
|
102
123
|
this._variant = "";
|
|
103
124
|
}
|
|
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
|
-
}
|
|
125
|
+
forwardTransitionEvent(event) {
|
|
126
|
+
this.dispatchEvent(
|
|
127
|
+
new TransitionEvent(event.type, {
|
|
128
|
+
bubbles: true,
|
|
129
|
+
composed: true,
|
|
130
|
+
propertyName: event.propertyName
|
|
131
|
+
})
|
|
132
|
+
);
|
|
142
133
|
}
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
} else {
|
|
159
|
-
trigger.removeAttribute("aria-describedby");
|
|
160
|
-
}
|
|
161
|
-
this.removeAttribute("aria-hidden");
|
|
162
|
-
this.removeProxy();
|
|
163
|
-
}
|
|
164
|
-
removeProxy() {
|
|
165
|
-
this._proxy.remove();
|
|
166
|
-
}
|
|
167
|
-
manageTooltip() {
|
|
168
|
-
const parentElement = this.parentElement;
|
|
169
|
-
if (this.selfManaged) {
|
|
170
|
-
if (this.slot) {
|
|
171
|
-
this.previousSlot = this.slot;
|
|
134
|
+
get triggerElement() {
|
|
135
|
+
var _a;
|
|
136
|
+
let start = this.assignedSlot || this;
|
|
137
|
+
let root = start.getRootNode();
|
|
138
|
+
if (true) {
|
|
139
|
+
if (root === document) {
|
|
140
|
+
window.__swc.warn(
|
|
141
|
+
this,
|
|
142
|
+
`Self managed <${this.localName}> elements walk up the composed tree to acquire a trigger element. No trigger element was found before the document.`,
|
|
143
|
+
"https://opensource.adobe.com/spectrum-web-components/components/tooltip#self-managed-overlays",
|
|
144
|
+
{
|
|
145
|
+
level: "high"
|
|
146
|
+
}
|
|
147
|
+
);
|
|
148
|
+
return root;
|
|
172
149
|
}
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
150
|
+
}
|
|
151
|
+
let triggerElement = start.parentElement || root.host || root;
|
|
152
|
+
while (!((_a = triggerElement == null ? void 0 : triggerElement.matches) == null ? void 0 : _a.call(triggerElement, focusableSelector))) {
|
|
153
|
+
start = triggerElement.assignedSlot || triggerElement;
|
|
154
|
+
root = start.getRootNode();
|
|
155
|
+
if (true) {
|
|
156
|
+
if (root === document) {
|
|
157
|
+
window.__swc.warn(
|
|
158
|
+
this,
|
|
159
|
+
`Self managed <${this.localName}> elements walk up the composed tree to acquire a trigger element. No trigger element was found before the document.`,
|
|
160
|
+
"https://opensource.adobe.com/spectrum-web-components/components/tooltip#self-managed-overlays",
|
|
161
|
+
{
|
|
162
|
+
level: "high"
|
|
163
|
+
}
|
|
164
|
+
);
|
|
165
|
+
return root;
|
|
166
|
+
}
|
|
183
167
|
}
|
|
184
|
-
parentElement.
|
|
185
|
-
parentElement.removeEventListener("focusin", this.openOverlay);
|
|
186
|
-
parentElement.removeEventListener(
|
|
187
|
-
"pointerleave",
|
|
188
|
-
this.closeOverlay
|
|
189
|
-
);
|
|
190
|
-
parentElement.removeEventListener("focusout", this.closeOverlay);
|
|
168
|
+
triggerElement = start.parentElement || root.host || root;
|
|
191
169
|
}
|
|
170
|
+
return triggerElement;
|
|
192
171
|
}
|
|
193
172
|
render() {
|
|
194
|
-
|
|
195
|
-
<
|
|
196
|
-
|
|
197
|
-
|
|
173
|
+
const tooltip = html`
|
|
174
|
+
<sp-tooltip-openable
|
|
175
|
+
id="tooltip"
|
|
176
|
+
placement=${ifDefined(this.placement)}
|
|
177
|
+
@transitionrun=${this.forwardTransitionEvent}
|
|
178
|
+
@transitionend=${this.forwardTransitionEvent}
|
|
179
|
+
@transitioncancel=${this.forwardTransitionEvent}
|
|
180
|
+
>
|
|
181
|
+
<slot name="icon"></slot>
|
|
182
|
+
<span id="label"><slot></slot></span>
|
|
183
|
+
<span id="tip" aria-hidden="true"></span>
|
|
184
|
+
</sp-tooltip-openable>
|
|
198
185
|
`;
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
186
|
+
if (this.selfManaged) {
|
|
187
|
+
import("@spectrum-web-components/overlay/sp-overlay.js");
|
|
188
|
+
return html`
|
|
189
|
+
<sp-overlay
|
|
190
|
+
?open=${this.open}
|
|
191
|
+
offset=${this.offset}
|
|
192
|
+
.placement=${this.placement}
|
|
193
|
+
type="hint"
|
|
194
|
+
.tipPadding=${this.tipPadding}
|
|
195
|
+
.triggerInteraction=${"hover"}
|
|
196
|
+
@sp-opened=${this.handleOpenOverlay}
|
|
197
|
+
@sp-closed=${this.handleCloseOverlay}
|
|
198
|
+
>
|
|
199
|
+
${tooltip}
|
|
200
|
+
</sp-overlay>
|
|
201
|
+
`;
|
|
202
|
+
} else {
|
|
203
|
+
return tooltip;
|
|
207
204
|
}
|
|
208
|
-
this.generateProxy();
|
|
209
|
-
super.update(changed);
|
|
210
205
|
}
|
|
211
|
-
|
|
212
|
-
super.
|
|
213
|
-
|
|
214
|
-
this.
|
|
215
|
-
|
|
206
|
+
connectedCallback() {
|
|
207
|
+
super.connectedCallback();
|
|
208
|
+
this.updateComplete.then(() => {
|
|
209
|
+
if (!this.selfManaged) {
|
|
210
|
+
return;
|
|
211
|
+
}
|
|
212
|
+
const overlayElement = this.overlayElement;
|
|
213
|
+
if (overlayElement) {
|
|
214
|
+
const triggerElement = this.triggerElement;
|
|
215
|
+
overlayElement.triggerElement = triggerElement;
|
|
216
|
+
}
|
|
217
|
+
});
|
|
216
218
|
}
|
|
217
|
-
}
|
|
218
|
-
/**
|
|
219
|
-
* @private
|
|
220
|
-
*/
|
|
221
|
-
_Tooltip.instanceCount = 0;
|
|
219
|
+
}
|
|
222
220
|
__decorateClass([
|
|
223
221
|
property({ type: Boolean, attribute: "self-managed" })
|
|
224
|
-
],
|
|
222
|
+
], Tooltip.prototype, "selfManaged", 2);
|
|
225
223
|
__decorateClass([
|
|
226
|
-
property({ type: Number
|
|
227
|
-
],
|
|
224
|
+
property({ type: Number })
|
|
225
|
+
], Tooltip.prototype, "offset", 2);
|
|
228
226
|
__decorateClass([
|
|
229
227
|
property({ type: Boolean, reflect: true })
|
|
230
|
-
],
|
|
228
|
+
], Tooltip.prototype, "open", 2);
|
|
229
|
+
__decorateClass([
|
|
230
|
+
query("sp-overlay")
|
|
231
|
+
], Tooltip.prototype, "overlayElement", 2);
|
|
231
232
|
__decorateClass([
|
|
232
233
|
property({ reflect: true })
|
|
233
|
-
],
|
|
234
|
+
], Tooltip.prototype, "placement", 2);
|
|
234
235
|
__decorateClass([
|
|
235
236
|
query("#tip")
|
|
236
|
-
],
|
|
237
|
+
], Tooltip.prototype, "tipElement", 2);
|
|
238
|
+
__decorateClass([
|
|
239
|
+
property({ type: Number })
|
|
240
|
+
], Tooltip.prototype, "tipPadding", 2);
|
|
237
241
|
__decorateClass([
|
|
238
242
|
property({ type: String })
|
|
239
|
-
],
|
|
240
|
-
export let Tooltip = _Tooltip;
|
|
243
|
+
], Tooltip.prototype, "variant", 1);
|
|
241
244
|
//# sourceMappingURL=Tooltip.dev.js.map
|
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 {\n Overlay,\n OverlayOpenCloseDetail,\n Placement,\n} from '@spectrum-web-components/overlay';\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 constructor() {\n super();\n this.addEventListener('sp-opened', this.redispatchEvent);\n this.addEventListener('sp-closed', this.redispatchEvent);\n }\n redispatchEvent(event: Event): void {\n event.stopPropagation();\n this.tooltip.dispatchEvent(\n new CustomEvent<OverlayOpenCloseDetail>(event.type, {\n bubbles: event.bubbles,\n composed: event.composed,\n detail: (event as CustomEvent<OverlayOpenCloseDetail>).detail,\n })\n );\n }\n get tooltip(): Tooltip {\n return (this.getRootNode() as ShadowRoot).host as Tooltip;\n }\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;\n /* c8 ignore next 3 */\n if (!tooltip) {\n return;\n }\n tooltip.open = open;\n }\n get open(): boolean {\n return this._open;\n }\n private _open = false;\n /**\n * @type {\"top\" | \"top-start\" | \"top-end\" | \"right\" | \"right-start\" | \"right-end\" | \"bottom\" | \"bottom-start\" | \"bottom-end\" | \"left\" | \"left-start\" | \"left-end\"}\n * @attr\n */\n set placement(placement: Placement) {\n this._placement = placement;\n const { tooltip } = this;\n if (!tooltip) {\n return;\n }\n tooltip.placement = placement;\n }\n /* c8 ignore next 3 */\n get placement(): Placement {\n return this._placement;\n }\n private _placement: Placement = 'top';\n get tipElement(): HTMLElement {\n return this.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 @query('sp-overlay')\n public overlayElement?: Overlay;\n\n /**\n * @type {\"top\" | \"top-start\" | \"top-end\" | \"right\" | \"right-start\" | \"right-end\" | \"bottom\" | \"bottom-start\" | \"bottom-end\" | \"left\" | \"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 forwardTransitionEvent(event: TransitionEvent): void {\n this.dispatchEvent(\n new TransitionEvent(event.type, {\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 if (window.__swc.DEBUG) {\n if (root === document) {\n window.__swc.warn(\n this,\n `Self managed <${this.localName}> elements walk up the composed tree to acquire a trigger element. No trigger element was found before the document.`,\n 'https://opensource.adobe.com/spectrum-web-components/components/tooltip#self-managed-overlays',\n {\n level: 'high',\n }\n );\n return root as HTMLElement;\n }\n }\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 /* c8 ignore next 13 */\n if (window.__swc.DEBUG) {\n if (root === document) {\n window.__swc.warn(\n this,\n `Self managed <${this.localName}> elements walk up the composed tree to acquire a trigger element. No trigger element was found before the document.`,\n 'https://opensource.adobe.com/spectrum-web-components/components/tooltip#self-managed-overlays',\n {\n level: 'high',\n }\n );\n return root as HTMLElement;\n }\n }\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.forwardTransitionEvent}\n @transitionend=${this.forwardTransitionEvent}\n @transitioncancel=${this.forwardTransitionEvent}\n >\n <slot name=\"icon\"></slot>\n <span id=\"label\"><slot></slot></span>\n <span id=\"tip\" aria-hidden=\"true\"></span>\n </sp-tooltip-openable>\n `;\n if (this.selfManaged) {\n import('@spectrum-web-components/overlay/sp-overlay.js');\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 .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 public override connectedCallback(): void {\n super.connectedCallback();\n\n this.updateComplete.then(() => {\n if (!this.selfManaged) {\n return;\n }\n const overlayElement = this.overlayElement;\n if (overlayElement) {\n const triggerElement = this.triggerElement;\n overlayElement.triggerElement = triggerElement;\n }\n });\n }\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;AAYA;AAAA,EAEI;AAAA,EACA;AAAA,OAEG;AACP;AAAA,EACI;AAAA,EACA;AAAA,OACG;AAOP,OAAO,mBAAmB;AAC1B,SAAS,iBAAiB;AAC1B,SAAS,yBAAyB;AAElC,MAAM,wBAAwB,YAAY;AAAA,EACtC,cAAc;AACV,UAAM;AAgDV,SAAQ,QAAQ;AAiBhB,SAAQ,aAAwB;AAhE5B,SAAK,iBAAiB,aAAa,KAAK,eAAe;AACvD,SAAK,iBAAiB,aAAa,KAAK,e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AgBF;AAGA;AAAA,EADN,MAAM,YAAY;AAAA,GAlBV,QAmBF;AAOA;AAAA,EADN,SAAS,EAAE,SAAS,KAAK,CAAC;AAAA,GAzBlB,QA0BF;AAGA;AAAA,EADN,MAAM,MAAM;AAAA,GA5BJ,QA6BF;AAGA;AAAA,EADN,SAAS,EAAE,MAAM,OAAO,CAAC;AAAA,GA/BjB,QAgCF;AAMI;AAAA,EADV,SAAS,EAAE,MAAM,OAAO,CAAC;AAAA,GArCjB,QAsCE;",
|
|
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 c=Object.defineProperty;var d=Object.getOwnPropertyDescriptor;var o=(r,s,e,n)=>{for(var t=n>1?void 0:n?d(s,e):s,i=r.length-1,l;i>=0;i--)(l=r[i])&&(t=(n?l(s,e,t):l(t))||t);return n&&t&&c(s,e,t),t};import{html as p,SpectrumElement as h}from"@spectrum-web-components/base";import{property as a,query as m}from"@spectrum-web-components/base/src/decorators.js";import u from"./tooltip.css.js";import{ifDefined as v}from"lit/directives/if-defined.js";import{focusableSelector as f}from"@spectrum-web-components/shared/src/focusable-selectors.js";class b extends HTMLElement{constructor(){super();this._open=!1;this._placement="top";this.addEventListener("sp-opened",this.redispatchEvent),this.addEventListener("sp-closed",this.redispatchEvent)}redispatchEvent(e){e.stopPropagation(),this.tooltip.dispatchEvent(new CustomEvent(e.type,{bubbles:e.bubbles,composed:e.composed,detail:e.detail}))}get tooltip(){return this.getRootNode().host}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{tooltip:n}=this;n&&(n.open=e)}get open(){return this._open}set placement(e){this._placement=e;const{tooltip:n}=this;n&&(n.placement=e)}get placement(){return this._placement}get tipElement(){return this.tooltip.tipElement}}customElements.get("sp-tooltip-openable")||customElements.define("sp-tooltip-openable",b);export class Tooltip extends h{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=""}}forwardTransitionEvent(e){this.dispatchEvent(new TransitionEvent(e.type,{bubbles:!0,composed:!0,propertyName:e.propertyName}))}get triggerElement(){var i;let e=this.assignedSlot||this,n=e.getRootNode(),t=e.parentElement||n.host||n;for(;!((i=t==null?void 0:t.matches)!=null&&i.call(t,f));)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=${v(this.placement)}
|
|
5
|
+
@transitionrun=${this.forwardTransitionEvent}
|
|
6
|
+
@transitionend=${this.forwardTransitionEvent}
|
|
7
|
+
@transitioncancel=${this.forwardTransitionEvent}
|
|
8
|
+
>
|
|
9
|
+
<slot name="icon"></slot>
|
|
10
|
+
<span id="label"><slot></slot></span>
|
|
11
|
+
<span id="tip" aria-hidden="true"></span>
|
|
12
|
+
</sp-tooltip-openable>
|
|
13
|
+
`;return this.selfManaged?(import("@spectrum-web-components/overlay/sp-overlay.js"),p`
|
|
14
|
+
<sp-overlay
|
|
15
|
+
?open=${this.open}
|
|
16
|
+
offset=${this.offset}
|
|
17
|
+
.placement=${this.placement}
|
|
18
|
+
type="hint"
|
|
19
|
+
.tipPadding=${this.tipPadding}
|
|
20
|
+
.triggerInteraction=${"hover"}
|
|
21
|
+
@sp-opened=${this.handleOpenOverlay}
|
|
22
|
+
@sp-closed=${this.handleCloseOverlay}
|
|
23
|
+
>
|
|
24
|
+
${e}
|
|
25
|
+
</sp-overlay>
|
|
26
|
+
`):e}connectedCallback(){super.connectedCallback(),this.updateComplete.then(()=>{if(!this.selfManaged)return;const e=this.overlayElement;if(e){const n=this.triggerElement;e.triggerElement=n}})}}o([a({type:Boolean,attribute:"self-managed"})],Tooltip.prototype,"selfManaged",2),o([a({type:Number})],Tooltip.prototype,"offset",2),o([a({type:Boolean,reflect:!0})],Tooltip.prototype,"open",2),o([m("sp-overlay")],Tooltip.prototype,"overlayElement",2),o([a({reflect:!0})],Tooltip.prototype,"placement",2),o([m("#tip")],Tooltip.prototype,"tipElement",2),o([a({type:Number})],Tooltip.prototype,"tipPadding",2),o([a({type:String})],Tooltip.prototype,"variant",1);
|
|
6
27
|
//# sourceMappingURL=Tooltip.js.map
|