2021-01-30 17:17:04 +01:00
|
|
|
<template>
|
|
|
|
<div class="dropdown is-right is-active" ref="dropdown">
|
|
|
|
<div class="dropdown-trigger" @click="open = !open">
|
|
|
|
<slot name="trigger">
|
|
|
|
<icon :icon="triggerIcon" class="icon"/>
|
|
|
|
</slot>
|
|
|
|
</div>
|
|
|
|
<transition name="fade">
|
|
|
|
<div class="dropdown-menu" v-if="open">
|
|
|
|
<div class="dropdown-content">
|
|
|
|
<slot></slot>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</transition>
|
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<script>
|
|
|
|
import {closeWhenClickedOutside} from '@/helpers/closeWhenClickedOutside'
|
|
|
|
|
|
|
|
export default {
|
|
|
|
name: 'dropdown',
|
|
|
|
data() {
|
|
|
|
return {
|
|
|
|
open: false,
|
|
|
|
}
|
|
|
|
},
|
|
|
|
mounted() {
|
|
|
|
document.addEventListener('click', this.hide)
|
|
|
|
},
|
2021-08-19 21:36:09 +02:00
|
|
|
beforeUnmount() {
|
2021-01-30 17:17:04 +01:00
|
|
|
document.removeEventListener('click', this.hide)
|
|
|
|
},
|
|
|
|
props: {
|
|
|
|
triggerIcon: {
|
|
|
|
type: String,
|
|
|
|
default: 'ellipsis-h',
|
|
|
|
},
|
|
|
|
},
|
|
|
|
methods: {
|
|
|
|
hide(e) {
|
|
|
|
if (this.open) {
|
|
|
|
closeWhenClickedOutside(e, this.$refs.dropdown, () => {
|
|
|
|
this.open = false
|
2021-04-15 17:03:26 +02:00
|
|
|
this.$emit('close', e)
|
2021-01-30 17:17:04 +01:00
|
|
|
})
|
|
|
|
}
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
</script>
|