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">
|
2021-10-01 20:20:07 +02:00
|
|
|
<slot name="trigger" :close="close">
|
2021-01-30 17:17:04 +01:00
|
|
|
<icon :icon="triggerIcon" class="icon"/>
|
|
|
|
</slot>
|
|
|
|
</div>
|
|
|
|
<transition name="fade">
|
|
|
|
<div class="dropdown-menu" v-if="open">
|
|
|
|
<div class="dropdown-content">
|
2021-10-01 20:20:07 +02:00
|
|
|
<slot :close="close"></slot>
|
2021-01-30 17:17:04 +01:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</transition>
|
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<script>
|
|
|
|
import {closeWhenClickedOutside} from '@/helpers/closeWhenClickedOutside'
|
|
|
|
|
|
|
|
export default {
|
|
|
|
name: 'dropdown',
|
|
|
|
data() {
|
|
|
|
return {
|
|
|
|
open: false,
|
|
|
|
}
|
|
|
|
},
|
|
|
|
mounted() {
|
2021-10-01 20:20:07 +02:00
|
|
|
document.addEventListener('click', this.handleClickOutside)
|
2021-01-30 17:17:04 +01:00
|
|
|
},
|
2021-08-19 21:36:09 +02:00
|
|
|
beforeUnmount() {
|
2021-10-01 20:20:07 +02:00
|
|
|
document.removeEventListener('click', this.handleClickOutside)
|
2021-01-30 17:17:04 +01:00
|
|
|
},
|
|
|
|
props: {
|
|
|
|
triggerIcon: {
|
|
|
|
type: String,
|
|
|
|
default: 'ellipsis-h',
|
|
|
|
},
|
|
|
|
},
|
2021-08-23 21:18:12 +02:00
|
|
|
emits: ['close'],
|
2021-01-30 17:17:04 +01:00
|
|
|
methods: {
|
2021-10-01 20:20:07 +02:00
|
|
|
close() {
|
|
|
|
this.open = false
|
|
|
|
},
|
|
|
|
toggleOpen() {
|
|
|
|
this.open = !this.open
|
|
|
|
},
|
|
|
|
handleClickOutside(e) {
|
|
|
|
if (!this.open) {
|
|
|
|
return
|
2021-01-30 17:17:04 +01:00
|
|
|
}
|
2021-10-01 20:20:07 +02:00
|
|
|
closeWhenClickedOutside(e, this.$refs.dropdown, () => {
|
|
|
|
this.open = false
|
|
|
|
this.$emit('close', e)
|
|
|
|
})
|
2021-01-30 17:17:04 +01:00
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
</script>
|