opnform-host-nginx/client/components/global/transitions/Collapsible.vue

56 lines
1008 B
Vue
Raw Normal View History

2023-12-09 15:47:03 +01:00
<template>
2023-12-20 13:42:43 +01:00
<transition @leave="onLeave">
2023-12-09 15:47:03 +01:00
<div
v-if="modelValue"
ref="collapsible"
2023-12-20 13:42:43 +01:00
v-on-click-outside.bubble="onClickAway"
2023-12-09 15:47:03 +01:00
>
<slot />
2023-12-09 15:47:03 +01:00
</div>
</transition>
</template>
2023-12-19 16:45:23 +01:00
<script setup>
import { vOnClickOutside } from "@vueuse/components"
2023-12-09 15:47:03 +01:00
2023-12-19 16:45:23 +01:00
const props = defineProps({
modelValue: { type: Boolean },
maxHeight: { type: Number, default: 200 },
2023-12-19 16:45:23 +01:00
})
const emit = defineEmits(["click-away"])
2023-12-19 16:45:23 +01:00
2023-12-20 13:42:43 +01:00
const motion = ref(null)
const collapsible = ref(null)
const variants = {
2023-12-19 16:45:23 +01:00
initial: {
opacity: 0,
y: -10,
transition: { duration: 75, ease: "easeIn" },
2023-12-09 15:47:03 +01:00
},
2023-12-20 13:42:43 +01:00
enter: {
opacity: 1,
y: 0,
transition: { duration: 150, ease: "easeOut" },
},
2023-12-20 13:42:43 +01:00
}
watch(
() => props.modelValue,
(newValue) => {
if (newValue) {
nextTick(() => {
motion.value = useMotion(collapsible.value, variants)
})
}
},
)
2023-12-20 13:42:43 +01:00
const onLeave = (el, done) => {
motion.value.leave(done)
}
const onClickAway = (event) => {
emit("click-away", event)
2023-12-09 15:47:03 +01:00
}
</script>