feat(ui): enable links on Popover items
This commit is contained in:
parent
c2dcd6cdba
commit
7162f496fa
|
@ -1,10 +1,14 @@
|
||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import { inject, ref } from 'vue'
|
import { computed, inject, ref } from 'vue'
|
||||||
|
import { type RouterLinkProps, RouterLink } from 'vue-router'
|
||||||
import { POPOVER_CONTEXT_INJECTION_KEY, type PopoverContext } from '~/injection-keys'
|
import { POPOVER_CONTEXT_INJECTION_KEY, type PopoverContext } from '~/injection-keys'
|
||||||
|
|
||||||
const emit = defineEmits<{'internal:id': [value: number]}>()
|
const emit = defineEmits<{'internal:id': [value: number]}>()
|
||||||
|
|
||||||
const { parentPopoverContext } = defineProps<{ parentPopoverContext?: PopoverContext }>()
|
const { parentPopoverContext, to } = defineProps<{
|
||||||
|
parentPopoverContext?: PopoverContext;
|
||||||
|
to?:RouterLinkProps['to'];
|
||||||
|
}>()
|
||||||
const { items, hoveredItem } = parentPopoverContext ?? inject(POPOVER_CONTEXT_INJECTION_KEY, {
|
const { items, hoveredItem } = parentPopoverContext ?? inject(POPOVER_CONTEXT_INJECTION_KEY, {
|
||||||
items: ref(0),
|
items: ref(0),
|
||||||
hoveredItem: ref(-2)
|
hoveredItem: ref(-2)
|
||||||
|
@ -15,7 +19,27 @@ emit('internal:id', id)
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
<div
|
<a v-if="to && typeof to === 'string' && to.startsWith('http')"
|
||||||
|
:href="to.toString()"
|
||||||
|
class="popover-item"
|
||||||
|
target="_blank"
|
||||||
|
>
|
||||||
|
<slot />
|
||||||
|
|
||||||
|
<div class="after" />
|
||||||
|
<slot name="after" />
|
||||||
|
</a>
|
||||||
|
<RouterLink v-else-if="to"
|
||||||
|
:to="to"
|
||||||
|
class="popover-item"
|
||||||
|
@mouseover="hoveredItem = id"
|
||||||
|
>
|
||||||
|
<slot />
|
||||||
|
|
||||||
|
<div class="after" />
|
||||||
|
<slot name="after" />
|
||||||
|
</RouterLink>
|
||||||
|
<div v-else
|
||||||
@mouseover="hoveredItem = id"
|
@mouseover="hoveredItem = id"
|
||||||
class="popover-item"
|
class="popover-item"
|
||||||
>
|
>
|
||||||
|
|
|
@ -449,6 +449,10 @@ const open = ref(false)
|
||||||
</template>
|
</template>
|
||||||
</Popover>
|
</Popover>
|
||||||
|
|
||||||
|
## Links
|
||||||
|
|
||||||
|
You can use `PopoverItem`s as Links by providing a `to` prop with the route object or and external Url (`http...`). Read more on the [Link component](./link) page.
|
||||||
|
|
||||||
## Menu
|
## Menu
|
||||||
|
|
||||||
Here is an example of a completed menu containing all supported features.
|
Here is an example of a completed menu containing all supported features.
|
||||||
|
|
Loading…
Reference in New Issue