JSFiddle - React, Tailwind, and code Playground
by Christian Gambardella
HTML
<script src="https://cdn.jsdelivr.net/vue/1.0.24/vue.js"></script>
<!-- template for the confirmation component -->
<script type="x/template" id="confirmation-template">
<div class="confirmation-mask" v-show="show" transition="confirmation">
<div class="confirmation-wrapper">
<div class="confirmation-container">
<div class="confirmation-header">
<slot name="header">
default header
</slot>
</div>
<div class="confirmation-body">
<slot name="body">
default body
</slot>
</div>
<div class="confirmation-footer">
<slot name="footer">
default footer
<button class="confirmation-default-button"
@click="yes">
YES
</button>
<button class="confirmation-default-button"
@click="no">
NO
</button>
</slot>
</div>
</div>
</div>
</div>
</script>
<!-- app -->
<div id="app">
<button id="show-confirmation" @click="showConfirmation = true">Show Confirmation</button>
<!-- use the modal component, pass in the prop -->
<confirmation :show.sync="showConfirmation">
<!--
you can use custom content here to overwrite
default content
-->
<h3 slot="header">custom header</h3>
</confirmation>
</div>
CSS
.confirmation-mask {
position: fixed;
z-index: 9998;
top: 0;
left: 0;
width: 100%;
height: 100%;
background-color: rgba(0, 0, 0, .5);
display: table;
transition: opacity .3s ease;
}
.confirmation-wrapper {
display: table-cell;
vertical-align: middle;
}
.confirmation-container {
width: 300px;
margin: 0px auto;
padding: 20px 30px;
background-color: #fff;
border-radius: 2px;
box-shadow: 0 2px 8px rgba(0, 0, 0, .33);
transition: all .3s ease;
font-family: Helvetica, Arial, sans-serif;
}
.confirmation-header h3 {
margin-top: 0;
color: #42b983;
}
.confirmation-body {
margin: 20px 0;
}
.confirmation-default-button {
float: right;
}
/*
* the following styles are auto-applied to elements with
* v-transition="confirmation" when their visiblity is toggled
* by Vue.js.
*
* You can easily play with the confirmation transition by editing
* these styles.
*/
.confirmation-enter, .confirmation-leave {
opacity: 0;
}
.confirmation-enter .confirmation-container,
.confirmation-leave .confirmation-container {
-webkit-transform: scale(1.1);
transform: scale(1.1);
}
JavaScript
// register modal component
Vue.component('confirmation', {
template: '#confirmation-template',
props: {
show: {
type: Boolean,
required: true,
twoWay: true
}
},
methods: {
yes: function() {
alert('yes');
this.show = false;
},
no: function() {
alert('no');
this.show = false;
}
}
})
// start app
new Vue({
el: '#app',
data: {
showConfirmation: false
}
})