This repository has been archived on 2024-07-22. You can view files and clone it, but cannot push or open issues or pull requests.
Zaimki/components/Dropdown.vue

52 lines
1.3 KiB
Vue
Raw Normal View History

2020-12-21 11:37:16 -08:00
<template>
<div class="dropdown">
<button :class="['btn dropdown-toggle', btnClass, shown ? 'show active' : '']"
@click.stop="shown = !shown"
>
<slot name="toggle">Dropdown</slot>
</button>
2021-05-13 03:09:08 -07:00
<ul :class="['dropdown-menu', end ? 'dropdown-menu-end' : '', shown ? 'show' : '']" >
2020-12-21 11:37:16 -08:00
<slot name="menu">
<li class="dropdown-item">Option</li>
</slot>
</ul>
</div>
</template>
<script>
export default {
props: {
btnClass: { 'default': 'btn-secondary' },
2021-05-13 03:09:08 -07:00
end: { type: Boolean },
2020-12-21 11:37:16 -08:00
},
data() {
return {
shown: false,
};
},
methods: {
documentClicked() {
if (this.shown) {
this.shown = false
}
},
},
created() {
if (process.client) {
document.addEventListener('click', this.documentClicked);
}
},
destroyed() {
if (process.client) {
document.removeEventListener('click', this.documentClicked);
}
},
}
</script>
2021-05-13 03:09:08 -07:00
<style lang="scss" scoped>
.dropdown-menu-end {
right: 0;
}
</style>