1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
|
<script>
import { computePosition, autoUpdate, flip } from '@floating-ui/dom';
import NavItem from './nav_item.vue';
export default {
name: 'FlyoutMenu',
components: { NavItem },
props: {
targetId: {
type: String,
required: true,
},
items: {
type: Array,
required: true,
},
},
cleanupFunction: undefined,
mounted() {
const target = document.querySelector(`#${this.targetId}`);
const flyout = document.querySelector(`#${this.targetId}-flyout`);
function updatePosition() {
return computePosition(target, flyout, {
middleware: [flip()],
placement: 'right-start',
strategy: 'fixed',
}).then(({ x, y }) => {
Object.assign(flyout.style, {
left: `${x}px`,
top: `${y}px`,
});
});
}
this.$options.cleanupFunction = autoUpdate(target, flyout, updatePosition);
},
beforeUnmount() {
this.$options.cleanupFunction();
},
};
</script>
<template>
<div
:id="`${targetId}-flyout`"
class="gl-fixed gl-pl-3 gl-z-index-9999"
@mouseover="$emit('mouseover')"
@mouseleave="$emit('mouseleave')"
>
<ul
v-if="items.length > 0"
class="gl-min-w-20 gl-max-w-34 gl-border-1 gl-rounded-base gl-border-solid gl-border-gray-100 gl-shadow gl-bg-white gl-p-2 gl-pb-1 gl-list-style-none"
>
<nav-item
v-for="item of items"
:key="item.id"
:item="item"
:is-flyout="true"
@pin-add="(itemId) => $emit('pin-add', itemId)"
@pin-remove="(itemId) => $emit('pin-remove', itemId)"
/>
</ul>
</div>
</template>
|