Skip to content

Instantly share code, notes, and snippets.

@toooni
Created August 23, 2024 14:00
Show Gist options
  • Save toooni/ef03df80d9e74794e7fee801f2d58ee9 to your computer and use it in GitHub Desktop.
Save toooni/ef03df80d9e74794e7fee801f2d58ee9 to your computer and use it in GitHub Desktop.
<template>
<div
v-if="exist || show"
class="grid ease-out transition-[grid-template-rows] duration-500"
:class="{
'grid-rows-[1fr]': deferredShow,
'grid-rows-[0fr]': !deferredShow,
}"
@transitionend="exist = show"
>
<div class="overflow-hidden" :class="childClass">
<slot />
</div>
</div>
</template>
<script setup>
const props = defineProps({
show: {
type: Boolean,
required: true,
},
childClass: {
type: [Array, Object, String],
default: null,
},
});
const exist = ref(props.show);
const deferredShow = ref(props.show);
watch(
() => props.show,
(newVal) => {
if (newVal === true) {
setTimeout(() => {
deferredShow.value = true;
}, 20);
} else {
deferredShow.value = false;
// fallback if for some reason transitionend event is not triggered
setTimeout(() => {
exist.value = false;
}, 800);
}
},
);
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment