2019-02-10 05:14:58 +00:00
|
|
|
<template>
|
|
|
|
<transition name="modal">
|
2019-05-11 06:50:59 +01:00
|
|
|
<div class="modal-mask" v-show="isVisible" v-on:click="closeOnBackground && close()">
|
|
|
|
<div class="modal-container p-8" :class="{ 'full-screen': isFullScreen }" @click.stop>
|
|
|
|
<div class="modal-close-icon" v-on:click="close" v-if="dismissable && showCloseIcon">
|
|
|
|
<Icon name="x" aria-label="Close modal" role="button"/>
|
2019-02-10 05:14:58 +00:00
|
|
|
</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'},
|
2019-05-11 06:50:59 +01:00
|
|
|
isVisible: {type: Boolean, default: false},
|
2019-02-10 05:15:45 +00:00
|
|
|
closeOnEsc: {type: Boolean, default: true},
|
2019-02-17 01:15:56 +00:00
|
|
|
dismissable: {type: Boolean, default: true},
|
2019-05-11 06:50:59 +01:00
|
|
|
showCloseIcon: {type: Boolean, default: true},
|
|
|
|
isFullScreen: {type: Boolean, default: false},
|
|
|
|
closeOnBackground: {type: Boolean, default: true},
|
2019-02-10 05:14:58 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
mounted: function () {
|
2019-05-11 06:50:59 +01:00
|
|
|
if (this.$props.closeOnEsc) {
|
2019-02-10 05:14:58 +00:00
|
|
|
document.addEventListener('keydown', e => {
|
2019-05-11 06:50:59 +01:00
|
|
|
if (this.isVisible && e.key === 'Escape') {
|
2019-02-10 05:14:58 +00:00
|
|
|
this.close();
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
methods: {
|
|
|
|
close: function () {
|
2019-05-11 06:50:59 +01:00
|
|
|
if (!this.$props.dismissable) {
|
|
|
|
return;
|
2019-02-17 01:15:56 +00:00
|
|
|
}
|
2019-05-11 06:50:59 +01:00
|
|
|
|
|
|
|
this.$emit('close', this.$props.modalName);
|
2019-02-10 05:14:58 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
});
|
|
|
|
</script>
|