This commit is contained in:
syuilo 2020-09-05 21:52:36 +09:00
parent cb965feab4
commit 32c4b079ba
4 changed files with 115 additions and 156 deletions

View File

@ -1,10 +1,6 @@
<template>
<div class="mk-dialog" :class="{ iconOnly }" :style="{ pointerEvents: closing ? 'none' : 'auto' }">
<transition :name="$store.state.device.animation ? 'bg-fade' : ''" appear>
<div class="bg _modalBg" @click="onBgClick" v-if="!closing"></div>
</transition>
<transition :name="$store.state.device.animation ? 'dialog' : ''" appear @after-leave="$store.commit('removeDialog', id)">
<div class="main" v-if="!closing">
<x-modal ref="modal" @closed="$store.commit('removeDialog', id)" @click="onBgClick" :showing="showing">
<div class="mk-dialog" :class="{ iconOnly }">
<template v-if="type == 'signin'">
<mk-signin/>
</template>
@ -44,8 +40,7 @@
</div>
</template>
</div>
</transition>
</div>
</x-modal>
</template>
<script lang="ts">
@ -57,9 +52,11 @@ import MkInput from './ui/input.vue';
import MkSelect from './ui/select.vue';
import MkSignin from './signin.vue';
import parseAcct from '../../misc/acct/parse';
import XModal from './modal.vue';
export default defineComponent({
components: {
XModal,
MkButton,
MkInput,
MkSelect,
@ -122,7 +119,7 @@ export default defineComponent({
data() {
return {
closing: false,
showing: true,
inputValue: this.input && this.input.default ? this.input.default : null,
userInputValue: null,
selectedValue: this.select ? this.select.default ? this.select.default : this.select.items ? this.select.items[0].value : this.select.groupedItems[0].items[0].value : null,
@ -161,7 +158,7 @@ export default defineComponent({
methods: {
done(canceled, result?) {
this.closing = true;
this.showing = false;
this.$store.commit('dialogDone', { id: this.id, result: { canceled, result } });
},
@ -211,40 +208,7 @@ export default defineComponent({
</script>
<style lang="scss" scoped>
.dialog-enter-active, .dialog-leave-active {
transition: opacity 0.3s, transform 0.3s !important;
}
.dialog-enter-from, .dialog-leave-to {
opacity: 0;
transform: scale(0.9);
pointer-events: none;
}
.bg-fade-enter-active, .bg-fade-leave-active {
transition: opacity 0.3s !important;
}
.bg-fade-enter-from, .bg-fade-leave-to {
opacity: 0;
pointer-events: none;
}
.mk-dialog {
display: flex;
align-items: center;
justify-content: center;
position: fixed;
z-index: 30000;
top: 0;
left: 0;
width: 100%;
height: 100%;
&.iconOnly > .main {
min-width: 0;
width: initial;
}
> .main {
display: block;
position: fixed;
margin: auto;
@ -257,6 +221,11 @@ export default defineComponent({
background: var(--panel);
border-radius: var(--radius);
&.iconOnly {
min-width: 0;
width: initial;
}
> .icon {
font-size: 32px;
@ -303,6 +272,5 @@ export default defineComponent({
margin: 0 8px;
}
}
}
}
</style>

View File

@ -1,10 +1,10 @@
<template>
<div class="mk-modal" v-hotkey.global="keymap">
<div class="mk-modal" v-hotkey.global="keymap" :style="{ pointerEvents: showing ? 'auto' : 'none' }">
<transition :name="$store.state.device.animation ? 'bg-fade' : ''" appear>
<div class="bg _modalBg" ref="bg" v-if="show" @click="canClose ? close() : () => {}"></div>
<div class="bg _modalBg" ref="bg" v-if="showing" @click="$emit('click')"></div>
</transition>
<transition :name="$store.state.device.animation ? 'modal' : ''" appear @after-leave="() => { $emit('closed'); destroyDom(); }">
<div class="content" ref="content" v-if="show" @click.self="canClose ? close() : () => {}"><slot></slot></div>
<transition :name="$store.state.device.animation ? 'modal' : ''" appear @after-leave="$emit('closed')">
<div class="content" ref="content" v-if="showing" @click.self="$emit('click')"><slot></slot></div>
</transition>
</div>
</template>
@ -13,32 +13,25 @@
import { defineComponent } from 'vue';
export default defineComponent({
emits: ['click', 'esc'],
props: {
showing: {
type: Boolean,
required: true,
},
canClose: {
type: Boolean,
required: false,
default: true,
},
},
data() {
return {
show: true,
};
},
computed: {
keymap(): any {
return {
'esc': this.close,
'esc': () => this.$emit('esc'),
};
},
},
methods: {
close() {
this.show = false;
(this.$refs.bg as any).style.pointerEvents = 'none';
(this.$refs.content as any).style.pointerEvents = 'none';
}
}
});
</script>
@ -46,7 +39,8 @@ export default defineComponent({
.modal-enter-active, .modal-leave-active {
transition: opacity 0.3s, transform 0.3s !important;
}
.modal-enter, .modal-leave-to {
.modal-enter-from, .modal-leave-to {
pointer-events: none;
opacity: 0;
transform: scale(0.9);
}
@ -54,7 +48,7 @@ export default defineComponent({
.bg-fade-enter-active, .bg-fade-leave-active {
transition: opacity 0.3s !important;
}
.bg-fade-enter, .bg-fade-leave-to {
.bg-fade-enter-from, .bg-fade-leave-to {
opacity: 0;
}
@ -73,18 +67,9 @@ export default defineComponent({
max-width: calc(100% - 16px);
max-height: calc(100% - 16px);
overflow: auto;
margin: auto;
::v-deep > * {
position: absolute;
top: 0;
bottom: 0;
left: 0;
right: 0;
margin: auto;
max-height: 100%;
max-width: 100%;
}
display: flex;
justify-content: center;
align-items: center;
}
}
</style>

View File

@ -1,5 +1,5 @@
<template>
<x-modal ref="modal" @closed="() => { $emit('closed'); destroyDom(); }" :can-close="canClose">
<x-modal ref="modal" @closed="$emit('closed')" :can-close="canClose">
<div class="ebkgoccj" :class="{ noPadding }" @keydown="onKeydown" :style="{ width: `${width}px`, height: `${height}px` }">
<div class="header">
<button class="_button" v-if="withOkButton" @click="close()"><fa :icon="faTimes"/></button>

View File

@ -14,6 +14,9 @@
<mk-switch v-model:value="dialogCancel">
<span>With cancel button</span>
</mk-switch>
<mk-switch v-model:value="dialogCancelByBgClick">
<span>Can cancel by modal bg click</span>
</mk-switch>
<mk-switch v-model:value="dialogInput">
<span>With input field</span>
</mk-switch>
@ -51,6 +54,7 @@ export default defineComponent({
dialogTitle: 'Hello',
dialogBody: 'World!',
dialogCancel: false,
dialogCancelByBgClick: true,
dialogInput: false,
dialogResult: null,
faExclamationTriangle
@ -59,10 +63,12 @@ export default defineComponent({
methods: {
async showDialog() {
this.dialogResult = null;
this.dialogResult = await this.$store.dispatch('showDialog', {
title: this.dialogTitle,
text: this.dialogBody,
showCancelButton: this.dialogCancel,
cancelableByBgClick: this.dialogCancelByBgClick,
input: this.dialogInput ? {} : null
});
}