@phila/phila-ui-tooltip 0.0.4
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 +27 -0
- package/dist/Tooltip.css +1 -0
- package/dist/Tooltip.js +112 -0
- package/dist/Tooltip.umd.cjs +2 -0
- package/dist/Tooltip.vue.d.ts +34 -0
- package/dist/types.d.ts +11 -0
- package/package.json +46 -0
package/README.md
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
## Notes
|
|
2
|
+
|
|
3
|
+
The tooltip is positioned according to the space available on the screen. On mobile the tooltip is enabled on tap, and an X is shown to allow users to close it.
|
|
4
|
+
|
|
5
|
+
## Code Samples
|
|
6
|
+
|
|
7
|
+
### Basic tooltip with dark mode enabled (default)
|
|
8
|
+
|
|
9
|
+
```html
|
|
10
|
+
<tooltip message="My tooltip message" />
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
### Basic tooltip with light mode enabled
|
|
14
|
+
|
|
15
|
+
```html
|
|
16
|
+
<tooltip message="My tooltip message" mode="light" />
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
## Live Examples
|
|
20
|
+
|
|
21
|
+
### Basic tooltip with dark mode enabled (default)
|
|
22
|
+
|
|
23
|
+
<example name="Tooltip1" height="300"></example>
|
|
24
|
+
|
|
25
|
+
### Basic tooltip with light mode enabled
|
|
26
|
+
|
|
27
|
+
<example name="Tooltip2" height="300"></example>
|
package/dist/Tooltip.css
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
@font-face{font-family:Montserrat;src:local("Montserrat Regular"),local("Montserrat-Regular"),url(https://www.phila.gov/assets/fonts/Montserrat/Montserrat-Regular.woff2) format("woff2"),url(https://www.phila.gov/assets/fonts/Montserrat/Montserrat-Regular.woff) format("woff");font-weight:400;font-style:normal}@font-face{font-family:Open Sans;src:local("Open Sans Italic"),local("OpenSans-Italic"),url(https://www.phila.gov/assets/fonts/OpenSans/OpenSans-Italic.woff2) format("woff2"),url(https://www.phila.gov/assets/fonts/OpenSans/OpenSans-Italic.woff) format("woff");font-weight:400;font-style:italic}@font-face{font-family:Open Sans;src:local("Open Sans Bold Italic"),local("OpenSans-BoldItalic"),url(https://www.phila.gov/assets/fonts/OpenSans/OpenSans-BoldItalic.woff2) format("woff2"),url(https://www.phila.gov/assets/fonts/OpenSans/OpenSans-BoldItalic.woff) format("woff");font-weight:700;font-style:italic}@font-face{font-family:Montserrat;src:local("Montserrat Bold"),local("Montserrat-Bold"),url(https://www.phila.gov/assets/fonts/Montserrat/Montserrat-Bold.woff2) format("woff2"),url(https://www.phila.gov/assets/fonts/Montserrat/Montserrat-Bold.woff) format("woff");font-weight:700;font-style:normal}@font-face{font-family:Open Sans;src:local("Open Sans Bold"),local("OpenSans-Bold"),url(https://www.phila.gov/assets/fonts/OpenSans/OpenSans-Bold.woff2) format("woff2"),url(https://www.phila.gov/assets/fonts/OpenSans/OpenSans-Bold.woff) format("woff");font-weight:700;font-style:normal}@font-face{font-family:Open Sans;src:local("Open Sans SemiBold Italic"),local("OpenSans-SemiBoldItalic"),url(https://www.phila.gov/assets/fonts/OpenSans/OpenSans-SemiBoldItalic.woff2) format("woff2"),url(https://www.phila.gov/assets/fonts/OpenSans/OpenSans-SemiBoldItalic.woff) format("woff");font-weight:600;font-style:italic}@font-face{font-family:Open Sans;src:local("Open Sans SemiBold"),local("OpenSans-SemiBold"),url(https://www.phila.gov/assets/fonts/OpenSans/OpenSans-SemiBold.woff2) format("woff2"),url(https://www.phila.gov/assets/fonts/OpenSans/OpenSans-SemiBold.woff) format("woff");font-weight:600;font-style:normal}@font-face{font-family:Open Sans;src:local("Open Sans Regular"),local("OpenSans-Regular"),url(https://www.phila.gov/assets/fonts/OpenSans/OpenSans-Regular.woff2) format("woff2"),url(https://www.phila.gov/assets/fonts/OpenSans/OpenSans-Regular.woff) format("woff");font-weight:400;font-style:normal}.tooltip{display:inline-block;margin-left:5px;vertical-align:middle}.tooltip button{color:#0f4d90;font-size:25px;border:0;background-color:transparent;box-shadow:none;padding:0;margin:0;cursor:pointer;vertical-align:middle;position:relative;top:-2px}.tooltip-box{display:block;visibility:hidden;z-index:-100;width:auto;max-width:500px;position:fixed;top:0;left:0;opacity:0;transition:opacity .25s ease-in-out;pointer-events:none}.tooltip-box .tooltip-message{line-height:20px;color:#fff;background-color:#444;font-size:12px;padding:10px 8px 8px}@media screen and (max-width: 768px){.tooltip-box .tooltip-message{padding-top:36px}.tooltip-box .tooltip-message:before{display:inline-block;font-style:normal;font-variant:normal;text-rendering:auto;-webkit-font-smoothing:antialiased;content:"";position:absolute;top:12px;right:16px;font-family:"Font Awesome 5 Pro",sans-serif;font-weight:900;font-size:20px}}@media screen and (max-width: 500px){.tooltip-box{width:auto;max-width:100%}}.tooltip-box .tooltip-arrow{position:fixed;left:0;top:0;border:solid 8px transparent;border-top-color:#444}.tooltip-box .tooltip-arrow.arrow-up{border-top-color:transparent;border-bottom-color:#444}.tooltip-box.light .tooltip-message{color:#444;background-color:#f0f0f0}.tooltip-box.light .tooltip-arrow{border-top-color:#f0f0f0}.tooltip-box.light .tooltip-arrow.arrow-up{border-top-color:transparent;border-bottom-color:#f0f0f0}.tooltip-box.show{visibility:visible;opacity:1;z-index:9999}
|
package/dist/Tooltip.js
ADDED
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
import "./Tooltip.css";
|
|
2
|
+
import { defineComponent as p, ref as n, onMounted as h, openBlock as a, createElementBlock as r, renderSlot as d } from "vue";
|
|
3
|
+
class c {
|
|
4
|
+
constructor(t, o, i, s) {
|
|
5
|
+
this.htmlBody = document.getElementsByTagName("body")[0], this.tooltip = t, this.tooltipIcon = null, this.tooltipIconClasses = "fas fa-info-circle", this.tooltipArrow = null, this.tooltipBox = null, this.tooltipText = o, this.tooltipBoxClasses = "tooltip-box", this.tooltipMessageClasses = "tooltip-message", this.tooltipArrowClasses = "tooltip-arrow", this.tooltipMode = i || "dark", this.currentTooltipPosition = null, this.initPositionSet = !1, this.tooltipID = s, this.tooltipBtnID = `btn-${s}`, this.padding = 8, this.arrowAttrs = {
|
|
6
|
+
height: 8,
|
|
7
|
+
width: 16
|
|
8
|
+
}, this.clickedToOpen = !1, this.newTooltip();
|
|
9
|
+
}
|
|
10
|
+
newTooltip() {
|
|
11
|
+
this.makeTooltipContainer(), this.setTooltipEvents(), this.setTooltipMsg(), this.setTooltipMode(), this.addTooltip();
|
|
12
|
+
const t = this;
|
|
13
|
+
var o = setInterval(function() {
|
|
14
|
+
const i = document.getElementById(t.tooltipID);
|
|
15
|
+
i && i.offsetHeight > 0 && (t.addTooltipIcon(), t.setInitTooltipPosition(), t.updateArrowPosition(), clearInterval(o));
|
|
16
|
+
}, 500);
|
|
17
|
+
}
|
|
18
|
+
makeTooltipContainer() {
|
|
19
|
+
this.tooltipArrow = document.createElement("div"), this.tooltipArrow.className = this.tooltipArrowClasses, this.tooltipBox = document.createElement("div"), this.tooltipBox.className = this.tooltipBoxClasses, this.tooltipBox.setAttribute("id", this.tooltipID), this.tooltipMessage = document.createElement("div"), this.tooltipMessage.className = this.tooltipMessageClasses, this.tooltipIcon = document.createElement("button"), this.tooltipIcon.setAttribute("aria-label", "tooltip"), this.tooltipIcon.className = this.tooltipIconClasses, this.tooltipIcon.setAttribute("id", this.tooltipBtnID);
|
|
20
|
+
}
|
|
21
|
+
addTooltipIcon() {
|
|
22
|
+
this.tooltip.appendChild(this.tooltipIcon);
|
|
23
|
+
}
|
|
24
|
+
addTooltip() {
|
|
25
|
+
this.tooltipBox.appendChild(this.tooltipMessage), this.tooltipBox.appendChild(this.tooltipArrow), this.htmlBody.appendChild(this.tooltipBox);
|
|
26
|
+
}
|
|
27
|
+
setTooltipMode() {
|
|
28
|
+
this.tooltipBox.className = this.tooltipBoxClasses, this.tooltipBox.classList.add(this.tooltipMode);
|
|
29
|
+
}
|
|
30
|
+
setTooltipMsg() {
|
|
31
|
+
this.tooltipMessage.innerText = this.tooltipText;
|
|
32
|
+
}
|
|
33
|
+
setTooltipEvents() {
|
|
34
|
+
const t = this;
|
|
35
|
+
window.addEventListener("resize", function() {
|
|
36
|
+
t.updateTooltipPosition();
|
|
37
|
+
}, !0), this.tooltipIcon.addEventListener("mouseenter", function() {
|
|
38
|
+
t.updateTooltipPosition(), t.showTooltip();
|
|
39
|
+
}), window.addEventListener("scroll", function() {
|
|
40
|
+
t.tooltipBox.classList.contains("show") && t.hideTooltip();
|
|
41
|
+
}), this.tooltipIcon.addEventListener("focus", function() {
|
|
42
|
+
t.updateTooltipPosition(), t.showTooltip();
|
|
43
|
+
}), this.tooltipIcon.addEventListener("mouseleave", function() {
|
|
44
|
+
t.clickedToOpen || t.hideTooltip();
|
|
45
|
+
}), this.tooltipIcon.addEventListener("blur", function() {
|
|
46
|
+
t.hideTooltip();
|
|
47
|
+
}), this.tooltipIcon.addEventListener("click", function() {
|
|
48
|
+
t.clickedToOpen = !0, t.updateTooltipPosition(), t.toggleTooltip();
|
|
49
|
+
}, !1), window.addEventListener("click", function(o) {
|
|
50
|
+
o.target !== t.tooltipIcon && t.clickedToOpen && (t.hideTooltip(), t.clickedToOpen = !1);
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
toggleTooltip() {
|
|
54
|
+
this.clickedToOpen ? this.showTooltip() : this.hideTooltip();
|
|
55
|
+
}
|
|
56
|
+
showTooltip() {
|
|
57
|
+
this.tooltipBox.classList.add("show"), this.tooltipBox.setAttribute("aria-hidden", !1);
|
|
58
|
+
}
|
|
59
|
+
hideTooltip() {
|
|
60
|
+
this.tooltipBox.classList.remove("show"), this.tooltipBox.setAttribute("aria-hidden", !0);
|
|
61
|
+
}
|
|
62
|
+
updateArrowPosition() {
|
|
63
|
+
const t = this.tooltipIcon.getBoundingClientRect(), o = this.tooltipBox.getBoundingClientRect();
|
|
64
|
+
this.tooltipArrow.style.left = `${t.left + this.tooltipIcon.offsetWidth / 2 - this.arrowAttrs.width / 2}px`, o.top > t.top ? (this.tooltipArrow.style.top = `${o.top - this.arrowAttrs.height * 2}px`, this.tooltipArrow.classList.add("arrow-up")) : (this.tooltipArrow.style.top = `${o.top + this.tooltipBox.offsetHeight}px`, this.tooltipArrow.classList.remove("arrow-up"));
|
|
65
|
+
}
|
|
66
|
+
setInitTooltipPosition() {
|
|
67
|
+
const t = this.tooltipIcon.getBoundingClientRect();
|
|
68
|
+
this.tooltipBox.style.left = `${t.left + this.tooltipIcon.offsetWidth / 2 - this.tooltipBox.offsetWidth / 2}px`, this.tooltipBox.style.top = `${t.top - this.tooltipBox.offsetHeight - this.arrowAttrs.height}px`;
|
|
69
|
+
}
|
|
70
|
+
updateTooltipPosition(t = !0) {
|
|
71
|
+
t && this.setInitTooltipPosition();
|
|
72
|
+
const o = window.innerWidth;
|
|
73
|
+
let i = o - this.padding * 2;
|
|
74
|
+
i <= 500 && (this.tooltipBox.style.maxWidth = `${i}px`);
|
|
75
|
+
const s = this.tooltipIcon.getBoundingClientRect(), e = this.tooltipBox.getBoundingClientRect();
|
|
76
|
+
if (e.left < this.padding) {
|
|
77
|
+
this.tooltipBox.style.left = `${this.padding}px`, this.tooltipBox.style.top = `${s.top - this.tooltipBox.offsetHeight - this.arrowAttrs.height}px`, this.updateTooltipPosition(!1);
|
|
78
|
+
return;
|
|
79
|
+
} else if (e.left + this.tooltipBox.offsetWidth > o - this.padding) {
|
|
80
|
+
this.tooltipBox.style.left = `${window.innerWidth - this.padding - this.tooltipBox.offsetWidth}px`, this.tooltipBox.style.top = `${s.top - this.tooltipBox.offsetHeight - this.arrowAttrs.height}px`, this.updateTooltipPosition(!1);
|
|
81
|
+
return;
|
|
82
|
+
} else if (e.top < this.padding) {
|
|
83
|
+
this.tooltipBox.style.left = `${e.left}px`, this.tooltipBox.style.top = `${s.bottom + this.arrowAttrs.height}px`, this.updateTooltipPosition(!1);
|
|
84
|
+
return;
|
|
85
|
+
}
|
|
86
|
+
this.updateArrowPosition();
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
const f = ["aria-describedby"], x = /* @__PURE__ */ p({
|
|
90
|
+
__name: "Tooltip",
|
|
91
|
+
props: {
|
|
92
|
+
mode: { default: "light" },
|
|
93
|
+
message: {}
|
|
94
|
+
},
|
|
95
|
+
setup(l) {
|
|
96
|
+
const t = l, o = n(Math.floor((1 + Math.random()) * 65536).toString(16).substring(1)), i = n(null);
|
|
97
|
+
return h(() => {
|
|
98
|
+
t.message.length >= 250 && console.warn("The tooltip message should be no longer than 250 characters"), new c(i.value, t.message, t.mode, o.value);
|
|
99
|
+
}), (s, e) => (a(), r("div", {
|
|
100
|
+
ref_key: "tooltip",
|
|
101
|
+
ref: i,
|
|
102
|
+
class: "tooltip",
|
|
103
|
+
role: "tooltip",
|
|
104
|
+
"aria-describedby": o.value
|
|
105
|
+
}, [
|
|
106
|
+
d(s.$slots, "default")
|
|
107
|
+
], 8, f));
|
|
108
|
+
}
|
|
109
|
+
});
|
|
110
|
+
export {
|
|
111
|
+
x as default
|
|
112
|
+
};
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
(function(i,l){typeof exports=="object"&&typeof module<"u"?module.exports=l(require("vue")):typeof define=="function"&&define.amd?define(["vue"],l):(i=typeof globalThis<"u"?globalThis:i||self,i.Tooltip=l(i.Vue))})(this,function(i){"use strict";var l=document.createElement("style");l.textContent=`@font-face{font-family:Montserrat;src:local("Montserrat Regular"),local("Montserrat-Regular"),url(https://www.phila.gov/assets/fonts/Montserrat/Montserrat-Regular.woff2) format("woff2"),url(https://www.phila.gov/assets/fonts/Montserrat/Montserrat-Regular.woff) format("woff");font-weight:400;font-style:normal}@font-face{font-family:Open Sans;src:local("Open Sans Italic"),local("OpenSans-Italic"),url(https://www.phila.gov/assets/fonts/OpenSans/OpenSans-Italic.woff2) format("woff2"),url(https://www.phila.gov/assets/fonts/OpenSans/OpenSans-Italic.woff) format("woff");font-weight:400;font-style:italic}@font-face{font-family:Open Sans;src:local("Open Sans Bold Italic"),local("OpenSans-BoldItalic"),url(https://www.phila.gov/assets/fonts/OpenSans/OpenSans-BoldItalic.woff2) format("woff2"),url(https://www.phila.gov/assets/fonts/OpenSans/OpenSans-BoldItalic.woff) format("woff");font-weight:700;font-style:italic}@font-face{font-family:Montserrat;src:local("Montserrat Bold"),local("Montserrat-Bold"),url(https://www.phila.gov/assets/fonts/Montserrat/Montserrat-Bold.woff2) format("woff2"),url(https://www.phila.gov/assets/fonts/Montserrat/Montserrat-Bold.woff) format("woff");font-weight:700;font-style:normal}@font-face{font-family:Open Sans;src:local("Open Sans Bold"),local("OpenSans-Bold"),url(https://www.phila.gov/assets/fonts/OpenSans/OpenSans-Bold.woff2) format("woff2"),url(https://www.phila.gov/assets/fonts/OpenSans/OpenSans-Bold.woff) format("woff");font-weight:700;font-style:normal}@font-face{font-family:Open Sans;src:local("Open Sans SemiBold Italic"),local("OpenSans-SemiBoldItalic"),url(https://www.phila.gov/assets/fonts/OpenSans/OpenSans-SemiBoldItalic.woff2) format("woff2"),url(https://www.phila.gov/assets/fonts/OpenSans/OpenSans-SemiBoldItalic.woff) format("woff");font-weight:600;font-style:italic}@font-face{font-family:Open Sans;src:local("Open Sans SemiBold"),local("OpenSans-SemiBold"),url(https://www.phila.gov/assets/fonts/OpenSans/OpenSans-SemiBold.woff2) format("woff2"),url(https://www.phila.gov/assets/fonts/OpenSans/OpenSans-SemiBold.woff) format("woff");font-weight:600;font-style:normal}@font-face{font-family:Open Sans;src:local("Open Sans Regular"),local("OpenSans-Regular"),url(https://www.phila.gov/assets/fonts/OpenSans/OpenSans-Regular.woff2) format("woff2"),url(https://www.phila.gov/assets/fonts/OpenSans/OpenSans-Regular.woff) format("woff");font-weight:400;font-style:normal}.tooltip{display:inline-block;margin-left:5px;vertical-align:middle}.tooltip button{color:#0f4d90;font-size:25px;border:0;background-color:transparent;box-shadow:none;padding:0;margin:0;cursor:pointer;vertical-align:middle;position:relative;top:-2px}.tooltip-box{display:block;visibility:hidden;z-index:-100;width:auto;max-width:500px;position:fixed;top:0;left:0;opacity:0;transition:opacity .25s ease-in-out;pointer-events:none}.tooltip-box .tooltip-message{line-height:20px;color:#fff;background-color:#444;font-size:12px;padding:10px 8px 8px}@media screen and (max-width: 768px){.tooltip-box .tooltip-message{padding-top:36px}.tooltip-box .tooltip-message:before{display:inline-block;font-style:normal;font-variant:normal;text-rendering:auto;-webkit-font-smoothing:antialiased;content:"";position:absolute;top:12px;right:16px;font-family:"Font Awesome 5 Pro",sans-serif;font-weight:900;font-size:20px}}@media screen and (max-width: 500px){.tooltip-box{width:auto;max-width:100%}}.tooltip-box .tooltip-arrow{position:fixed;left:0;top:0;border:solid 8px transparent;border-top-color:#444}.tooltip-box .tooltip-arrow.arrow-up{border-top-color:transparent;border-bottom-color:#444}.tooltip-box.light .tooltip-message{color:#444;background-color:#f0f0f0}.tooltip-box.light .tooltip-arrow{border-top-color:#f0f0f0}.tooltip-box.light .tooltip-arrow.arrow-up{border-top-color:transparent;border-bottom-color:#f0f0f0}.tooltip-box.show{visibility:visible;opacity:1;z-index:9999}
|
|
2
|
+
`,document.head.appendChild(l);class p{constructor(t,o,s,e){this.htmlBody=document.getElementsByTagName("body")[0],this.tooltip=t,this.tooltipIcon=null,this.tooltipIconClasses="fas fa-info-circle",this.tooltipArrow=null,this.tooltipBox=null,this.tooltipText=o,this.tooltipBoxClasses="tooltip-box",this.tooltipMessageClasses="tooltip-message",this.tooltipArrowClasses="tooltip-arrow",this.tooltipMode=s||"dark",this.currentTooltipPosition=null,this.initPositionSet=!1,this.tooltipID=e,this.tooltipBtnID=`btn-${e}`,this.padding=8,this.arrowAttrs={height:8,width:16},this.clickedToOpen=!1,this.newTooltip()}newTooltip(){this.makeTooltipContainer(),this.setTooltipEvents(),this.setTooltipMsg(),this.setTooltipMode(),this.addTooltip();const t=this;var o=setInterval(function(){const s=document.getElementById(t.tooltipID);s&&s.offsetHeight>0&&(t.addTooltipIcon(),t.setInitTooltipPosition(),t.updateArrowPosition(),clearInterval(o))},500)}makeTooltipContainer(){this.tooltipArrow=document.createElement("div"),this.tooltipArrow.className=this.tooltipArrowClasses,this.tooltipBox=document.createElement("div"),this.tooltipBox.className=this.tooltipBoxClasses,this.tooltipBox.setAttribute("id",this.tooltipID),this.tooltipMessage=document.createElement("div"),this.tooltipMessage.className=this.tooltipMessageClasses,this.tooltipIcon=document.createElement("button"),this.tooltipIcon.setAttribute("aria-label","tooltip"),this.tooltipIcon.className=this.tooltipIconClasses,this.tooltipIcon.setAttribute("id",this.tooltipBtnID)}addTooltipIcon(){this.tooltip.appendChild(this.tooltipIcon)}addTooltip(){this.tooltipBox.appendChild(this.tooltipMessage),this.tooltipBox.appendChild(this.tooltipArrow),this.htmlBody.appendChild(this.tooltipBox)}setTooltipMode(){this.tooltipBox.className=this.tooltipBoxClasses,this.tooltipBox.classList.add(this.tooltipMode)}setTooltipMsg(){this.tooltipMessage.innerText=this.tooltipText}setTooltipEvents(){const t=this;window.addEventListener("resize",function(){t.updateTooltipPosition()},!0),this.tooltipIcon.addEventListener("mouseenter",function(){t.updateTooltipPosition(),t.showTooltip()}),window.addEventListener("scroll",function(){t.tooltipBox.classList.contains("show")&&t.hideTooltip()}),this.tooltipIcon.addEventListener("focus",function(){t.updateTooltipPosition(),t.showTooltip()}),this.tooltipIcon.addEventListener("mouseleave",function(){t.clickedToOpen||t.hideTooltip()}),this.tooltipIcon.addEventListener("blur",function(){t.hideTooltip()}),this.tooltipIcon.addEventListener("click",function(){t.clickedToOpen=!0,t.updateTooltipPosition(),t.toggleTooltip()},!1),window.addEventListener("click",function(o){o.target!==t.tooltipIcon&&t.clickedToOpen&&(t.hideTooltip(),t.clickedToOpen=!1)})}toggleTooltip(){this.clickedToOpen?this.showTooltip():this.hideTooltip()}showTooltip(){this.tooltipBox.classList.add("show"),this.tooltipBox.setAttribute("aria-hidden",!1)}hideTooltip(){this.tooltipBox.classList.remove("show"),this.tooltipBox.setAttribute("aria-hidden",!0)}updateArrowPosition(){const t=this.tooltipIcon.getBoundingClientRect(),o=this.tooltipBox.getBoundingClientRect();this.tooltipArrow.style.left=`${t.left+this.tooltipIcon.offsetWidth/2-this.arrowAttrs.width/2}px`,o.top>t.top?(this.tooltipArrow.style.top=`${o.top-this.arrowAttrs.height*2}px`,this.tooltipArrow.classList.add("arrow-up")):(this.tooltipArrow.style.top=`${o.top+this.tooltipBox.offsetHeight}px`,this.tooltipArrow.classList.remove("arrow-up"))}setInitTooltipPosition(){const t=this.tooltipIcon.getBoundingClientRect();this.tooltipBox.style.left=`${t.left+this.tooltipIcon.offsetWidth/2-this.tooltipBox.offsetWidth/2}px`,this.tooltipBox.style.top=`${t.top-this.tooltipBox.offsetHeight-this.arrowAttrs.height}px`}updateTooltipPosition(t=!0){t&&this.setInitTooltipPosition();const o=window.innerWidth;let s=o-this.padding*2;s<=500&&(this.tooltipBox.style.maxWidth=`${s}px`);const e=this.tooltipIcon.getBoundingClientRect(),n=this.tooltipBox.getBoundingClientRect();if(n.left<this.padding){this.tooltipBox.style.left=`${this.padding}px`,this.tooltipBox.style.top=`${e.top-this.tooltipBox.offsetHeight-this.arrowAttrs.height}px`,this.updateTooltipPosition(!1);return}else if(n.left+this.tooltipBox.offsetWidth>o-this.padding){this.tooltipBox.style.left=`${window.innerWidth-this.padding-this.tooltipBox.offsetWidth}px`,this.tooltipBox.style.top=`${e.top-this.tooltipBox.offsetHeight-this.arrowAttrs.height}px`,this.updateTooltipPosition(!1);return}else if(n.top<this.padding){this.tooltipBox.style.left=`${n.left}px`,this.tooltipBox.style.top=`${e.bottom+this.arrowAttrs.height}px`,this.updateTooltipPosition(!1);return}this.updateArrowPosition()}}const r=["aria-describedby"];return i.defineComponent({__name:"Tooltip",props:{mode:{default:"light"},message:{}},setup(a){const t=a,o=i.ref(Math.floor((1+Math.random())*65536).toString(16).substring(1)),s=i.ref(null);return i.onMounted(()=>{t.message.length>=250&&console.warn("The tooltip message should be no longer than 250 characters"),new p(s.value,t.message,t.mode,o.value)}),(e,n)=>(i.openBlock(),i.createElementBlock("div",{ref_key:"tooltip",ref:s,class:"tooltip",role:"tooltip","aria-describedby":o.value},[i.renderSlot(e.$slots,"default")],8,r))}})});
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { TooltipProps } from './types';
|
|
2
|
+
|
|
3
|
+
declare const _default: __VLS_WithTemplateSlots<import('vue').DefineComponent<__VLS_WithDefaults<__VLS_TypePropsToRuntimeProps<TooltipProps>, {
|
|
4
|
+
mode: string;
|
|
5
|
+
}>, {}, unknown, {}, {}, import('vue').ComponentOptionsMixin, import('vue').ComponentOptionsMixin, {}, string, import('vue').PublicProps, Readonly<import('vue').ExtractPropTypes<__VLS_WithDefaults<__VLS_TypePropsToRuntimeProps<TooltipProps>, {
|
|
6
|
+
mode: string;
|
|
7
|
+
}>>>, {
|
|
8
|
+
mode: "dark" | "light";
|
|
9
|
+
}, {}>, {
|
|
10
|
+
default?(_: {}): any;
|
|
11
|
+
}>;
|
|
12
|
+
export default _default;
|
|
13
|
+
type __VLS_NonUndefinedable<T> = T extends undefined ? never : T;
|
|
14
|
+
type __VLS_TypePropsToRuntimeProps<T> = {
|
|
15
|
+
[K in keyof T]-?: {} extends Pick<T, K> ? {
|
|
16
|
+
type: import('vue').PropType<__VLS_NonUndefinedable<T[K]>>;
|
|
17
|
+
} : {
|
|
18
|
+
type: import('vue').PropType<T[K]>;
|
|
19
|
+
required: true;
|
|
20
|
+
};
|
|
21
|
+
};
|
|
22
|
+
type __VLS_WithDefaults<P, D> = {
|
|
23
|
+
[K in keyof Pick<P, keyof P>]: K extends keyof D ? __VLS_Prettify<P[K] & {
|
|
24
|
+
default: D[K];
|
|
25
|
+
}> : P[K];
|
|
26
|
+
};
|
|
27
|
+
type __VLS_Prettify<T> = {
|
|
28
|
+
[K in keyof T]: T[K];
|
|
29
|
+
} & {};
|
|
30
|
+
type __VLS_WithTemplateSlots<T, S> = T & {
|
|
31
|
+
new (): {
|
|
32
|
+
$slots: S;
|
|
33
|
+
};
|
|
34
|
+
};
|
package/dist/types.d.ts
ADDED
package/package.json
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@phila/phila-ui-tooltip",
|
|
3
|
+
"private": false,
|
|
4
|
+
"version": "0.0.4",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"files": [
|
|
7
|
+
"dist"
|
|
8
|
+
],
|
|
9
|
+
"main": "./dist/Tooltip.umd.cjs",
|
|
10
|
+
"module": "./dist/Tooltip.js",
|
|
11
|
+
"types": "./dist/types.d.ts",
|
|
12
|
+
"exports": {
|
|
13
|
+
".": {
|
|
14
|
+
"import": {
|
|
15
|
+
"types": "./dist/types.d.ts",
|
|
16
|
+
"default": "./dist/Tooltip.js"
|
|
17
|
+
},
|
|
18
|
+
"require": "./dist/Tooltip.umd.cjs"
|
|
19
|
+
}
|
|
20
|
+
},
|
|
21
|
+
"scripts": {
|
|
22
|
+
"dev": "vite",
|
|
23
|
+
"prepublish": "npm i && npm run build",
|
|
24
|
+
"build": "vue-tsc && vite build",
|
|
25
|
+
"preview": "vite preview"
|
|
26
|
+
},
|
|
27
|
+
"dependencies": {
|
|
28
|
+
"@phila/phila-ui-core": "^1.0.12",
|
|
29
|
+
"vue": "^3.3.8"
|
|
30
|
+
},
|
|
31
|
+
"devDependencies": {
|
|
32
|
+
"@types/node": "^20.10.3",
|
|
33
|
+
"@vitejs/plugin-vue": "^4.5.0",
|
|
34
|
+
"sass": "^1.70.0",
|
|
35
|
+
"typescript": "^5.2.2",
|
|
36
|
+
"vite": "^5.0.0",
|
|
37
|
+
"vite-plugin-dts": "^3.6.4",
|
|
38
|
+
"vite-plugin-lib-inject-css": "^1.3.0",
|
|
39
|
+
"vue-tsc": "^1.8.22"
|
|
40
|
+
},
|
|
41
|
+
"publishConfig": {
|
|
42
|
+
"registry": "https://registry.npmjs.com/",
|
|
43
|
+
"access": "public"
|
|
44
|
+
},
|
|
45
|
+
"gitHead": "2b2468cbfe9c815c8febd5c12dccb2c785617cb1"
|
|
46
|
+
}
|