Last active
April 26, 2017 05:59
-
-
Save phillip-haydon/2a7029df9789b9838f3948daeb551023 to your computer and use it in GitHub Desktop.
custom modal component vue
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<template> | |
<div id="modal" v-bind:class="{ 'show': show }"> | |
<div class="modal-dialog"> | |
<div class="modal-content"> | |
<div></div> | |
</div> | |
</div> | |
<button v-on:click="$bus.$emit('hide-tm')">Close</button> | |
</div> | |
</template> | |
<script> | |
export default { | |
name: 'custom-modal', | |
data() { | |
return { | |
show: false, | |
currentComponent: null, | |
blankDiv: global.window.document.createElement('DIV') | |
} | |
}, | |
created() { | |
this.$bus.$on('show-tm', (componentName, data = {}) => { | |
this.show = true | |
let Component = this.$options.components[componentName] | |
this.currentComponent = new Component({ | |
el: this.$el.querySelector('div.modal-content > div'), | |
parent: this, | |
data: data | |
}) | |
}) | |
this.$bus.$on('hide-tm', () => { | |
this.show = false | |
this.currentComponent = {} | |
this.$el.replaceChild(this.blankDiv, this.$el.querySelector('div.modal-content > div')) | |
}) | |
}, | |
components: [] | |
} | |
</script> | |
<style lang="scss"> | |
div#modal { | |
position: fixed; | |
top: 0; | |
left: 0; | |
bottom: 0; | |
right: 0; | |
width: 100%; | |
height: 100%; | |
background: rgba(0,0,0,0.3); | |
opacity: 0; | |
visibility: hidden; | |
transition: opacity 200ms ease-in; | |
&.show { | |
opacity: 1; | |
visibility: visible; | |
} | |
} | |
</style> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment