2021-11-13 19:48:06 +00:00
|
|
|
<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"
|
|
|
|
/>
|
2021-11-13 19:48:06 +00:00
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
|
2022-02-15 12:07:34 +00:00
|
|
|
<script setup lang="ts">
|
2024-02-17 16:48:22 +00:00
|
|
|
import {ref, watch} from 'vue'
|
2022-10-17 11:45:03 +00:00
|
|
|
import {onClickOutside} from '@vueuse/core'
|
2021-11-13 19:48:06 +00:00
|
|
|
|
2022-01-09 16:27:28 +00:00
|
|
|
const props = defineProps({
|
|
|
|
hasOverflow: {
|
|
|
|
type: Boolean,
|
|
|
|
default: false,
|
2022-01-09 16:28:58 +00:00
|
|
|
},
|
2024-02-17 16:48:22 +00:00
|
|
|
open: {
|
|
|
|
type: Boolean,
|
|
|
|
default: false,
|
|
|
|
},
|
2022-01-09 16:27:28 +00:00
|
|
|
})
|
|
|
|
|
2024-03-09 18:24:17 +00:00
|
|
|
const emit = defineEmits(['close'])
|
|
|
|
|
2024-02-17 16:48:22 +00:00
|
|
|
watch(
|
|
|
|
() => props.open,
|
|
|
|
nowOpen => {
|
2024-03-09 18:24:17 +00:00
|
|
|
openValue.value = nowOpen
|
2024-02-17 16:48:22 +00:00
|
|
|
},
|
|
|
|
)
|
|
|
|
|
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)
|
2021-11-13 19:48:06 +00:00
|
|
|
|
2022-10-17 11:45:03 +00:00
|
|
|
function close() {
|
2024-03-09 18:24:17 +00:00
|
|
|
openValue.value = false
|
2023-06-09 12:23:32 +00:00
|
|
|
emit('close')
|
2021-11-13 19:48:06 +00:00
|
|
|
}
|
|
|
|
|
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
|
|
|
}
|
2021-11-13 19:48:06 +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()
|
2021-11-13 19:48:06 +00:00
|
|
|
})
|
|
|
|
</script>
|
|
|
|
|
|
|
|
<style scoped lang="scss">
|
|
|
|
.popup {
|
|
|
|
transition: opacity $transition;
|
|
|
|
opacity: 0;
|
|
|
|
height: 0;
|
|
|
|
overflow: hidden;
|
|
|
|
position: absolute;
|
|
|
|
top: 1rem;
|
2024-01-26 20:22:51 +00:00
|
|
|
z-index: 100;
|
2021-11-13 19:48:06 +00:00
|
|
|
|
|
|
|
&.is-open {
|
|
|
|
opacity: 1;
|
|
|
|
height: auto;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
</style>
|