chunk.DBZL4FBI.js 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323
  1. import {
  2. createPopper
  3. } from "./chunk.GADG7AUG.js";
  4. import {
  5. animateTo,
  6. parseDuration,
  7. stopAnimations,
  8. waitForEvent
  9. } from "./chunk.CTCDC263.js";
  10. import {
  11. getAnimation,
  12. setDefaultAnimation
  13. } from "./chunk.NC36RJW4.js";
  14. import {
  15. event,
  16. watch
  17. } from "./chunk.XX234VRK.js";
  18. import {
  19. e as e2
  20. } from "./chunk.YXKHB4AC.js";
  21. import {
  22. T,
  23. e,
  24. h,
  25. n,
  26. o,
  27. r
  28. } from "./chunk.5PIDMFOE.js";
  29. import {
  30. __decorateClass
  31. } from "./chunk.IHGPZX35.js";
  32. // _uyihdawu1:/Users/claviska/Projects/shoelace/src/components/tooltip/tooltip.scss
  33. var tooltip_default = ':host {\n position: relative;\n box-sizing: border-box;\n}\n:host *, :host *:before, :host *:after {\n box-sizing: inherit;\n}\n\n[hidden] {\n display: none !important;\n}\n\n:host {\n --max-width: 20rem;\n --hide-delay: 0ms;\n --show-delay: 150ms;\n display: contents;\n}\n\n.tooltip-positioner {\n position: absolute;\n z-index: var(--sl-z-index-tooltip);\n pointer-events: none;\n}\n\n.tooltip {\n max-width: var(--max-width);\n border-radius: var(--sl-tooltip-border-radius);\n background-color: var(--sl-tooltip-background-color);\n font-family: var(--sl-tooltip-font-family);\n font-size: var(--sl-tooltip-font-size);\n font-weight: var(--sl-tooltip-font-weight);\n line-height: var(--sl-tooltip-line-height);\n color: var(--sl-tooltip-color);\n padding: var(--sl-tooltip-padding);\n}\n.tooltip:after {\n content: "";\n position: absolute;\n width: 0;\n height: 0;\n}\n\n.tooltip-positioner[data-popper-placement^=top] .tooltip {\n transform-origin: bottom;\n}\n.tooltip-positioner[data-popper-placement^=bottom] .tooltip {\n transform-origin: top;\n}\n.tooltip-positioner[data-popper-placement^=left] .tooltip {\n transform-origin: right;\n}\n.tooltip-positioner[data-popper-placement^=right] .tooltip {\n transform-origin: left;\n}\n\n.tooltip-positioner[data-popper-placement^=bottom] .tooltip:after {\n bottom: 100%;\n left: calc(50% - var(--sl-tooltip-arrow-size));\n border-bottom: var(--sl-tooltip-arrow-size) solid var(--sl-tooltip-background-color);\n border-left: var(--sl-tooltip-arrow-size) solid transparent;\n border-right: var(--sl-tooltip-arrow-size) solid transparent;\n}\n\n.tooltip-positioner[data-popper-placement=bottom-start] .tooltip:after {\n left: var(--sl-tooltip-arrow-start-end-offset);\n}\n\n.tooltip-positioner[data-popper-placement=bottom-end] .tooltip:after {\n right: var(--sl-tooltip-arrow-start-end-offset);\n left: auto;\n}\n\n.tooltip-positioner[data-popper-placement^=top] .tooltip:after {\n top: 100%;\n left: calc(50% - var(--sl-tooltip-arrow-size));\n border-top: var(--sl-tooltip-arrow-size) solid var(--sl-tooltip-background-color);\n border-left: var(--sl-tooltip-arrow-size) solid transparent;\n border-right: var(--sl-tooltip-arrow-size) solid transparent;\n}\n\n.tooltip-positioner[data-popper-placement=top-start] .tooltip:after {\n left: var(--sl-tooltip-arrow-start-end-offset);\n}\n\n.tooltip-positioner[data-popper-placement=top-end] .tooltip:after {\n right: var(--sl-tooltip-arrow-start-end-offset);\n left: auto;\n}\n\n.tooltip-positioner[data-popper-placement^=left] .tooltip:after {\n top: calc(50% - var(--sl-tooltip-arrow-size));\n left: 100%;\n border-left: var(--sl-tooltip-arrow-size) solid var(--sl-tooltip-background-color);\n border-top: var(--sl-tooltip-arrow-size) solid transparent;\n border-bottom: var(--sl-tooltip-arrow-size) solid transparent;\n}\n\n.tooltip-positioner[data-popper-placement=left-start] .tooltip:after {\n top: var(--sl-tooltip-arrow-start-end-offset);\n}\n\n.tooltip-positioner[data-popper-placement=left-end] .tooltip:after {\n top: auto;\n bottom: var(--sl-tooltip-arrow-start-end-offset);\n}\n\n.tooltip-positioner[data-popper-placement^=right] .tooltip:after {\n top: calc(50% - var(--sl-tooltip-arrow-size));\n right: 100%;\n border-right: var(--sl-tooltip-arrow-size) solid var(--sl-tooltip-background-color);\n border-top: var(--sl-tooltip-arrow-size) solid transparent;\n border-bottom: var(--sl-tooltip-arrow-size) solid transparent;\n}\n\n.tooltip-positioner[data-popper-placement=right-start] .tooltip:after {\n top: var(--sl-tooltip-arrow-start-end-offset);\n}\n\n.tooltip-positioner[data-popper-placement=right-end] .tooltip:after {\n top: auto;\n bottom: var(--sl-tooltip-arrow-start-end-offset);\n}';
  34. // src/components/tooltip/tooltip.ts
  35. var id = 0;
  36. var SlTooltip = class extends h {
  37. constructor() {
  38. super(...arguments);
  39. this.componentId = `tooltip-${++id}`;
  40. this.hasInitialized = false;
  41. this.content = "";
  42. this.placement = "top";
  43. this.disabled = false;
  44. this.distance = 10;
  45. this.open = false;
  46. this.skidding = 0;
  47. this.trigger = "hover focus";
  48. }
  49. connectedCallback() {
  50. super.connectedCallback();
  51. this.handleBlur = this.handleBlur.bind(this);
  52. this.handleClick = this.handleClick.bind(this);
  53. this.handleFocus = this.handleFocus.bind(this);
  54. this.handleKeyDown = this.handleKeyDown.bind(this);
  55. this.handleMouseOver = this.handleMouseOver.bind(this);
  56. this.handleMouseOut = this.handleMouseOut.bind(this);
  57. this.updateComplete.then(() => {
  58. this.addEventListener("blur", this.handleBlur, true);
  59. this.addEventListener("focus", this.handleFocus, true);
  60. this.addEventListener("click", this.handleClick);
  61. this.addEventListener("keydown", this.handleKeyDown);
  62. this.addEventListener("mouseover", this.handleMouseOver);
  63. this.addEventListener("mouseout", this.handleMouseOut);
  64. this.target = this.getTarget();
  65. this.syncOptions();
  66. });
  67. }
  68. firstUpdated() {
  69. this.tooltip.hidden = !this.open;
  70. this.updateComplete.then(() => this.hasInitialized = true);
  71. }
  72. disconnectedCallback() {
  73. super.disconnectedCallback();
  74. this.removeEventListener("blur", this.handleBlur, true);
  75. this.removeEventListener("focus", this.handleFocus, true);
  76. this.removeEventListener("click", this.handleClick);
  77. this.removeEventListener("keydown", this.handleKeyDown);
  78. this.removeEventListener("mouseover", this.handleMouseOver);
  79. this.removeEventListener("mouseout", this.handleMouseOut);
  80. if (this.popover) {
  81. this.popover.destroy();
  82. }
  83. }
  84. async show() {
  85. if (this.open) {
  86. return;
  87. }
  88. this.open = true;
  89. return waitForEvent(this, "sl-after-show");
  90. }
  91. async hide() {
  92. if (!this.open) {
  93. return;
  94. }
  95. this.open = false;
  96. return waitForEvent(this, "sl-after-hide");
  97. }
  98. getTarget() {
  99. const target = [...this.children].find((el) => el.tagName.toLowerCase() !== "style" && el.getAttribute("slot") !== "content");
  100. if (!target) {
  101. throw new Error("Invalid tooltip target: no child element was found.");
  102. }
  103. return target;
  104. }
  105. handleBlur() {
  106. if (this.hasTrigger("focus")) {
  107. this.hide();
  108. }
  109. }
  110. handleClick() {
  111. if (this.hasTrigger("click")) {
  112. this.open ? this.hide() : this.show();
  113. }
  114. }
  115. handleFocus() {
  116. if (this.hasTrigger("focus")) {
  117. this.show();
  118. }
  119. }
  120. handleKeyDown(event2) {
  121. if (this.open && event2.key === "Escape") {
  122. event2.stopPropagation();
  123. this.hide();
  124. }
  125. }
  126. handleMouseOver() {
  127. if (this.hasTrigger("hover")) {
  128. const delay = parseDuration(getComputedStyle(this).getPropertyValue("--show-delay"));
  129. clearTimeout(this.hoverTimeout);
  130. this.hoverTimeout = setTimeout(() => this.show(), delay);
  131. }
  132. }
  133. handleMouseOut() {
  134. if (this.hasTrigger("hover")) {
  135. const delay = parseDuration(getComputedStyle(this).getPropertyValue("--hide-delay"));
  136. clearTimeout(this.hoverTimeout);
  137. this.hoverTimeout = setTimeout(() => this.hide(), delay);
  138. }
  139. }
  140. async handleOpenChange() {
  141. if (!this.hasInitialized || this.disabled) {
  142. return;
  143. }
  144. if (this.open) {
  145. this.slShow.emit();
  146. await stopAnimations(this.tooltip);
  147. if (this.popover) {
  148. this.popover.destroy();
  149. }
  150. this.popover = createPopper(this.target, this.positioner, {
  151. placement: this.placement,
  152. strategy: "absolute",
  153. modifiers: [
  154. {
  155. name: "flip",
  156. options: {
  157. boundary: "viewport"
  158. }
  159. },
  160. {
  161. name: "offset",
  162. options: {
  163. offset: [this.skidding, this.distance]
  164. }
  165. }
  166. ]
  167. });
  168. this.tooltip.hidden = false;
  169. const { keyframes, options } = getAnimation(this, "tooltip.show");
  170. await animateTo(this.tooltip, keyframes, options);
  171. this.slAfterShow.emit();
  172. } else {
  173. this.slHide.emit();
  174. await stopAnimations(this.tooltip);
  175. const { keyframes, options } = getAnimation(this, "tooltip.hide");
  176. await animateTo(this.tooltip, keyframes, options);
  177. this.tooltip.hidden = true;
  178. if (this.popover) {
  179. this.popover.destroy();
  180. }
  181. this.slAfterHide.emit();
  182. }
  183. }
  184. handleOptionsChange() {
  185. this.syncOptions();
  186. }
  187. handleDisabledChange() {
  188. if (this.disabled && this.open) {
  189. this.hide();
  190. }
  191. }
  192. handleSlotChange() {
  193. const oldTarget = this.target;
  194. const newTarget = this.getTarget();
  195. if (newTarget !== oldTarget) {
  196. if (oldTarget) {
  197. oldTarget.removeAttribute("aria-describedby");
  198. }
  199. newTarget.setAttribute("aria-describedby", this.componentId);
  200. }
  201. }
  202. hasTrigger(triggerType) {
  203. const triggers = this.trigger.split(" ");
  204. return triggers.includes(triggerType);
  205. }
  206. syncOptions() {
  207. if (this.popover) {
  208. this.popover.setOptions({
  209. placement: this.placement,
  210. strategy: "absolute",
  211. modifiers: [
  212. {
  213. name: "flip",
  214. options: {
  215. boundary: "viewport"
  216. }
  217. },
  218. {
  219. name: "offset",
  220. options: {
  221. offset: [this.skidding, this.distance]
  222. }
  223. }
  224. ]
  225. });
  226. }
  227. }
  228. render() {
  229. return T`
  230. <slot @slotchange=${this.handleSlotChange.bind(this)}></slot>
  231. <div class="tooltip-positioner">
  232. <div
  233. part="base"
  234. id=${this.componentId}
  235. class=${e2({
  236. tooltip: true,
  237. "tooltip--open": this.open
  238. })}
  239. role="tooltip"
  240. aria-hidden=${this.open ? "false" : "true"}
  241. >
  242. <slot name="content">${this.content}</slot>
  243. </div>
  244. </div>
  245. `;
  246. }
  247. };
  248. SlTooltip.styles = r(tooltip_default);
  249. __decorateClass([
  250. o(".tooltip-positioner")
  251. ], SlTooltip.prototype, "positioner", 2);
  252. __decorateClass([
  253. o(".tooltip")
  254. ], SlTooltip.prototype, "tooltip", 2);
  255. __decorateClass([
  256. e()
  257. ], SlTooltip.prototype, "content", 2);
  258. __decorateClass([
  259. e()
  260. ], SlTooltip.prototype, "placement", 2);
  261. __decorateClass([
  262. e({ type: Boolean, reflect: true })
  263. ], SlTooltip.prototype, "disabled", 2);
  264. __decorateClass([
  265. e({ type: Number })
  266. ], SlTooltip.prototype, "distance", 2);
  267. __decorateClass([
  268. e({ type: Boolean, reflect: true })
  269. ], SlTooltip.prototype, "open", 2);
  270. __decorateClass([
  271. e({ type: Number })
  272. ], SlTooltip.prototype, "skidding", 2);
  273. __decorateClass([
  274. e()
  275. ], SlTooltip.prototype, "trigger", 2);
  276. __decorateClass([
  277. event("sl-show")
  278. ], SlTooltip.prototype, "slShow", 2);
  279. __decorateClass([
  280. event("sl-after-show")
  281. ], SlTooltip.prototype, "slAfterShow", 2);
  282. __decorateClass([
  283. event("sl-hide")
  284. ], SlTooltip.prototype, "slHide", 2);
  285. __decorateClass([
  286. event("sl-after-hide")
  287. ], SlTooltip.prototype, "slAfterHide", 2);
  288. __decorateClass([
  289. watch("open")
  290. ], SlTooltip.prototype, "handleOpenChange", 1);
  291. __decorateClass([
  292. watch("placement"),
  293. watch("distance"),
  294. watch("skidding")
  295. ], SlTooltip.prototype, "handleOptionsChange", 1);
  296. __decorateClass([
  297. watch("disabled")
  298. ], SlTooltip.prototype, "handleDisabledChange", 1);
  299. SlTooltip = __decorateClass([
  300. n("sl-tooltip")
  301. ], SlTooltip);
  302. var tooltip_default2 = SlTooltip;
  303. setDefaultAnimation("tooltip.show", {
  304. keyframes: [
  305. { opacity: 0, transform: "scale(0.8)" },
  306. { opacity: 1, transform: "scale(1)" }
  307. ],
  308. options: { duration: 150, easing: "ease" }
  309. });
  310. setDefaultAnimation("tooltip.hide", {
  311. keyframes: [
  312. { opacity: 1, transform: "scale(1)" },
  313. { opacity: 0, transform: "scale(0.8)" }
  314. ],
  315. options: { duration: 150, easing: "ease" }
  316. });
  317. export {
  318. tooltip_default2 as tooltip_default
  319. };