2018-12-30 21:10:16 +00:00
|
|
|
import Vue from 'vue';
|
|
|
|
import Icon from "./Icon";
|
|
|
|
|
|
|
|
export default Vue.component('modal', {
|
|
|
|
components: {
|
|
|
|
Icon,
|
|
|
|
},
|
|
|
|
|
|
|
|
props: {
|
|
|
|
modalName: { type: String, default: 'modal' },
|
|
|
|
show: { type: Boolean, default: false },
|
|
|
|
closeOnEsc: { type: Boolean, default: true },
|
|
|
|
},
|
|
|
|
|
|
|
|
mounted: function () {
|
|
|
|
if (this.$props.closeOnEsc) {
|
|
|
|
document.addEventListener('keydown', e => {
|
|
|
|
if (this.show && e.key === 'Escape') {
|
|
|
|
this.close();
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
methods: {
|
|
|
|
close: function () {
|
|
|
|
this.$emit('close', this.$props.modalName);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
template: `
|
|
|
|
<transition name="modal">
|
|
|
|
<div class="modal-mask" v-show="show" v-on:click="close">
|
|
|
|
<div class="modal-container" @click.stop>
|
2018-12-30 23:07:18 +00:00
|
|
|
<div v-on:click="close">
|
|
|
|
<icon name="x"
|
|
|
|
class="absolute pin-r pin-t m-2 text-grey cursor-pointer"
|
|
|
|
aria-label="Close modal"
|
|
|
|
role="button"
|
|
|
|
/>
|
|
|
|
</div>
|
2018-12-30 21:10:16 +00:00
|
|
|
<slot/>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</transition>
|
|
|
|
`
|
|
|
|
})
|