2022-12-18 00:31:19 +01:00
|
|
|
<template>
|
|
|
|
<div class="relative h-9 w-9" v-click-outside="clickOutsideObj">
|
2023-06-10 19:46:57 +02:00
|
|
|
<slot :disabled="disabled" :showMenu="showMenu" :clickShowMenu="clickShowMenu" :processing="processing">
|
|
|
|
<button v-if="!processing" type="button" :disabled="disabled" class="relative h-full w-full flex items-center justify-center shadow-sm pl-3 pr-3 text-left focus:outline-none cursor-pointer text-gray-100 hover:text-gray-200 rounded-full hover:bg-white/5" aria-haspopup="listbox" :aria-expanded="showMenu" @click.stop.prevent="clickShowMenu">
|
2024-07-08 18:36:37 +02:00
|
|
|
<span class="material-symbols" :class="iconClass">more_vert</span>
|
2023-04-14 01:03:39 +02:00
|
|
|
</button>
|
2023-06-10 19:46:57 +02:00
|
|
|
<div v-else class="h-full w-full flex items-center justify-center">
|
|
|
|
<widgets-loading-spinner />
|
|
|
|
</div>
|
2023-04-14 01:03:39 +02:00
|
|
|
</slot>
|
2022-12-18 00:31:19 +01:00
|
|
|
|
|
|
|
<transition name="menu">
|
2023-06-07 22:48:23 +02:00
|
|
|
<div v-show="showMenu" ref="menuWrapper" class="absolute right-0 mt-1 z-10 bg-bg border border-black-200 shadow-lg rounded-md py-1 focus:outline-none sm:text-sm" :style="{ width: menuWidth + 'px' }">
|
2022-12-18 00:31:19 +01:00
|
|
|
<template v-for="(item, index) in items">
|
2023-05-30 00:38:38 +02:00
|
|
|
<template v-if="item.subitems">
|
2023-06-10 22:46:12 +02:00
|
|
|
<div :key="index" class="flex items-center px-2 py-1.5 hover:bg-white/5 text-white text-xs cursor-default" :class="{ 'bg-white/5': mouseoverItemIndex == index }" @mouseover="mouseoverItem(index)" @mouseleave="mouseleaveItem(index)" @click.stop>
|
2023-05-30 00:38:38 +02:00
|
|
|
<p>{{ item.text }}</p>
|
|
|
|
</div>
|
2023-06-07 22:48:23 +02:00
|
|
|
<div
|
|
|
|
v-if="mouseoverItemIndex === index"
|
|
|
|
:key="`subitems-${index}`"
|
|
|
|
@mouseover="mouseoverSubItemMenu(index)"
|
|
|
|
@mouseleave="mouseleaveSubItemMenu(index)"
|
|
|
|
class="absolute bg-bg border rounded-b-md border-black-200 shadow-lg z-50 -ml-px py-1"
|
|
|
|
:class="openSubMenuLeft ? 'rounded-l-md' : 'rounded-r-md'"
|
|
|
|
:style="{ left: submenuLeftPos + 'px', top: index * 28 + 'px', width: submenuWidth + 'px' }"
|
|
|
|
>
|
2023-06-10 22:46:12 +02:00
|
|
|
<div v-for="(subitem, subitemindex) in item.subitems" :key="`subitem-${subitemindex}`" class="flex items-center px-2 py-1.5 hover:bg-white/5 text-white text-xs cursor-pointer" @click.stop="clickAction(subitem.action, subitem.data)">
|
2023-05-30 00:38:38 +02:00
|
|
|
<p>{{ subitem.text }}</p>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</template>
|
2023-06-10 22:46:12 +02:00
|
|
|
<div v-else :key="index" class="flex items-center px-2 py-1.5 hover:bg-white/5 text-white text-xs cursor-pointer" @click.stop="clickAction(item.action)">
|
2023-06-10 19:46:57 +02:00
|
|
|
<p class="text-left">{{ item.text }}</p>
|
2022-12-18 00:31:19 +01:00
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
</div>
|
|
|
|
</transition>
|
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<script>
|
|
|
|
export default {
|
|
|
|
props: {
|
|
|
|
disabled: Boolean,
|
|
|
|
items: {
|
|
|
|
type: Array,
|
|
|
|
default: () => []
|
2023-01-08 00:14:55 +01:00
|
|
|
},
|
|
|
|
iconClass: {
|
|
|
|
type: String,
|
|
|
|
default: ''
|
2023-04-14 01:03:39 +02:00
|
|
|
},
|
|
|
|
menuWidth: {
|
2023-06-07 22:48:23 +02:00
|
|
|
type: Number,
|
|
|
|
default: 192
|
2023-06-10 19:46:57 +02:00
|
|
|
},
|
|
|
|
processing: Boolean
|
2022-12-18 00:31:19 +01:00
|
|
|
},
|
|
|
|
data() {
|
|
|
|
return {
|
|
|
|
clickOutsideObj: {
|
|
|
|
handler: this.clickedOutside,
|
|
|
|
events: ['mousedown'],
|
|
|
|
isActive: true
|
|
|
|
},
|
2023-06-07 22:48:23 +02:00
|
|
|
submenuWidth: 144,
|
2023-05-30 00:38:38 +02:00
|
|
|
showMenu: false,
|
|
|
|
mouseoverItemIndex: null,
|
2023-06-07 22:48:23 +02:00
|
|
|
isOverSubItemMenu: false,
|
|
|
|
openSubMenuLeft: false
|
|
|
|
}
|
|
|
|
},
|
|
|
|
computed: {
|
|
|
|
submenuLeftPos() {
|
|
|
|
return this.openSubMenuLeft ? -(this.submenuWidth - 1) : this.menuWidth - 0.5
|
2022-12-18 00:31:19 +01:00
|
|
|
}
|
|
|
|
},
|
|
|
|
methods: {
|
2023-05-30 00:38:38 +02:00
|
|
|
mouseoverSubItemMenu(index) {
|
|
|
|
this.isOverSubItemMenu = true
|
|
|
|
},
|
|
|
|
mouseleaveSubItemMenu(index) {
|
|
|
|
setTimeout(() => {
|
|
|
|
if (this.isOverSubItemMenu && this.mouseoverItemIndex === index) this.mouseoverItemIndex = null
|
|
|
|
}, 1)
|
|
|
|
},
|
|
|
|
mouseoverItem(index) {
|
|
|
|
this.isOverSubItemMenu = false
|
|
|
|
this.mouseoverItemIndex = index
|
|
|
|
},
|
|
|
|
mouseleaveItem(index) {
|
|
|
|
setTimeout(() => {
|
|
|
|
if (this.isOverSubItemMenu) return
|
|
|
|
if (this.mouseoverItemIndex === index) this.mouseoverItemIndex = null
|
|
|
|
}, 1)
|
|
|
|
},
|
2022-12-18 00:31:19 +01:00
|
|
|
clickShowMenu() {
|
|
|
|
if (this.disabled) return
|
|
|
|
this.showMenu = !this.showMenu
|
2023-06-07 22:48:23 +02:00
|
|
|
this.$nextTick(() => {
|
|
|
|
const boundingRect = this.$refs.menuWrapper?.getBoundingClientRect()
|
|
|
|
if (boundingRect) {
|
|
|
|
this.openSubMenuLeft = window.innerWidth - boundingRect.x < this.menuWidth + this.submenuWidth + 5
|
|
|
|
}
|
|
|
|
})
|
2022-12-18 00:31:19 +01:00
|
|
|
},
|
|
|
|
clickedOutside() {
|
|
|
|
this.showMenu = false
|
|
|
|
},
|
2023-05-30 00:38:38 +02:00
|
|
|
clickAction(action, data) {
|
2022-12-18 00:31:19 +01:00
|
|
|
if (this.disabled) return
|
|
|
|
this.showMenu = false
|
2023-05-30 00:38:38 +02:00
|
|
|
this.$emit('action', { action, data })
|
2022-12-18 00:31:19 +01:00
|
|
|
}
|
|
|
|
},
|
|
|
|
mounted() {}
|
|
|
|
}
|
|
|
|
</script>
|