JSFiddle - React, Tailwind, and code Playground
by Kingdaro
HTML
<template id='overlay-template'>
<div class='outside' transition='fade' @click.self="$emit('close')">
<div class='inside' transition='fluid'>
<p>hello</p>
<button @click="$emit('close')">close</button>
</div>
</div>
</template>
<div id='app'>
<button @click="overlay = 'overlay'">show</button>
<component :is='overlay' @close="overlay = ''"></component>
</div>
CSS
.outside {
background-color: rgba(0, 0, 0, 0.25);
position: fixed;
left: 0;
top: 0;
right: 0;
bottom: 0;
display: flex;
justify-content: center;
align-items: center;
}
.inside {
background-color: white;
width: 100px;
height: 100px;
padding: 30px;
}
.fade-transition {
transition: 0.3s opacity;
opacity: 1;
}
.fade-enter, .fade-leave {
opacity: 0;
}
.fluid-transition {
transition: 0.3s transform;
transform: translateY(0px);
}
.fluid-enter, .fluid-leave {
transform: translateY(-20px);
}
JavaScript
Vue.component('overlay', {
template: '#overlay-template',
data () {
return { visible: true }
}
})
new Vue({
el: '#app',
data: {
overlay: ''
}
})