You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
37 lines
699 B
37 lines
699 B
![]()
1 year ago
|
<script setup>
|
||
|
import { ref, watch } from 'vue'
|
||
|
|
||
|
const props = defineProps({
|
||
|
visible: {
|
||
|
type: Boolean,
|
||
|
default: false,
|
||
|
},
|
||
|
position: {
|
||
|
type: Object,
|
||
|
default: () => ({ x: 0, y: 0 }),
|
||
|
}
|
||
|
})
|
||
|
|
||
|
const emit = defineEmits(['close'])
|
||
|
|
||
|
const handleClickOutside = (event) => {
|
||
|
emit('close')
|
||
|
}
|
||
|
|
||
|
watch(() => props.visible, (newVal) => {
|
||
|
if (newVal) {
|
||
|
setTimeout(() => {
|
||
|
document.addEventListener('click', handleClickOutside)
|
||
|
}, 0)
|
||
|
} else {
|
||
|
document.removeEventListener('click', handleClickOutside)
|
||
|
}
|
||
|
})
|
||
|
</script>
|
||
|
|
||
|
<template>
|
||
|
<div class="context-menu" v-if="visible" :style="{ top: `${position.y}px`, left: `${position.x}px` }">
|
||
|
<slot />
|
||
|
</div>
|
||
|
</template>
|