59 lines
1.2 KiB
Svelte
59 lines
1.2 KiB
Svelte
<script lang="ts">
|
|
import { onMount, onDestroy } from "svelte";
|
|
export let text: string;
|
|
|
|
let isVisible: boolean = false;
|
|
let timer: number;
|
|
|
|
function showTooltip() {
|
|
isVisible = true;
|
|
timer = setTimeout(() => {
|
|
isVisible = false;
|
|
}, 2000);
|
|
}
|
|
|
|
function hideTooltip() {
|
|
isVisible = false;
|
|
clearTimeout(timer);
|
|
}
|
|
|
|
onDestroy(() => {
|
|
clearTimeout(timer);
|
|
});
|
|
</script>
|
|
|
|
<div class="tooltip" on:touchstart={showTooltip} on:touchend={hideTooltip} on:touchcancel={hideTooltip}>
|
|
<slot />
|
|
<span class="tooltiptext">{text}</span>
|
|
</div>
|
|
|
|
<style>
|
|
.tooltip {
|
|
position: relative;
|
|
display: inline-block;
|
|
cursor: pointer;
|
|
}
|
|
|
|
.tooltip .tooltiptext {
|
|
visibility: hidden;
|
|
width: 120px;
|
|
background-color: var(--island-button-color);
|
|
color: #fff;
|
|
text-align: center;
|
|
border-radius: 6px;
|
|
padding: 5px;
|
|
position: absolute;
|
|
z-index: 1;
|
|
bottom: 125%;
|
|
left: 50%;
|
|
margin-left: -60px;
|
|
opacity: 0;
|
|
transition: opacity 0.3s;
|
|
}
|
|
|
|
.tooltip:hover .tooltiptext {
|
|
visibility: visible;
|
|
opacity: 1;
|
|
}
|
|
</style>
|