-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
102 additions
and
28 deletions.
There are no files selected for viewing
54 changes: 54 additions & 0 deletions
54
holo-key-manager-extension/src/lib/components/HoverTooltip.svelte
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
<script lang="ts"> | ||
import { onMount } from 'svelte'; | ||
export let delay = 2000; | ||
export let tooltipText = ''; | ||
let showTooltip = false; | ||
let hovered = false; | ||
let tooltipTimeout: ReturnType<typeof setTimeout> | undefined; | ||
let tooltipPosition = { top: 0, left: 0 }; | ||
const handleMouseEnter = (event: MouseEvent) => { | ||
const target = event.currentTarget as HTMLElement; | ||
const rect = target.getBoundingClientRect(); | ||
tooltipPosition = { top: rect.bottom, left: rect.left }; | ||
tooltipTimeout = setTimeout(() => { | ||
hovered = true; | ||
showTooltip = true; | ||
}, delay); | ||
}; | ||
const handleMouseLeave = () => { | ||
if (tooltipTimeout) { | ||
clearTimeout(tooltipTimeout); | ||
} | ||
showTooltip = false; | ||
hovered = false; | ||
}; | ||
onMount(() => { | ||
return () => { | ||
if (tooltipTimeout) { | ||
clearTimeout(tooltipTimeout); | ||
} | ||
}; | ||
}); | ||
</script> | ||
|
||
<div | ||
on:mouseenter={handleMouseEnter} | ||
on:mouseleave={handleMouseLeave} | ||
class="relative cursor-pointer" | ||
role="tooltip" | ||
> | ||
<slot /> | ||
{#if showTooltip && hovered} | ||
<div | ||
class={`absolute z-50 max-w-[200px] rounded-lg border border-gray-300 bg-gray-100 p-2 text-xs text-gray-700 shadow-lg top-[${tooltipPosition.top}px] left-[${tooltipPosition.left}px]`} | ||
> | ||
<span class="break-words">{tooltipText}</span> | ||
</div> | ||
{/if} | ||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters