Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 29 additions & 22 deletions app/components/Tooltip/Base.vue
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<script setup lang="ts">
import type { HTMLAttributes } from 'vue'
import type { Placement } from '@floating-ui/vue'
import { autoUpdate, flip, offset, shift, useFloating } from '@floating-ui/vue'

const props = defineProps<{
/** Tooltip text */
Expand All @@ -12,34 +14,39 @@ const props = defineProps<{
tooltipAttr?: HTMLAttributes
}>()

const positionClasses: Record<string, string> = {
top: 'bottom-full inset-is-1/2 -translate-x-1/2 mb-1',
bottom: 'top-full inset-is-0 mt-1',
left: 'inset-ie-full top-1/2 -translate-y-1/2 me-2',
right: 'inset-is-full top-1/2 -translate-y-1/2 ms-2',
}
const triggerRef = shallowRef<HTMLElement | null>(null)
const tooltipRef = shallowRef<HTMLElement | null>(null)
Comment thread
danielroe marked this conversation as resolved.
Outdated

const tooltipPosition = computed(() => positionClasses[props.position || 'bottom'])
const placement = computed<Placement>(() => props.position || 'bottom')

const { floatingStyles } = useFloating(triggerRef, tooltipRef, {
placement,
whileElementsMounted: autoUpdate,
middleware: [offset(4), flip(), shift({ padding: 8 })],
})
</script>

<template>
<div class="relative inline-flex">
<div ref="triggerRef" class="inline-flex">
<slot />

<Transition
enter-active-class="transition-opacity duration-150 motion-reduce:transition-none"
leave-active-class="transition-opacity duration-100 motion-reduce:transition-none"
enter-from-class="opacity-0"
leave-to-class="opacity-0"
>
<div
v-if="props.isVisible"
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"
:class="tooltipPosition"
v-bind="tooltipAttr"
<Teleport to="body">
<Transition
enter-active-class="transition-opacity duration-150 motion-reduce:transition-none"
leave-active-class="transition-opacity duration-100 motion-reduce:transition-none"
enter-from-class="opacity-0"
leave-to-class="opacity-0"
>
{{ text }}
</div>
</Transition>
<div
v-if="props.isVisible"
ref="tooltipRef"
class="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"
:style="floatingStyles"
v-bind="tooltipAttr"
>
{{ text }}
</div>
</Transition>
</Teleport>
</div>
</template>
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
"@atproto/lex": "0.0.13",
"@atproto/oauth-client-node": "^0.3.15",
"@deno/doc": "jsr:^0.189.1",
"@floating-ui/vue": "1.1.10",
"@iconify-json/carbon": "1.2.18",
"@iconify-json/lucide": "1.2.87",
"@iconify-json/simple-icons": "1.2.68",
Expand Down
3 changes: 3 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading