vikunja/frontend/src/components/misc/popup.vue

85 lines
1.2 KiB
Vue
Raw Normal View History

<template>
2024-02-07 11:18:19 +00:00
<slot
name="trigger"
2024-03-09 18:24:17 +00:00
:is-open="openValue"
2024-02-07 11:18:19 +00:00
:toggle="toggle"
:close="close"
/>
2022-10-17 11:45:03 +00:00
<div
2024-02-07 11:18:19 +00:00
ref="popup"
2022-10-17 11:45:03 +00:00
class="popup"
:class="{
2024-03-09 18:24:17 +00:00
'is-open': openValue,
'has-overflow': props.hasOverflow && openValue
2022-10-17 11:45:03 +00:00
}"
>
2024-02-07 11:18:19 +00:00
<slot
name="content"
2024-03-09 18:24:17 +00:00
:is-open="openValue"
2024-02-07 11:18:19 +00:00
:toggle="toggle"
:close="close"
/>
</div>
</template>
2022-02-15 12:07:34 +00:00
<script setup lang="ts">
import {ref, watch} from 'vue'
2022-10-17 11:45:03 +00:00
import {onClickOutside} from '@vueuse/core'
const props = defineProps({
hasOverflow: {
type: Boolean,
default: false,
2022-01-09 16:28:58 +00:00
},
open: {
type: Boolean,
default: false,
},
})
2024-03-09 18:24:17 +00:00
const emit = defineEmits(['close'])
watch(
() => props.open,
nowOpen => {
2024-03-09 18:24:17 +00:00
openValue.value = nowOpen
},
)
2024-03-09 18:24:17 +00:00
const openValue = ref(false)
2022-10-17 11:45:03 +00:00
const popup = ref<HTMLElement | null>(null)
2022-10-17 11:45:03 +00:00
function close() {
2024-03-09 18:24:17 +00:00
openValue.value = false
emit('close')
}
2022-10-17 11:45:03 +00:00
function toggle() {
2024-03-09 18:24:17 +00:00
openValue.value = !openValue.value
2022-10-17 11:45:03 +00:00
}
2022-10-17 11:45:03 +00:00
onClickOutside(popup, () => {
2024-03-09 18:24:17 +00:00
if (!openValue.value) {
2022-10-17 11:45:03 +00:00
return
}
close()
})
</script>
<style scoped lang="scss">
.popup {
transition: opacity $transition;
opacity: 0;
height: 0;
overflow: hidden;
position: absolute;
top: 1rem;
z-index: 100;
&.is-open {
opacity: 1;
height: auto;
}
}
</style>