Skip to content

Commit 79f9d2c

Browse files
committed
feat: add global tooltip component
1 parent d1af9c2 commit 79f9d2c

1 file changed

Lines changed: 47 additions & 0 deletions

File tree

app/components/AppTooltip.vue

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
<script setup lang="ts">
2+
const props = defineProps<{
3+
/** Tooltip text */
4+
text: string
5+
/** Position: 'top' | 'bottom' | 'left' | 'right' */
6+
position?: 'top' | 'bottom' | 'left' | 'right'
7+
}>()
8+
9+
const isVisible = ref(false)
10+
11+
const positionClasses: Record<string, string> = {
12+
top: 'bottom-full left-1/2 -translate-x-1/2 mb-1',
13+
bottom: 'top-full left-0 mt-1',
14+
left: 'right-full top-1/2 -translate-y-1/2 mr-2',
15+
right: 'left-full top-1/2 -translate-y-1/2 ml-2',
16+
}
17+
18+
const tooltipPosition = computed(() => positionClasses[props.position || 'bottom'])
19+
</script>
20+
21+
<template>
22+
<div
23+
class="relative inline-flex"
24+
@mouseenter="isVisible = true"
25+
@mouseleave="isVisible = false"
26+
@focus="isVisible = true"
27+
@blur="isVisible = false"
28+
>
29+
<slot />
30+
31+
<Transition
32+
enter-active-class="transition-opacity duration-150"
33+
leave-active-class="transition-opacity duration-100"
34+
enter-from-class="opacity-0"
35+
leave-to-class="opacity-0"
36+
>
37+
<div
38+
v-if="isVisible"
39+
role="tooltip"
40+
class="absolute px-2 py-1 font-mono text-xs text-fg bg-bg-elevated border border-border rounded shadow-lg whitespace-nowrap z-[100] pointer-events-none"
41+
:class="tooltipPosition"
42+
>
43+
{{ text }}
44+
</div>
45+
</Transition>
46+
</div>
47+
</template>

0 commit comments

Comments
 (0)