feat: improve dropdown (#1788)

Co-authored-by: Dominik Pschenitschni <mail@celement.de>
Reviewed-on: https://kolaente.dev/vikunja/frontend/pulls/1788
Reviewed-by: konrad <k@knt.li>
Co-authored-by: Dominik Pschenitschni <dpschen@noreply.kolaente.de>
Co-committed-by: Dominik Pschenitschni <dpschen@noreply.kolaente.de>
This commit is contained in:
Dominik Pschenitschni 2022-04-18 17:28:43 +00:00 committed by konrad
parent e3483b1a5a
commit e0023b14e8
3 changed files with 49 additions and 57 deletions

View file

@ -33,8 +33,10 @@
<notifications/>
<div class="user">
<dropdown class="is-right" ref="usernameDropdown">
<template #trigger>
<template #trigger="{toggleOpen}">
<x-button
class="username-dropdown-trigger"
@click="toggleOpen()"
variant="secondary"
:shadow="false"
>
@ -203,16 +205,13 @@ $hamburger-menu-icon-width: 28px;
display: flex;
align-items: center;
:deep(.dropdown-trigger) {
.username-dropdown-trigger {
line-height: 1;
padding: 0 0.25rem;
height: 1rem;
.button {
padding: 0 0.25rem;
height: 1rem;
.icon {
width: .5rem;
}
.icon {
width: .5rem;
}
}
@ -254,7 +253,7 @@ $hamburger-menu-icon-width: 28px;
margin-right: var(--button-padding-horizontal);
}
:deep(.dropdown-trigger .button) {
.username-dropdown-trigger {
background: none;
&:focus:not(:active), &:active {

View file

@ -1,10 +1,11 @@
<template>
<div class="dropdown is-right is-active" ref="dropdown">
<div class="dropdown-trigger is-flex" @click="open = !open">
<slot name="trigger" :close="close">
<slot name="trigger" :close="close" :toggleOpen="toggleOpen">
<BaseButton class="dropdown-trigger is-flex" @click="toggleOpen">
<icon :icon="triggerIcon" class="icon"/>
</slot>
</div>
</BaseButton>
</slot>
<transition name="fade">
<div class="dropdown-menu" v-if="open">
<div class="dropdown-content">
@ -15,46 +16,42 @@
</div>
</template>
<script lang="ts">
import {defineComponent} from 'vue'
import {closeWhenClickedOutside} from '@/helpers/closeWhenClickedOutside'
<script setup lang="ts">
import {ref} from 'vue'
import {onClickOutside} from '@vueuse/core'
export default defineComponent({
name: 'dropdown',
data() {
return {
open: false,
}
},
mounted() {
document.addEventListener('click', this.handleClickOutside)
},
beforeUnmount() {
document.removeEventListener('click', this.handleClickOutside)
},
props: {
triggerIcon: {
type: String,
default: 'ellipsis-h',
},
},
emits: ['close'],
methods: {
close() {
this.open = false
},
toggleOpen() {
this.open = !this.open
},
handleClickOutside(e) {
if (!this.open) {
return
}
closeWhenClickedOutside(e, this.$refs.dropdown, () => {
this.open = false
this.$emit('close', e)
})
},
import BaseButton from '@/components/base/BaseButton.vue'
defineProps({
triggerIcon: {
type: String,
default: 'ellipsis-h',
},
})
const emit = defineEmits(['close'])
const open = ref(false)
function close() {
open.value = false
}
function toggleOpen() {
open.value = !open.value
}
const dropdown = ref()
onClickOutside(dropdown, (e: Event) => {
if (!open.value) {
return
}
close()
emit('close', e)
})
</script>
<style lang="scss" scoped>
.dropdown-menu .dropdown-content {
box-shadow: var(--shadow-md);
}
</style>

View file

@ -144,10 +144,6 @@ button.table {
margin-right: 4px;
}
.dropdown-menu .dropdown-content {
box-shadow: var(--shadow-md);
}
.is-strikethrough {
text-decoration: line-through;
}