diff --git a/src/App.vue b/src/App.vue index cda06c71..c43ddcdf 100644 --- a/src/App.vue +++ b/src/App.vue @@ -25,29 +25,35 @@ diff --git a/src/components/shared/SongItem.vue b/src/components/shared/SongItem.vue index 2e8983be..904c3331 100644 --- a/src/components/shared/SongItem.vue +++ b/src/components/shared/SongItem.vue @@ -25,7 +25,7 @@ :class="{ last_played: !isPlaying }" > -
+
{{ track.title }}
@@ -42,7 +42,7 @@
-
+
{{ track.title }}

diff --git a/src/directives/vTooltip.ts b/src/directives/vTooltip.ts index 89eccd6f..8e85367c 100644 --- a/src/directives/vTooltip.ts +++ b/src/directives/vTooltip.ts @@ -1,10 +1,45 @@ import { Directive } from "vue"; -import { createPopper } from "@popperjs/core"; +import { createPopper, Instance, VirtualElement } from "@popperjs/core"; let tooltip: HTMLElement; +let popperInstance: Instance; +let store: any; -function getTooltip() { - return document.getElementById("tooltip") as HTMLElement; +// @ts-ignore +const virtualEl = { + getBoundingClientRect: () => null, +} as VirtualElement; + +const getTooltip = () => document.getElementById("tooltip") as HTMLElement; + +function getInstance() { + if (tooltip && virtualEl) { + return createPopper(virtualEl, getTooltip(), { + placement: "top", + modifiers: [ + { + name: "offset", + options: { + offset: [0, 10], + }, + }, + { + name: "hide", + enabled: true, + }, + { + name: "eventListeners", + enabled: false, + }, + ], + }); + } + + return null; +} + +function showTooltip() { + tooltip.style.visibility = "visible"; } function hideTooltip() { @@ -12,37 +47,26 @@ function hideTooltip() { } export default { - mounted(el, binding) { - let isHovered = false; - - if (tooltip === undefined) { + mounted(el: HTMLElement, binding) { + if (!tooltip) { tooltip = getTooltip(); } + if (!popperInstance) { + popperInstance = getInstance() as Instance; + } + + let isHovered = false; + el.addEventListener("mouseover", () => { isHovered = true; setTimeout(() => { - if (isHovered) { - tooltip.innerText = binding.value; - tooltip.style.visibility = "visible"; + if (!isHovered) return; + tooltip.innerText = el.innerText; - createPopper(el, tooltip, { - placement: "top", - modifiers: [ - { - name: "offset", - options: { - offset: [0, 10], - }, - }, - { - name: "hide", - enabled: true, - }, - ], - }); - } + virtualEl.getBoundingClientRect = () => el.getBoundingClientRect(); + popperInstance.update().then(showTooltip); }, 1500); }); diff --git a/src/main.ts b/src/main.ts index dd6f0e2b..aee5679b 100644 --- a/src/main.ts +++ b/src/main.ts @@ -1,12 +1,13 @@ import "./assets/scss/index.scss"; -import { createPinia } from "pinia"; import { createApp } from "vue"; +import { createPinia } from "pinia"; import piniaPluginPersistedstate from "pinia-plugin-persistedstate"; -import vTooltip from "./directives/vTooltip"; + import App from "./App.vue"; import router from "./router"; +import vTooltip from "./directives/vTooltip"; const app = createApp(App); const pinia = createPinia(); @@ -16,4 +17,4 @@ app.use(pinia); app.use(router); app.directive("tooltip", vTooltip); -app.mount("#app"); +app.mount("#app")