2021-05-29 11:31:21 -07:00
|
|
|
<template>
|
2021-09-22 00:23:37 -07:00
|
|
|
<el-dialog
|
|
|
|
:visible="visible"
|
|
|
|
:before-close="closeDialog"
|
2021-10-18 20:57:49 -07:00
|
|
|
:class="{'dialog-wrapper': true, [$style.center]: center, scrollable: scrollable}"
|
2021-09-22 00:23:37 -07:00
|
|
|
:width="width"
|
|
|
|
:show-close="showClose"
|
|
|
|
:custom-class="getCustomClass()"
|
2021-10-18 20:57:49 -07:00
|
|
|
:close-on-click-modal="closeOnClickModal"
|
|
|
|
:close-on-press-escape="closeOnPressEscape"
|
2021-09-22 00:23:37 -07:00
|
|
|
:style="styles"
|
|
|
|
append-to-body
|
|
|
|
>
|
2021-10-18 20:57:49 -07:00
|
|
|
<template v-slot:title v-if="$scopedSlots.header">
|
2021-09-22 00:23:37 -07:00
|
|
|
<slot name="header" v-if="!loading" />
|
|
|
|
</template>
|
2021-10-18 20:57:49 -07:00
|
|
|
<template v-slot:title v-else-if="title">
|
|
|
|
<div :class="centerTitle ? $style.centerTitle : ''">
|
|
|
|
<div v-if="title">
|
|
|
|
<n8n-heading tag="h1" size="xlarge">{{title}}</n8n-heading>
|
|
|
|
</div>
|
|
|
|
<div v-if="subtitle" :class="$style.subtitle">
|
|
|
|
<n8n-heading tag="h3" size="small" color="text-light">{{subtitle}}</n8n-heading>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</template>
|
2021-09-22 00:23:37 -07:00
|
|
|
<div class="modal-content" @keydown.stop @keydown.enter="handleEnter" @keydown.esc="closeDialog">
|
|
|
|
<slot v-if="!loading" name="content"/>
|
2021-10-18 20:57:49 -07:00
|
|
|
<div :class="$style.loader" v-else>
|
2021-09-22 00:23:37 -07:00
|
|
|
<n8n-spinner />
|
2021-05-29 11:31:21 -07:00
|
|
|
</div>
|
2021-09-22 00:23:37 -07:00
|
|
|
</div>
|
2021-10-18 20:57:49 -07:00
|
|
|
<div v-if="!loading && $scopedSlots.footer" :class="$style.footer">
|
2021-09-22 00:23:37 -07:00
|
|
|
<slot name="footer" :close="closeDialog" />
|
2021-10-18 20:57:49 -07:00
|
|
|
</div>
|
2021-09-22 00:23:37 -07:00
|
|
|
</el-dialog>
|
2021-05-29 11:31:21 -07:00
|
|
|
</template>
|
|
|
|
|
|
|
|
<script lang="ts">
|
|
|
|
import Vue from "vue";
|
|
|
|
|
|
|
|
export default Vue.extend({
|
|
|
|
name: "Modal",
|
2021-09-22 00:23:37 -07:00
|
|
|
props: {
|
|
|
|
name: {
|
|
|
|
type: String,
|
|
|
|
},
|
|
|
|
title: {
|
|
|
|
type: String,
|
|
|
|
},
|
2021-10-18 20:57:49 -07:00
|
|
|
subtitle: {
|
|
|
|
type: String,
|
|
|
|
},
|
2021-09-22 00:23:37 -07:00
|
|
|
eventBus: {
|
|
|
|
type: Vue,
|
|
|
|
},
|
|
|
|
showClose: {
|
|
|
|
type: Boolean,
|
|
|
|
default: true,
|
|
|
|
},
|
|
|
|
loading: {
|
|
|
|
type: Boolean,
|
|
|
|
},
|
|
|
|
classic: {
|
|
|
|
type: Boolean,
|
|
|
|
},
|
|
|
|
beforeClose: {
|
|
|
|
type: Function,
|
|
|
|
},
|
|
|
|
customClass: {
|
|
|
|
type: String,
|
|
|
|
},
|
|
|
|
center: {
|
|
|
|
type: Boolean,
|
|
|
|
},
|
|
|
|
width: {
|
|
|
|
type: String,
|
|
|
|
default: '50%',
|
|
|
|
},
|
|
|
|
minWidth: {
|
|
|
|
type: String,
|
|
|
|
},
|
|
|
|
maxWidth: {
|
|
|
|
type: String,
|
|
|
|
},
|
|
|
|
height: {
|
|
|
|
type: String,
|
|
|
|
},
|
2021-10-18 20:57:49 -07:00
|
|
|
minHeight: {
|
|
|
|
type: String,
|
|
|
|
},
|
2021-09-22 00:23:37 -07:00
|
|
|
maxHeight: {
|
|
|
|
type: String,
|
|
|
|
},
|
|
|
|
scrollable: {
|
|
|
|
type: Boolean,
|
|
|
|
default: false,
|
|
|
|
},
|
2021-10-18 20:57:49 -07:00
|
|
|
centerTitle: {
|
|
|
|
type: Boolean,
|
|
|
|
default: false,
|
|
|
|
},
|
|
|
|
closeOnClickModal: {
|
|
|
|
type: Boolean,
|
|
|
|
default: true,
|
|
|
|
},
|
|
|
|
closeOnPressEscape: {
|
|
|
|
type: Boolean,
|
|
|
|
default: true,
|
|
|
|
},
|
2021-07-22 01:22:17 -07:00
|
|
|
},
|
2021-05-29 11:31:21 -07:00
|
|
|
mounted() {
|
|
|
|
window.addEventListener('keydown', this.onWindowKeydown);
|
|
|
|
|
|
|
|
if (this.$props.eventBus) {
|
|
|
|
this.$props.eventBus.$on('close', () => {
|
|
|
|
this.closeDialog();
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
const activeElement = document.activeElement as HTMLElement;
|
|
|
|
if (activeElement) {
|
|
|
|
activeElement.blur();
|
|
|
|
}
|
|
|
|
},
|
|
|
|
beforeDestroy() {
|
|
|
|
window.removeEventListener('keydown', this.onWindowKeydown);
|
|
|
|
},
|
|
|
|
methods: {
|
|
|
|
onWindowKeydown(event: KeyboardEvent) {
|
|
|
|
if (!this.isActive) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (event && event.keyCode === 13) {
|
|
|
|
this.handleEnter();
|
|
|
|
}
|
|
|
|
},
|
|
|
|
handleEnter() {
|
|
|
|
if (this.isActive) {
|
|
|
|
this.$emit('enter');
|
|
|
|
}
|
|
|
|
},
|
2021-07-22 01:22:17 -07:00
|
|
|
closeDialog(callback?: () => void) {
|
2021-09-11 01:15:36 -07:00
|
|
|
if (this.beforeClose) {
|
|
|
|
this.beforeClose(() => {
|
|
|
|
this.$store.commit('ui/closeTopModal');
|
|
|
|
if (typeof callback === 'function') {
|
|
|
|
callback();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2021-05-29 11:31:21 -07:00
|
|
|
this.$store.commit('ui/closeTopModal');
|
2021-08-29 04:36:17 -07:00
|
|
|
if (typeof callback === 'function') {
|
2021-07-22 01:22:17 -07:00
|
|
|
callback();
|
|
|
|
}
|
|
|
|
},
|
2021-09-11 01:15:36 -07:00
|
|
|
getCustomClass() {
|
|
|
|
let classes = this.$props.customClass || '';
|
|
|
|
|
|
|
|
if (this.$props.classic) {
|
|
|
|
classes = `${classes} classic`;
|
|
|
|
}
|
|
|
|
|
|
|
|
return classes;
|
|
|
|
},
|
2021-05-29 11:31:21 -07:00
|
|
|
},
|
|
|
|
computed: {
|
|
|
|
isActive(): boolean {
|
|
|
|
return this.$store.getters['ui/isModalActive'](this.$props.name);
|
|
|
|
},
|
2021-09-22 00:23:37 -07:00
|
|
|
visible(): boolean {
|
2021-05-29 11:31:21 -07:00
|
|
|
return this.$store.getters['ui/isModalOpen'](this.$props.name);
|
|
|
|
},
|
2021-09-22 00:23:37 -07:00
|
|
|
styles() {
|
|
|
|
const styles: {[prop: string]: string} = {};
|
|
|
|
if (this.height) {
|
|
|
|
styles['--dialog-height'] = this.height;
|
|
|
|
}
|
2021-10-18 20:57:49 -07:00
|
|
|
if (this.minHeight) {
|
|
|
|
styles['--dialog-min-height'] = this.minHeight;
|
|
|
|
}
|
2021-09-22 00:23:37 -07:00
|
|
|
if (this.maxHeight) {
|
|
|
|
styles['--dialog-max-height'] = this.maxHeight;
|
|
|
|
}
|
|
|
|
if (this.maxWidth) {
|
|
|
|
styles['--dialog-max-width'] = this.maxWidth;
|
|
|
|
}
|
|
|
|
if (this.minWidth) {
|
|
|
|
styles['--dialog-min-width'] = this.minWidth;
|
|
|
|
}
|
|
|
|
return styles;
|
|
|
|
},
|
2021-05-29 11:31:21 -07:00
|
|
|
},
|
|
|
|
});
|
|
|
|
</script>
|
|
|
|
|
|
|
|
<style lang="scss">
|
2021-09-11 01:15:36 -07:00
|
|
|
.dialog-wrapper {
|
2021-09-22 00:23:37 -07:00
|
|
|
.el-dialog {
|
|
|
|
display: flex;
|
|
|
|
flex-direction: column;
|
|
|
|
max-width: var(--dialog-max-width, 80%);
|
|
|
|
min-width: var(--dialog-min-width, 420px);
|
|
|
|
height: var(--dialog-height);
|
2021-10-18 20:57:49 -07:00
|
|
|
min-height: var(--dialog-min-height);
|
2021-09-22 00:23:37 -07:00
|
|
|
max-height: var(--dialog-max-height);
|
2021-05-29 11:31:21 -07:00
|
|
|
}
|
|
|
|
|
2021-09-22 00:23:37 -07:00
|
|
|
.el-dialog__body {
|
2021-09-11 01:15:36 -07:00
|
|
|
overflow: hidden;
|
2021-09-22 00:23:37 -07:00
|
|
|
display: flex;
|
|
|
|
flex-direction: column;
|
|
|
|
flex-grow: 1;
|
|
|
|
}
|
2021-09-11 01:15:36 -07:00
|
|
|
|
2021-09-22 00:23:37 -07:00
|
|
|
.modal-content {
|
|
|
|
overflow: hidden;
|
|
|
|
flex-grow: 1;
|
2021-09-11 01:15:36 -07:00
|
|
|
}
|
2021-09-22 00:23:37 -07:00
|
|
|
|
2021-10-18 20:57:49 -07:00
|
|
|
&.scrollable .modal-content {
|
|
|
|
overflow-y: auto;
|
|
|
|
}
|
2021-09-22 00:23:37 -07:00
|
|
|
}
|
2021-10-18 20:57:49 -07:00
|
|
|
</style>
|
2021-09-11 01:15:36 -07:00
|
|
|
|
2021-10-18 20:57:49 -07:00
|
|
|
<style lang="scss" module>
|
2021-09-22 00:23:37 -07:00
|
|
|
.center {
|
2021-05-29 11:31:21 -07:00
|
|
|
display: flex;
|
|
|
|
align-items: center;
|
|
|
|
justify-content: center;
|
|
|
|
}
|
2021-09-11 01:15:36 -07:00
|
|
|
|
|
|
|
.loader {
|
|
|
|
display: flex;
|
|
|
|
align-items: center;
|
|
|
|
justify-content: center;
|
|
|
|
color: var(--color-primary-tint-1);
|
|
|
|
font-size: 30px;
|
|
|
|
height: 80%;
|
|
|
|
}
|
2021-10-18 20:57:49 -07:00
|
|
|
|
|
|
|
.centerTitle {
|
|
|
|
text-align: center;
|
|
|
|
}
|
|
|
|
|
|
|
|
.subtitle {
|
|
|
|
margin-top: var(--spacing-2xs);
|
|
|
|
}
|
|
|
|
|
|
|
|
.footer {
|
|
|
|
margin-top: var(--spacing-l);
|
|
|
|
}
|
2021-08-21 05:11:32 -07:00
|
|
|
</style>
|