PteroTheme/resources/assets/scripts/components/core/Modal.vue

49 lines
1.3 KiB
Vue
Raw Normal View History

2019-02-10 05:14:58 +00:00
<template>
<transition name="modal">
<div class="modal-mask" v-show="show" v-on:click="close">
<div class="modal-container" @click.stop>
<div v-on:click="close">
<Icon name="x"
class="absolute pin-r pin-t m-2 text-neutral-500 cursor-pointer"
aria-label="Close modal"
role="button"
/>
</div>
<slot/>
</div>
</div>
</transition>
</template>
<script lang="ts">
import Vue from 'vue';
import Icon from "./Icon.vue";
export default Vue.extend({
name: 'Modal',
components: {Icon},
props: {
2019-02-10 05:15:45 +00:00
modalName: {type: String, default: 'modal'},
show: {type: Boolean, default: false},
closeOnEsc: {type: Boolean, default: true},
2019-02-10 05:14:58 +00:00
},
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);
}
},
});
</script>