mirror of
https://github.com/ArthurDanjou/ui.git
synced 2026-02-02 21:27:54 +01:00
@@ -0,0 +1,41 @@
|
|||||||
|
<script setup lang="ts">
|
||||||
|
const open = ref(false)
|
||||||
|
const anchor = ref({ x: 0, y: 0 })
|
||||||
|
|
||||||
|
const reference = computed(() => ({
|
||||||
|
getBoundingClientRect: () =>
|
||||||
|
({
|
||||||
|
width: 0,
|
||||||
|
height: 0,
|
||||||
|
left: anchor.value.x,
|
||||||
|
right: anchor.value.x,
|
||||||
|
top: anchor.value.y,
|
||||||
|
bottom: anchor.value.y,
|
||||||
|
...anchor.value
|
||||||
|
} as DOMRect)
|
||||||
|
}))
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<template>
|
||||||
|
<UTooltip
|
||||||
|
:open="open"
|
||||||
|
:reference="reference"
|
||||||
|
:content="{ side: 'top', sideOffset: 16, updatePositionStrategy: 'always' }"
|
||||||
|
>
|
||||||
|
<div
|
||||||
|
class="flex items-center justify-center rounded-md border border-dashed border-accented text-sm aspect-video w-72"
|
||||||
|
@pointerenter="open = true"
|
||||||
|
@pointerleave="open = false"
|
||||||
|
@pointermove="(ev) => {
|
||||||
|
anchor.x = ev.clientX
|
||||||
|
anchor.y = ev.clientY
|
||||||
|
}"
|
||||||
|
>
|
||||||
|
Hover me
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<template #content>
|
||||||
|
{{ anchor.x.toFixed(0) }} - {{ anchor.y.toFixed(0) }}
|
||||||
|
</template>
|
||||||
|
</UTooltip>
|
||||||
|
</template>
|
||||||
@@ -186,6 +186,20 @@ name: 'tooltip-open-example'
|
|||||||
In this example, leveraging [`defineShortcuts`](/composables/define-shortcuts), you can toggle the Tooltip by pressing :kbd{value="O"}.
|
In this example, leveraging [`defineShortcuts`](/composables/define-shortcuts), you can toggle the Tooltip by pressing :kbd{value="O"}.
|
||||||
::
|
::
|
||||||
|
|
||||||
|
### With following cursor :badge{label="Soon" class="align-text-top"}
|
||||||
|
|
||||||
|
You can make the Tooltip follow the cursor when hovering over an element using the [`reference`](https://reka-ui.com/docs/components/tooltip#trigger) prop:
|
||||||
|
|
||||||
|
::component-example
|
||||||
|
---
|
||||||
|
name: 'tooltip-cursor-example'
|
||||||
|
---
|
||||||
|
::
|
||||||
|
|
||||||
|
::note
|
||||||
|
This example is based on Reka UI's [Tooltip Cursor](https://reka-ui.com/examples/tooltip-cursor) example.
|
||||||
|
::
|
||||||
|
|
||||||
## API
|
## API
|
||||||
|
|
||||||
### Props
|
### Props
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import type { TooltipRootProps, TooltipRootEmits, TooltipContentProps, TooltipContentEmits, TooltipArrowProps } from 'reka-ui'
|
import type { TooltipRootProps, TooltipRootEmits, TooltipContentProps, TooltipContentEmits, TooltipArrowProps, TooltipTriggerProps } from 'reka-ui'
|
||||||
import type { AppConfig } from '@nuxt/schema'
|
import type { AppConfig } from '@nuxt/schema'
|
||||||
import theme from '#build/ui/tooltip'
|
import theme from '#build/ui/tooltip'
|
||||||
import type { KbdProps } from '../types'
|
import type { KbdProps } from '../types'
|
||||||
@@ -27,6 +27,7 @@ export interface TooltipProps extends TooltipRootProps {
|
|||||||
* @defaultValue true
|
* @defaultValue true
|
||||||
*/
|
*/
|
||||||
portal?: boolean | string | HTMLElement
|
portal?: boolean | string | HTMLElement
|
||||||
|
reference?: TooltipTriggerProps['reference']
|
||||||
class?: any
|
class?: any
|
||||||
ui?: Tooltip['slots']
|
ui?: Tooltip['slots']
|
||||||
}
|
}
|
||||||
@@ -70,7 +71,7 @@ const ui = computed(() => tv({ extend: tv(theme), ...(appConfig.ui?.tooltip || {
|
|||||||
|
|
||||||
<template>
|
<template>
|
||||||
<TooltipRoot v-slot="{ open }" v-bind="rootProps">
|
<TooltipRoot v-slot="{ open }" v-bind="rootProps">
|
||||||
<TooltipTrigger v-if="!!slots.default" v-bind="$attrs" as-child :class="props.class">
|
<TooltipTrigger v-if="!!slots.default || !!reference" v-bind="$attrs" as-child :reference="reference" :class="props.class">
|
||||||
<slot :open="open" />
|
<slot :open="open" />
|
||||||
</TooltipTrigger>
|
</TooltipTrigger>
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user