2019-08-14 09:48:44 +00:00
|
|
|
<template>
|
|
|
|
<transition name="modal-fade">
|
2020-03-01 05:53:55 +00:00
|
|
|
<div
|
|
|
|
v-if="show"
|
2021-02-27 07:03:12 +00:00
|
|
|
:class="modalClassName"
|
2020-03-01 05:53:55 +00:00
|
|
|
transition="modal"
|
|
|
|
@click="onBackDropClick"
|
|
|
|
>
|
2020-10-25 18:58:23 +00:00
|
|
|
<div :class="modalContainerClassName" @click.stop>
|
2020-05-17 15:37:45 +00:00
|
|
|
<i class="ion-android-close modal--close" @click="close"></i>
|
2019-12-16 12:53:14 +00:00
|
|
|
<slot />
|
2019-08-14 09:48:44 +00:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</transition>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<script>
|
|
|
|
export default {
|
|
|
|
props: {
|
2020-02-29 12:13:49 +00:00
|
|
|
closeOnBackdropClick: {
|
|
|
|
type: Boolean,
|
|
|
|
default: true,
|
|
|
|
},
|
2019-08-14 09:48:44 +00:00
|
|
|
show: Boolean,
|
2020-02-29 12:13:49 +00:00
|
|
|
onClose: {
|
|
|
|
type: Function,
|
|
|
|
required: true,
|
|
|
|
},
|
2020-10-25 18:58:23 +00:00
|
|
|
fullWidth: {
|
|
|
|
type: Boolean,
|
|
|
|
default: false,
|
|
|
|
},
|
2021-02-27 07:03:12 +00:00
|
|
|
modalType: {
|
|
|
|
type: String,
|
|
|
|
default: 'centered',
|
|
|
|
},
|
2020-10-25 18:58:23 +00:00
|
|
|
},
|
|
|
|
computed: {
|
|
|
|
modalContainerClassName() {
|
|
|
|
let className = 'modal-container';
|
|
|
|
if (this.fullWidth) {
|
|
|
|
return `${className} modal-container--full-width`;
|
|
|
|
}
|
|
|
|
return className;
|
2020-02-29 12:13:49 +00:00
|
|
|
},
|
2021-02-27 07:03:12 +00:00
|
|
|
modalClassName() {
|
|
|
|
const modalClassNameMap = {
|
|
|
|
centered: '',
|
|
|
|
'right-aligned': 'right-aligned',
|
|
|
|
};
|
|
|
|
|
|
|
|
return `modal-mask ${modalClassNameMap[this.modalType] || ''}`;
|
|
|
|
},
|
2019-08-14 09:48:44 +00:00
|
|
|
},
|
|
|
|
mounted() {
|
2019-12-14 12:44:35 +00:00
|
|
|
document.addEventListener('keydown', e => {
|
2021-08-26 10:25:58 +00:00
|
|
|
if (this.show && e.code === 'Escape') {
|
2019-08-14 09:48:44 +00:00
|
|
|
this.onClose();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
},
|
2019-12-14 12:44:35 +00:00
|
|
|
methods: {
|
|
|
|
close() {
|
2020-03-01 05:53:55 +00:00
|
|
|
this.onClose();
|
|
|
|
},
|
|
|
|
onBackDropClick() {
|
2020-02-29 12:13:49 +00:00
|
|
|
if (this.closeOnBackdropClick) {
|
|
|
|
this.onClose();
|
|
|
|
}
|
2019-12-14 12:44:35 +00:00
|
|
|
},
|
|
|
|
},
|
2019-08-14 09:48:44 +00:00
|
|
|
};
|
|
|
|
</script>
|
2020-10-25 18:58:23 +00:00
|
|
|
|
2021-02-27 07:03:12 +00:00
|
|
|
<style scoped lang="scss">
|
2020-10-25 18:58:23 +00:00
|
|
|
.modal-container--full-width {
|
|
|
|
align-items: center;
|
|
|
|
border-radius: 0;
|
|
|
|
display: flex;
|
|
|
|
height: 100%;
|
|
|
|
justify-content: center;
|
|
|
|
width: 100%;
|
|
|
|
}
|
2021-02-27 07:03:12 +00:00
|
|
|
|
|
|
|
.modal-mask.right-aligned {
|
|
|
|
justify-content: flex-end;
|
|
|
|
|
|
|
|
.modal-container {
|
|
|
|
border-radius: 0;
|
|
|
|
height: 100%;
|
|
|
|
width: 48rem;
|
|
|
|
}
|
|
|
|
}
|
2020-10-25 18:58:23 +00:00
|
|
|
</style>
|