opnform/client/components/global/transitions/Collapsible.vue

53 lines
977 B
Vue
Raw Permalink Normal View History

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