2
0
mirror of https://github.com/frappe/books.git synced 2024-09-21 03:39:02 +00:00
books/ui/components/Dropdown.vue

62 lines
1.4 KiB
Vue
Raw Normal View History

2018-07-14 14:41:31 +00:00
<template>
<div class="dropdown show" ref="dropdownMenu">
2018-07-15 07:00:47 +00:00
<button
:id="_uid"
2018-07-15 07:00:47 +00:00
class="btn btn-sm btn-light dropdown-toggle"
2018-07-14 15:01:44 +00:00
aria-haspopup="true"
2018-07-15 07:00:47 +00:00
:aria-expanded="isShown ? 'true' : 'false'"
@click="isShown = !isShown"
>
{{ label }}
2018-07-15 07:00:47 +00:00
</button>
<div :class="['dropdown-menu dropdown-menu-right', isShown ? 'show' : '']" :aria-labelledby="_uid">
<a
href="#"
class="dropdown-item"
2018-07-14 15:01:44 +00:00
v-for="option in options"
:key="option.label"
2018-07-15 07:00:47 +00:00
@click.prevent="option.handler"
>
{{ option.label }}
2018-07-14 15:01:44 +00:00
</a>
2018-07-14 14:41:31 +00:00
</div>
</div>
</template>
<script>
export default {
2018-07-15 07:00:47 +00:00
props: ['label', 'options'],
data() {
return {
isShown: false
}
},
methods:{
documentClick(e) {
let el = this.$refs.dropdownMenu;
let target = e.target;
if ((el !== target) && (!el.contains(target))) {
this.isShown = false;
}
}
},
created () {
document.addEventListener('click', this.documentClick);
},
destroyed () {
document.removeEventListener('click', this.documentClick);
}
};
2018-07-14 14:41:31 +00:00
</script>
2018-07-15 07:00:47 +00:00
<style lang="scss">
@import "../styles/variables.scss";
$dropdown-link-active-bg: $gray-300;
.dropdown-item {
&.active,
&:active {
@include gradient-bg($dropdown-link-active-bg);
}
}
2018-07-14 14:41:31 +00:00
</style>