2020-10-08 00:01:17 -04:00
|
|
|
<template>
|
2022-05-20 07:44:22 -04:00
|
|
|
<div v-click-away="onClickOutside" class="dropdown" :class="{ 'is-active': is_active }">
|
2020-10-08 00:01:17 -04:00
|
|
|
<div class="dropdown-trigger">
|
2022-05-20 07:44:22 -04:00
|
|
|
<button class="button" aria-haspopup="true" aria-controls="dropdown-menu" @click="is_active = !is_active">
|
|
|
|
<span v-text="option.name" />
|
|
|
|
<mdicon class="icon" name="chevron-down" size="16" />
|
2020-10-08 00:01:17 -04:00
|
|
|
</button>
|
|
|
|
</div>
|
2022-02-19 00:39:14 -05:00
|
|
|
<div id="dropdown-menu" class="dropdown-menu" role="menu">
|
2020-10-08 00:01:17 -04:00
|
|
|
<div class="dropdown-content">
|
2022-05-20 07:44:22 -04:00
|
|
|
<a v-for="option in options" :key="option.id" class="dropdown-item" :class="{ 'is-active': modelValue === option.id }" @click="select(option)" v-text="option.name" />
|
2020-10-08 00:01:17 -04:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<script>
|
|
|
|
export default {
|
|
|
|
name: 'DropdownMenu',
|
2022-02-19 00:18:01 -05:00
|
|
|
props: ['modelValue', 'options'],
|
|
|
|
emits: ['update:modelValue'],
|
2020-10-08 00:01:17 -04:00
|
|
|
|
2022-02-19 00:39:14 -05:00
|
|
|
data() {
|
2020-10-08 00:01:17 -04:00
|
|
|
return {
|
|
|
|
is_active: false
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2022-05-20 07:44:22 -04:00
|
|
|
computed: {
|
|
|
|
option: {
|
|
|
|
get() {
|
|
|
|
return this.options.find((option) => option.id === this.modelValue)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2020-10-08 00:01:17 -04:00
|
|
|
methods: {
|
2022-02-19 00:39:14 -05:00
|
|
|
onClickOutside(event) {
|
2020-10-08 00:01:17 -04:00
|
|
|
this.is_active = false
|
|
|
|
},
|
|
|
|
|
2022-02-19 00:39:14 -05:00
|
|
|
select(option) {
|
2020-10-08 00:01:17 -04:00
|
|
|
this.is_active = false
|
2022-05-20 07:44:22 -04:00
|
|
|
this.$emit('update:modelValue', option.id)
|
2020-10-08 00:01:17 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
</script>
|
|
|
|
|
2022-02-19 00:39:14 -05:00
|
|
|
<style></style>
|