1
0
mirror of https://github.com/amir20/dozzle.git synced 2025-12-24 14:31:44 +01:00

feat: improves popup timing (#2166)

This commit is contained in:
Amir Raminfar
2023-05-02 09:09:13 -07:00
committed by GitHub
parent 764d176455
commit cfe616a79e
3 changed files with 28 additions and 4 deletions

View File

@@ -1,8 +1,8 @@
<template>
<div @mouseenter="onMouseEnter" @mouseleave="show = false" ref="trigger"><slot></slot></div>
<div @mouseenter="onMouseEnter" @mouseleave="onMouseLeave" ref="trigger"><slot></slot></div>
<Teleport to="body">
<Transition name="fade">
<div v-show="show && delayedShow" class="content" ref="content">
<div v-show="show && (delayedShow || glopbalShow)" class="content" ref="content">
<slot name="content"></slot>
</div>
</Transition>
@@ -10,14 +10,18 @@
</template>
<script lang="ts" setup>
import { refDebounced } from "@vueuse/core";
let show = ref(false);
import { globalShowPopup } from "@/composables/popup";
let glopbalShow = globalShowPopup();
let show = ref(glopbalShow.value);
let delayedShow = refDebounced(show, 1000);
let content: HTMLElement | null = $ref(null);
let trigger: HTMLElement | null = $ref(null);
function onMouseEnter(e: MouseEvent) {
show.value = true;
glopbalShow.value = true;
if (e.target && content && e.target instanceof Element) {
const { left, top, width } = e.target.getBoundingClientRect();
const x = left + width + 10;
@@ -27,6 +31,11 @@ function onMouseEnter(e: MouseEvent) {
content.style.top = `${y}px`;
}
}
function onMouseLeave() {
show.value = false;
glopbalShow.value = false;
}
</script>
<style scoped>