@spectrum-web-components/tooltip 0.0.0-20241209155954
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 +133 -0
- package/package.json +79 -0
- package/sp-tooltip.d.ts +6 -0
- package/sp-tooltip.dev.js +5 -0
- package/sp-tooltip.dev.js.map +7 -0
- package/sp-tooltip.js +2 -0
- package/sp-tooltip.js.map +7 -0
- package/src/Tooltip.d.ts +48 -0
- package/src/Tooltip.dev.js +259 -0
- package/src/Tooltip.dev.js.map +7 -0
- package/src/Tooltip.js +29 -0
- package/src/Tooltip.js.map +7 -0
- package/src/index.d.ts +1 -0
- package/src/index.dev.js +3 -0
- package/src/index.dev.js.map +7 -0
- package/src/index.js +2 -0
- package/src/index.js.map +7 -0
- package/src/spectrum-config.js +168 -0
- package/src/spectrum-tooltip.css.d.ts +2 -0
- package/src/spectrum-tooltip.css.dev.js +7 -0
- package/src/spectrum-tooltip.css.dev.js.map +7 -0
- package/src/spectrum-tooltip.css.js +4 -0
- package/src/spectrum-tooltip.css.js.map +7 -0
- package/src/tooltip-directive.d.ts +5 -0
- package/src/tooltip-directive.dev.js +27 -0
- package/src/tooltip-directive.dev.js.map +7 -0
- package/src/tooltip-directive.js +6 -0
- package/src/tooltip-directive.js.map +7 -0
- package/src/tooltip-overrides.css.d.ts +2 -0
- package/src/tooltip-overrides.css.dev.js +7 -0
- package/src/tooltip-overrides.css.dev.js.map +7 -0
- package/src/tooltip-overrides.css.js +4 -0
- package/src/tooltip-overrides.css.js.map +7 -0
- package/src/tooltip.css.d.ts +2 -0
- package/src/tooltip.css.dev.js +7 -0
- package/src/tooltip.css.dev.js.map +7 -0
- package/src/tooltip.css.js +4 -0
- package/src/tooltip.css.js.map +7 -0
package/README.md
ADDED
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
## Description
|
|
2
|
+
|
|
3
|
+
`sp-tooltip` allow users to get contextual help or information about specific components when hovering or focusing on them.
|
|
4
|
+
|
|
5
|
+
### Usage
|
|
6
|
+
|
|
7
|
+
[](https://www.npmjs.com/package/@spectrum-web-components/tooltip)
|
|
8
|
+
[](https://bundlephobia.com/result?p=@spectrum-web-components/tooltip)
|
|
9
|
+
[](https://webcomponents.dev/edit/collection/fO75441E1Q5ZlI0e9pgq/VmbuRedDUMmN4amLK7ie/src/index.ts)
|
|
10
|
+
|
|
11
|
+
```
|
|
12
|
+
yarn add @spectrum-web-components/tooltip
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
Import the side effectful registration of `<sp-tooltip>` via:
|
|
16
|
+
|
|
17
|
+
```
|
|
18
|
+
import '@spectrum-web-components/tooltip/sp-tooltip.js';
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
When looking to leverage the `Tooltip` base class as a type and/or for extension purposes, do so via:
|
|
22
|
+
|
|
23
|
+
```
|
|
24
|
+
import { Tooltip } from '@spectrum-web-components/tooltip';
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
## Example
|
|
28
|
+
|
|
29
|
+
Tooltips can be top, bottom, left, or right.
|
|
30
|
+
|
|
31
|
+
```html
|
|
32
|
+
<sp-tooltip open placement="top">Label</sp-tooltip>
|
|
33
|
+
<br />
|
|
34
|
+
<br />
|
|
35
|
+
<sp-tooltip open placement="bottom">Label</sp-tooltip>
|
|
36
|
+
<br />
|
|
37
|
+
<br />
|
|
38
|
+
<sp-tooltip open placement="left">Label</sp-tooltip>
|
|
39
|
+
<br />
|
|
40
|
+
<br />
|
|
41
|
+
<sp-tooltip open placement="right">Label</sp-tooltip>
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
### Self-managed overlays
|
|
45
|
+
|
|
46
|
+
By default, Tooltip provides styling without behavior.
|
|
47
|
+
You must combine it with an [Overlay Trigger](https://opensource.adobe.com/spectrum-web-components/components/overlay-trigger/#%22hover%22-content-only) in order to manage its overlay behavior.
|
|
48
|
+
|
|
49
|
+
You can use the tooltip as the descendant of an interactive element, such as [Action Button](https://opensource.adobe.com/spectrum-web-components/components/action-button/), by applying the `self-managed` attribute which automatically binds the Tooltip to its first interactive ancestor element's focus/hover interactions:
|
|
50
|
+
|
|
51
|
+
```html
|
|
52
|
+
<sp-action-button>
|
|
53
|
+
Trigger
|
|
54
|
+
<sp-tooltip self-managed>Content</sp-tooltip>
|
|
55
|
+
</sp-action-button>
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
This is especially useful when inserting an intermediate `<overlay-trigger>` would interfere with
|
|
59
|
+
parent/child relationships, such as between `<sp-action-group>` and `<sp-action-button>`.
|
|
60
|
+
|
|
61
|
+
Note that an interactive element is an element that can receive focus during tab navigation, such as `sp-action-button`, `sp-action-menu`, `sp-field-label` etc.
|
|
62
|
+
|
|
63
|
+
Given that tooltip is not focusable by itself, it would not show up during tab navigation. Thus a tooltip would not be accessible if used with a non-interactive element, such as `<sp-icon-*>`.
|
|
64
|
+
|
|
65
|
+
The correct way to make it accessible would be to wrap it under an interactive element, such as `sp-action-button`:
|
|
66
|
+
|
|
67
|
+
```html
|
|
68
|
+
<sp-action-button size="s">
|
|
69
|
+
<sp-icon-info slot="icon"></sp-icon-info>
|
|
70
|
+
<sp-tooltip self-managed placement="right">
|
|
71
|
+
Display something here
|
|
72
|
+
</sp-tooltip>
|
|
73
|
+
</sp-action-button>
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
## Variants
|
|
77
|
+
|
|
78
|
+
### Informative
|
|
79
|
+
|
|
80
|
+
This is the informative or info variant of Tooltip
|
|
81
|
+
|
|
82
|
+
```html
|
|
83
|
+
<sp-tooltip open placement="top" variant="info">Label</sp-tooltip>
|
|
84
|
+
<sp-tooltip open placement="top" variant="info">
|
|
85
|
+
Lorem ipsum dolor sit amet, consectetur adipiscing elit
|
|
86
|
+
</sp-tooltip>
|
|
87
|
+
<sp-tooltip open placement="top" variant="info">
|
|
88
|
+
<sp-icon-info slot="icon" size="s"></sp-icon-info>
|
|
89
|
+
Label
|
|
90
|
+
</sp-tooltip>
|
|
91
|
+
<sp-tooltip open placement="top" variant="info">
|
|
92
|
+
<sp-icon-info slot="icon" size="s"></sp-icon-info>
|
|
93
|
+
Lorem ipsum dolor sit amet, consectetur adipiscing elit
|
|
94
|
+
</sp-tooltip>
|
|
95
|
+
```
|
|
96
|
+
|
|
97
|
+
### Positive
|
|
98
|
+
|
|
99
|
+
This is the postive (a.k.a.) success variant of Tooltip
|
|
100
|
+
|
|
101
|
+
```html
|
|
102
|
+
<sp-tooltip open placement="top" variant="positive">Label</sp-tooltip>
|
|
103
|
+
<sp-tooltip open placement="top" variant="positive">
|
|
104
|
+
Lorem ipsum dolor sit amet, consectetur adipiscing elit
|
|
105
|
+
</sp-tooltip>
|
|
106
|
+
<sp-tooltip open placement="top" variant="positive">
|
|
107
|
+
<sp-icon-checkmark-circle slot="icon" size="s"></sp-icon-checkmark-circle>
|
|
108
|
+
Label
|
|
109
|
+
</sp-tooltip>
|
|
110
|
+
<sp-tooltip open placement="top" variant="positive">
|
|
111
|
+
<sp-icon-checkmark-circle slot="icon" size="s"></sp-icon-checkmark-circle>
|
|
112
|
+
Lorem ipsum dolor sit amet, consectetur adipiscing elit
|
|
113
|
+
</sp-tooltip>
|
|
114
|
+
```
|
|
115
|
+
|
|
116
|
+
### Negative
|
|
117
|
+
|
|
118
|
+
This is the negative a.k.a. error variant of Tooltip
|
|
119
|
+
|
|
120
|
+
```html
|
|
121
|
+
<sp-tooltip open placement="top" variant="negative">Label</sp-tooltip>
|
|
122
|
+
<sp-tooltip open placement="top" variant="negative">
|
|
123
|
+
Lorem ipsum dolor sit amet, consectetur adipiscing elit
|
|
124
|
+
</sp-tooltip>
|
|
125
|
+
<sp-tooltip open placement="top" variant="negative">
|
|
126
|
+
<sp-icon-alert slot="icon" size="s"></sp-icon-alert>
|
|
127
|
+
Label
|
|
128
|
+
</sp-tooltip>
|
|
129
|
+
<sp-tooltip open placement="top" variant="negative">
|
|
130
|
+
<sp-icon-alert slot="icon" size="s"></sp-icon-alert>
|
|
131
|
+
Lorem ipsum dolor sit amet, consectetur adipiscing elit
|
|
132
|
+
</sp-tooltip>
|
|
133
|
+
```
|
package/package.json
ADDED
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@spectrum-web-components/tooltip",
|
|
3
|
+
"version": "0.0.0-20241209155954",
|
|
4
|
+
"publishConfig": {
|
|
5
|
+
"access": "public"
|
|
6
|
+
},
|
|
7
|
+
"description": "",
|
|
8
|
+
"license": "Apache-2.0",
|
|
9
|
+
"repository": {
|
|
10
|
+
"type": "git",
|
|
11
|
+
"url": "https://github.com/adobe/spectrum-web-components.git",
|
|
12
|
+
"directory": "packages/tooltip"
|
|
13
|
+
},
|
|
14
|
+
"author": "",
|
|
15
|
+
"homepage": "https://opensource.adobe.com/spectrum-web-components/components/tooltip",
|
|
16
|
+
"bugs": {
|
|
17
|
+
"url": "https://github.com/adobe/spectrum-web-components/issues"
|
|
18
|
+
},
|
|
19
|
+
"main": "./src/index.js",
|
|
20
|
+
"module": "./src/index.js",
|
|
21
|
+
"type": "module",
|
|
22
|
+
"exports": {
|
|
23
|
+
".": {
|
|
24
|
+
"development": "./src/index.dev.js",
|
|
25
|
+
"default": "./src/index.js"
|
|
26
|
+
},
|
|
27
|
+
"./package.json": "./package.json",
|
|
28
|
+
"./src/Tooltip.js": {
|
|
29
|
+
"development": "./src/Tooltip.dev.js",
|
|
30
|
+
"default": "./src/Tooltip.js"
|
|
31
|
+
},
|
|
32
|
+
"./src/index.js": {
|
|
33
|
+
"development": "./src/index.dev.js",
|
|
34
|
+
"default": "./src/index.js"
|
|
35
|
+
},
|
|
36
|
+
"./src/tooltip-directive.js": {
|
|
37
|
+
"development": "./src/tooltip-directive.dev.js",
|
|
38
|
+
"default": "./src/tooltip-directive.js"
|
|
39
|
+
},
|
|
40
|
+
"./src/tooltip-overrides.css.js": "./src/tooltip-overrides.css.js",
|
|
41
|
+
"./src/tooltip.css.js": "./src/tooltip.css.js",
|
|
42
|
+
"./sp-tooltip.js": {
|
|
43
|
+
"development": "./sp-tooltip.dev.js",
|
|
44
|
+
"default": "./sp-tooltip.js"
|
|
45
|
+
}
|
|
46
|
+
},
|
|
47
|
+
"scripts": {
|
|
48
|
+
"test": "echo \"Error: run tests from mono-repo root.\" && exit 1"
|
|
49
|
+
},
|
|
50
|
+
"files": [
|
|
51
|
+
"**/*.d.ts",
|
|
52
|
+
"**/*.js",
|
|
53
|
+
"**/*.js.map",
|
|
54
|
+
"custom-elements.json",
|
|
55
|
+
"!stories/",
|
|
56
|
+
"!test/"
|
|
57
|
+
],
|
|
58
|
+
"keywords": [
|
|
59
|
+
"spectrum css",
|
|
60
|
+
"web components",
|
|
61
|
+
"lit-element",
|
|
62
|
+
"lit-html"
|
|
63
|
+
],
|
|
64
|
+
"dependencies": {
|
|
65
|
+
"@spectrum-web-components/base": "0.0.0-20241209155954",
|
|
66
|
+
"@spectrum-web-components/overlay": "0.0.0-20241209155954",
|
|
67
|
+
"@spectrum-web-components/reactive-controllers": "0.0.0-20241209155954",
|
|
68
|
+
"@spectrum-web-components/shared": "0.0.0-20241209155954"
|
|
69
|
+
},
|
|
70
|
+
"devDependencies": {
|
|
71
|
+
"@spectrum-css/tooltip": "^7.0.0-s2-foundations.15"
|
|
72
|
+
},
|
|
73
|
+
"types": "./src/index.d.ts",
|
|
74
|
+
"customElements": "custom-elements.json",
|
|
75
|
+
"sideEffects": [
|
|
76
|
+
"./sp-*.js",
|
|
77
|
+
"./**/*.dev.js"
|
|
78
|
+
]
|
|
79
|
+
}
|
package/sp-tooltip.d.ts
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["sp-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*/\nimport { Tooltip } from './src/Tooltip.dev.js'\nimport { defineElement } from '@spectrum-web-components/base/src/define-element.js';\n\ndefineElement('sp-tooltip', Tooltip);\n\ndeclare global {\n interface HTMLElementTagNameMap {\n 'sp-tooltip': Tooltip;\n }\n}\n"],
|
|
5
|
+
"mappings": ";AAWA,SAAS,eAAe;AACxB,SAAS,qBAAqB;AAE9B,cAAc,cAAc,OAAO;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
package/sp-tooltip.js
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["sp-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*/\nimport { Tooltip } from './src/Tooltip.js';\nimport { defineElement } from '@spectrum-web-components/base/src/define-element.js';\n\ndefineElement('sp-tooltip', Tooltip);\n\ndeclare global {\n interface HTMLElementTagNameMap {\n 'sp-tooltip': Tooltip;\n }\n}\n"],
|
|
5
|
+
"mappings": "aAWA,OAAS,WAAAA,MAAe,mBACxB,OAAS,iBAAAC,MAAqB,sDAE9BA,EAAc,aAAcD,CAAO",
|
|
6
|
+
"names": ["Tooltip", "defineElement"]
|
|
7
|
+
}
|
package/src/Tooltip.d.ts
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { CSSResultArray, SpectrumElement, TemplateResult } from '@spectrum-web-components/base';
|
|
2
|
+
import type { Overlay, Placement } from '@spectrum-web-components/overlay';
|
|
3
|
+
/**
|
|
4
|
+
* @element sp-tooltip
|
|
5
|
+
*
|
|
6
|
+
* @slot icon - the icon element appearing at the start of the label
|
|
7
|
+
* @slot - the text label of the Tooltip
|
|
8
|
+
*/
|
|
9
|
+
export declare class Tooltip extends SpectrumElement {
|
|
10
|
+
static get styles(): CSSResultArray;
|
|
11
|
+
/**
|
|
12
|
+
* A Tooltip that is `delayed` will its Overlay wait until a warm-up period of
|
|
13
|
+
* 1000ms has completed before opening. Once the warmup period has completed, all
|
|
14
|
+
* subsequent Overlays will open immediately. When no Overlays are opened, a
|
|
15
|
+
* cooldown period of 1000ms will begin. Once the cooldown has completed, the next
|
|
16
|
+
* Overlay to be opened will be subject to the warm-up period if provided that option.
|
|
17
|
+
*/
|
|
18
|
+
delayed: boolean;
|
|
19
|
+
private dependencyManager;
|
|
20
|
+
/**
|
|
21
|
+
* Whether to prevent a self-managed Tooltip from responding to user input.
|
|
22
|
+
*/
|
|
23
|
+
disabled: boolean;
|
|
24
|
+
/**
|
|
25
|
+
* Automatically bind to the parent element of the assigned `slot` or the parent element of the `sp-tooltip`.
|
|
26
|
+
* Without this, you must provide your own `overlay-trigger`.
|
|
27
|
+
*/
|
|
28
|
+
selfManaged: boolean;
|
|
29
|
+
offset: number;
|
|
30
|
+
open: boolean;
|
|
31
|
+
overlayElement?: Overlay;
|
|
32
|
+
/**
|
|
33
|
+
* @type {"top" | "top-start" | "top-end" | "right" | "right-start" | "right-end" | "bottom" | "bottom-start" | "bottom-end" | "left" | "left-start" | "left-end"}
|
|
34
|
+
* @attr
|
|
35
|
+
*/
|
|
36
|
+
placement?: Placement;
|
|
37
|
+
tipElement: HTMLSpanElement;
|
|
38
|
+
tipPadding?: number;
|
|
39
|
+
private _variant;
|
|
40
|
+
get variant(): string;
|
|
41
|
+
set variant(variant: string);
|
|
42
|
+
private handleOpenOverlay;
|
|
43
|
+
protected handleCloseOverlay: () => void;
|
|
44
|
+
protected forwardTransitionEvent(event: TransitionEvent): void;
|
|
45
|
+
private get triggerElement();
|
|
46
|
+
render(): TemplateResult;
|
|
47
|
+
connectedCallback(): void;
|
|
48
|
+
}
|
|
@@ -0,0 +1,259 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __decorateClass = (decorators, target, key, kind) => {
|
|
5
|
+
var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc(target, key) : target;
|
|
6
|
+
for (var i = decorators.length - 1, decorator; i >= 0; i--)
|
|
7
|
+
if (decorator = decorators[i])
|
|
8
|
+
result = (kind ? decorator(target, key, result) : decorator(result)) || result;
|
|
9
|
+
if (kind && result) __defProp(target, key, result);
|
|
10
|
+
return result;
|
|
11
|
+
};
|
|
12
|
+
import {
|
|
13
|
+
html,
|
|
14
|
+
SpectrumElement
|
|
15
|
+
} from "@spectrum-web-components/base";
|
|
16
|
+
import {
|
|
17
|
+
property,
|
|
18
|
+
query
|
|
19
|
+
} from "@spectrum-web-components/base/src/decorators.js";
|
|
20
|
+
import { ifDefined } from "@spectrum-web-components/base/src/directives.js";
|
|
21
|
+
import tooltipStyles from "./tooltip.css.js";
|
|
22
|
+
import { focusableSelector } from "@spectrum-web-components/shared/src/focusable-selectors.js";
|
|
23
|
+
import { DependencyManagerController } from "@spectrum-web-components/reactive-controllers/src/DependencyManger.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
|
+
/* c8 ignore next 3 */
|
|
67
|
+
get open() {
|
|
68
|
+
return this._open;
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* @type {"top" | "top-start" | "top-end" | "right" | "right-start" | "right-end" | "bottom" | "bottom-start" | "bottom-end" | "left" | "left-start" | "left-end"}
|
|
72
|
+
* @attr
|
|
73
|
+
*/
|
|
74
|
+
set placement(placement) {
|
|
75
|
+
this._placement = placement;
|
|
76
|
+
const { tooltip } = this;
|
|
77
|
+
if (!tooltip) {
|
|
78
|
+
return;
|
|
79
|
+
}
|
|
80
|
+
tooltip.placement = placement;
|
|
81
|
+
}
|
|
82
|
+
/* c8 ignore next 3 */
|
|
83
|
+
get placement() {
|
|
84
|
+
return this._placement;
|
|
85
|
+
}
|
|
86
|
+
get tipElement() {
|
|
87
|
+
return this.tooltip.tipElement;
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
if (!customElements.get("sp-tooltip-openable")) {
|
|
91
|
+
customElements.define("sp-tooltip-openable", TooltipOpenable);
|
|
92
|
+
}
|
|
93
|
+
export class Tooltip extends SpectrumElement {
|
|
94
|
+
constructor() {
|
|
95
|
+
super(...arguments);
|
|
96
|
+
this.delayed = false;
|
|
97
|
+
this.dependencyManager = new DependencyManagerController(this);
|
|
98
|
+
this.disabled = false;
|
|
99
|
+
this.selfManaged = false;
|
|
100
|
+
this.offset = 0;
|
|
101
|
+
this.open = false;
|
|
102
|
+
/* Ensure that a '' value for `variant` removes the attribute instead of a blank value */
|
|
103
|
+
this._variant = "";
|
|
104
|
+
this.handleOpenOverlay = () => {
|
|
105
|
+
this.open = true;
|
|
106
|
+
};
|
|
107
|
+
this.handleCloseOverlay = () => {
|
|
108
|
+
this.open = false;
|
|
109
|
+
};
|
|
110
|
+
}
|
|
111
|
+
static get styles() {
|
|
112
|
+
return [tooltipStyles];
|
|
113
|
+
}
|
|
114
|
+
get variant() {
|
|
115
|
+
return this._variant;
|
|
116
|
+
}
|
|
117
|
+
set variant(variant) {
|
|
118
|
+
if (variant === this.variant) {
|
|
119
|
+
return;
|
|
120
|
+
}
|
|
121
|
+
if (["info", "positive", "negative"].includes(variant)) {
|
|
122
|
+
this.setAttribute("variant", variant);
|
|
123
|
+
this._variant = variant;
|
|
124
|
+
return;
|
|
125
|
+
}
|
|
126
|
+
this.removeAttribute("variant");
|
|
127
|
+
this._variant = "";
|
|
128
|
+
}
|
|
129
|
+
forwardTransitionEvent(event) {
|
|
130
|
+
this.dispatchEvent(
|
|
131
|
+
new TransitionEvent(event.type, {
|
|
132
|
+
bubbles: true,
|
|
133
|
+
composed: true,
|
|
134
|
+
propertyName: event.propertyName
|
|
135
|
+
})
|
|
136
|
+
);
|
|
137
|
+
}
|
|
138
|
+
get triggerElement() {
|
|
139
|
+
var _a;
|
|
140
|
+
let start = this.assignedSlot || this;
|
|
141
|
+
let root = start.getRootNode();
|
|
142
|
+
if (root === document) {
|
|
143
|
+
if (true) {
|
|
144
|
+
window.__swc.warn(
|
|
145
|
+
this,
|
|
146
|
+
`Self managed <${this.localName}> elements walk up the composed tree to acquire a trigger element. No trigger element was found before the document.`,
|
|
147
|
+
"https://opensource.adobe.com/spectrum-web-components/components/tooltip#self-managed-overlays",
|
|
148
|
+
{
|
|
149
|
+
level: "high"
|
|
150
|
+
}
|
|
151
|
+
);
|
|
152
|
+
}
|
|
153
|
+
return null;
|
|
154
|
+
}
|
|
155
|
+
let triggerElement = start.parentElement || root.host || /* c8 ignore next 1 */
|
|
156
|
+
root;
|
|
157
|
+
while (!((_a = triggerElement == null ? void 0 : triggerElement.matches) == null ? void 0 : _a.call(triggerElement, focusableSelector))) {
|
|
158
|
+
start = triggerElement.assignedSlot || triggerElement;
|
|
159
|
+
root = start.getRootNode();
|
|
160
|
+
if (root === document) {
|
|
161
|
+
if (true) {
|
|
162
|
+
window.__swc.warn(
|
|
163
|
+
this,
|
|
164
|
+
`Self managed <${this.localName}> elements walk up the composed tree to acquire a trigger element. No trigger element was found before the document.`,
|
|
165
|
+
"https://opensource.adobe.com/spectrum-web-components/components/tooltip#self-managed-overlays",
|
|
166
|
+
{
|
|
167
|
+
level: "high"
|
|
168
|
+
}
|
|
169
|
+
);
|
|
170
|
+
}
|
|
171
|
+
return null;
|
|
172
|
+
}
|
|
173
|
+
triggerElement = start.parentElement || root.host || /* c8 ignore next 1 */
|
|
174
|
+
root;
|
|
175
|
+
}
|
|
176
|
+
return triggerElement;
|
|
177
|
+
}
|
|
178
|
+
render() {
|
|
179
|
+
const tooltip = html`
|
|
180
|
+
<sp-tooltip-openable
|
|
181
|
+
id="tooltip"
|
|
182
|
+
placement=${ifDefined(this.placement)}
|
|
183
|
+
@transitionrun=${this.forwardTransitionEvent}
|
|
184
|
+
@transitionend=${this.forwardTransitionEvent}
|
|
185
|
+
@transitioncancel=${this.forwardTransitionEvent}
|
|
186
|
+
>
|
|
187
|
+
<slot name="icon"></slot>
|
|
188
|
+
<span id="label"><slot></slot></span>
|
|
189
|
+
<span id="tip" aria-hidden="true"></span>
|
|
190
|
+
</sp-tooltip-openable>
|
|
191
|
+
`;
|
|
192
|
+
if (this.selfManaged) {
|
|
193
|
+
this.dependencyManager.add("sp-overlay");
|
|
194
|
+
import("@spectrum-web-components/overlay/sp-overlay.js");
|
|
195
|
+
return html`
|
|
196
|
+
<sp-overlay
|
|
197
|
+
?open=${this.open && !this.disabled && this.dependencyManager.loaded}
|
|
198
|
+
?delayed=${this.delayed}
|
|
199
|
+
?disabled=${this.disabled}
|
|
200
|
+
offset=${this.offset}
|
|
201
|
+
.placement=${this.placement}
|
|
202
|
+
type="hint"
|
|
203
|
+
.tipPadding=${this.tipPadding}
|
|
204
|
+
.triggerInteraction=${"hover"}
|
|
205
|
+
@sp-opened=${this.handleOpenOverlay}
|
|
206
|
+
@sp-closed=${this.handleCloseOverlay}
|
|
207
|
+
>
|
|
208
|
+
${tooltip}
|
|
209
|
+
</sp-overlay>
|
|
210
|
+
`;
|
|
211
|
+
} else {
|
|
212
|
+
return tooltip;
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
connectedCallback() {
|
|
216
|
+
super.connectedCallback();
|
|
217
|
+
this.updateComplete.then(() => {
|
|
218
|
+
if (!this.selfManaged) {
|
|
219
|
+
return;
|
|
220
|
+
}
|
|
221
|
+
const overlayElement = this.overlayElement;
|
|
222
|
+
if (overlayElement) {
|
|
223
|
+
const triggerElement = this.triggerElement;
|
|
224
|
+
overlayElement.triggerElement = triggerElement;
|
|
225
|
+
}
|
|
226
|
+
});
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
__decorateClass([
|
|
230
|
+
property({ type: Boolean })
|
|
231
|
+
], Tooltip.prototype, "delayed", 2);
|
|
232
|
+
__decorateClass([
|
|
233
|
+
property({ type: Boolean })
|
|
234
|
+
], Tooltip.prototype, "disabled", 2);
|
|
235
|
+
__decorateClass([
|
|
236
|
+
property({ type: Boolean, attribute: "self-managed" })
|
|
237
|
+
], Tooltip.prototype, "selfManaged", 2);
|
|
238
|
+
__decorateClass([
|
|
239
|
+
property({ type: Number })
|
|
240
|
+
], Tooltip.prototype, "offset", 2);
|
|
241
|
+
__decorateClass([
|
|
242
|
+
property({ type: Boolean, reflect: true })
|
|
243
|
+
], Tooltip.prototype, "open", 2);
|
|
244
|
+
__decorateClass([
|
|
245
|
+
query("sp-overlay")
|
|
246
|
+
], Tooltip.prototype, "overlayElement", 2);
|
|
247
|
+
__decorateClass([
|
|
248
|
+
property({ reflect: true })
|
|
249
|
+
], Tooltip.prototype, "placement", 2);
|
|
250
|
+
__decorateClass([
|
|
251
|
+
query("#tip")
|
|
252
|
+
], Tooltip.prototype, "tipElement", 2);
|
|
253
|
+
__decorateClass([
|
|
254
|
+
property({ type: Number })
|
|
255
|
+
], Tooltip.prototype, "tipPadding", 2);
|
|
256
|
+
__decorateClass([
|
|
257
|
+
property({ type: String })
|
|
258
|
+
], Tooltip.prototype, "variant", 1);
|
|
259
|
+
//# sourceMappingURL=Tooltip.dev.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 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 SpectrumElement,\n TemplateResult,\n} from '@spectrum-web-components/base';\nimport {\n property,\n query,\n} from '@spectrum-web-components/base/src/decorators.js';\nimport { ifDefined } from '@spectrum-web-components/base/src/directives.js';\nimport type {\n Overlay,\n OverlayOpenCloseDetail,\n Placement,\n} from '@spectrum-web-components/overlay';\n\nimport tooltipStyles from './tooltip.css.js';\nimport { focusableSelector } from '@spectrum-web-components/shared/src/focusable-selectors.js';\nimport { DependencyManagerController } from '@spectrum-web-components/reactive-controllers/src/DependencyManger.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 /* c8 ignore next 3 */\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 * A Tooltip that is `delayed` will its Overlay wait until a warm-up period of\n * 1000ms has completed before opening. Once the warmup period has completed, all\n * subsequent Overlays will open immediately. When no Overlays are opened, a\n * cooldown period of 1000ms will begin. Once the cooldown has completed, the next\n * Overlay to be opened will be subject to the warm-up period if provided that option.\n */\n @property({ type: Boolean })\n delayed = false;\n\n private dependencyManager = new DependencyManagerController(this);\n\n /**\n * Whether to prevent a self-managed Tooltip from responding to user input.\n */\n @property({ type: Boolean })\n disabled = false;\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 | null {\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 (root === document) {\n if (window.__swc.DEBUG) {\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 }\n return null;\n }\n let triggerElement = (start.parentElement ||\n (root as ShadowRoot).host ||\n /* c8 ignore next 1 */\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 (root === document) {\n if (window.__swc.DEBUG) {\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 }\n return null;\n }\n triggerElement = (start.parentElement ||\n (root as ShadowRoot).host ||\n /* c8 ignore next 1 */\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 this.dependencyManager.add('sp-overlay');\n import('@spectrum-web-components/overlay/sp-overlay.js');\n return html`\n <sp-overlay\n ?open=${this.open &&\n !this.disabled &&\n this.dependencyManager.loaded}\n ?delayed=${this.delayed}\n ?disabled=${this.disabled}\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;AACP,SAAS,iBAAiB;AAO1B,OAAO,mBAAmB;AAC1B,SAAS,yBAAyB;AAClC,SAAS,mCAAmC;AAE5C,MAAM,wBAAwB,YAAY;AAAA,EACtC,cAAc;AACV,UAAM;AAiDV,SAAQ,QAAQ;AAiBhB,SAAQ,aAAwB;AAjE5B,SAAK,iBAAiB,aAAa,KAAK,eAAe;AACvD,SAAK,iBAAiB,aAAa,KAAK,eAAe;AAAA,EAC3D;AAAA,EACA,gBAAgB,OAAoB;AAChC,UAAM,gBAAgB;AACtB,SAAK,QAAQ;AAAA,MACT,IAAI,YAAoC,MAAM,MAAM;AAAA,QAChD,SAAS,MAAM;AAAA,QACf,UAAU,MAAM;AAAA,QAChB,QAAS,MAA8C;AAAA,MAC3D,CAAC;AAAA,IACL;AAAA,EACJ;AAAA,EACA,IAAI,UAAmB;AACnB,WAAQ,KAAK,YAAY,EAAiB;AAAA,EAC9C;AAAA,EACA,WAAW,qBAA+B;AACtC,WAAO,CAAC,QAAQ,WAAW;AAAA,EAC/B;AAAA,EACA,yBACI,MACA,WACA,UACI;AACJ,YAAQ,MAAM;AAAA,M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,SAAS,KAAK,CAAC;AAAA,GA3ClB,QA4CF;AAGA;AAAA,EADN,MAAM,MAAM;AAAA,GA9CJ,QA+CF;AAGA;AAAA,EADN,SAAS,EAAE,MAAM,OAAO,CAAC;AAAA,GAjDjB,QAkDF;AAMI;AAAA,EADV,SAAS,EAAE,MAAM,OAAO,CAAC;AAAA,GAvDjB,QAwDE;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
package/src/Tooltip.js
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
"use strict";var c=Object.defineProperty;var m=Object.getOwnPropertyDescriptor;var o=(r,s,e,t)=>{for(var n=t>1?void 0:t?m(s,e):s,i=r.length-1,l;i>=0;i--)(l=r[i])&&(n=(t?l(s,e,n):l(n))||n);return t&&n&&c(s,e,n),n};import{html as p,SpectrumElement as h}from"@spectrum-web-components/base";import{property as a,query as d}from"@spectrum-web-components/base/src/decorators.js";import{ifDefined as u}from"@spectrum-web-components/base/src/directives.js";import v from"./tooltip.css.js";import{focusableSelector as b}from"@spectrum-web-components/shared/src/focusable-selectors.js";import{DependencyManagerController as f}from"@spectrum-web-components/reactive-controllers/src/DependencyManger.js";class g 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,t,n){switch(e){case"open":this.open=n!==null;break;case"placement":this.placement=n;break}}set open(e){this._open=e;const{tooltip:t}=this;t&&(t.open=e)}get open(){return this._open}set placement(e){this._placement=e;const{tooltip:t}=this;t&&(t.placement=e)}get placement(){return this._placement}get tipElement(){return this.tooltip.tipElement}}customElements.get("sp-tooltip-openable")||customElements.define("sp-tooltip-openable",g);export class Tooltip extends h{constructor(){super(...arguments);this.delayed=!1;this.dependencyManager=new f(this);this.disabled=!1;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[v]}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,t=e.getRootNode();if(t===document)return null;let n=e.parentElement||t.host||t;for(;!((i=n==null?void 0:n.matches)!=null&&i.call(n,b));){if(e=n.assignedSlot||n,t=e.getRootNode(),t===document)return null;n=e.parentElement||t.host||t}return n}render(){const e=p`
|
|
2
|
+
<sp-tooltip-openable
|
|
3
|
+
id="tooltip"
|
|
4
|
+
placement=${u(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?(this.dependencyManager.add("sp-overlay"),import("@spectrum-web-components/overlay/sp-overlay.js"),p`
|
|
14
|
+
<sp-overlay
|
|
15
|
+
?open=${this.open&&!this.disabled&&this.dependencyManager.loaded}
|
|
16
|
+
?delayed=${this.delayed}
|
|
17
|
+
?disabled=${this.disabled}
|
|
18
|
+
offset=${this.offset}
|
|
19
|
+
.placement=${this.placement}
|
|
20
|
+
type="hint"
|
|
21
|
+
.tipPadding=${this.tipPadding}
|
|
22
|
+
.triggerInteraction=${"hover"}
|
|
23
|
+
@sp-opened=${this.handleOpenOverlay}
|
|
24
|
+
@sp-closed=${this.handleCloseOverlay}
|
|
25
|
+
>
|
|
26
|
+
${e}
|
|
27
|
+
</sp-overlay>
|
|
28
|
+
`):e}connectedCallback(){super.connectedCallback(),this.updateComplete.then(()=>{if(!this.selfManaged)return;const e=this.overlayElement;if(e){const t=this.triggerElement;e.triggerElement=t}})}}o([a({type:Boolean})],Tooltip.prototype,"delayed",2),o([a({type:Boolean})],Tooltip.prototype,"disabled",2),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([d("sp-overlay")],Tooltip.prototype,"overlayElement",2),o([a({reflect:!0})],Tooltip.prototype,"placement",2),o([d("#tip")],Tooltip.prototype,"tipElement",2),o([a({type:Number})],Tooltip.prototype,"tipPadding",2),o([a({type:String})],Tooltip.prototype,"variant",1);
|
|
29
|
+
//# sourceMappingURL=Tooltip.js.map
|