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,51 +1,46 @@
<template> <template>
<div class="mk-dialog" :class="{ iconOnly }" :style="{ pointerEvents: closing ? 'none' : 'auto' }"> <x-modal ref="modal" @closed="$store.commit('removeDialog', id)" @click="onBgClick" :showing="showing">
<transition :name="$store.state.device.animation ? 'bg-fade' : ''" appear> <div class="mk-dialog" :class="{ iconOnly }">
<div class="bg _modalBg" @click="onBgClick" v-if="!closing"></div> <template v-if="type == 'signin'">
</transition> <mk-signin/>
<transition :name="$store.state.device.animation ? 'dialog' : ''" appear @after-leave="$store.commit('removeDialog', id)"> </template>
<div class="main" v-if="!closing"> <template v-else>
<template v-if="type == 'signin'"> <div class="icon" v-if="icon">
<mk-signin/> <fa :icon="icon"/>
</template> </div>
<template v-else> <div class="icon" v-else-if="!input && !select && !user" :class="type">
<div class="icon" v-if="icon"> <fa :icon="faCheck" v-if="type === 'success'"/>
<fa :icon="icon"/> <fa :icon="faTimesCircle" v-if="type === 'error'"/>
</div> <fa :icon="faExclamationTriangle" v-if="type === 'warning'"/>
<div class="icon" v-else-if="!input && !select && !user" :class="type"> <fa :icon="faInfoCircle" v-if="type === 'info'"/>
<fa :icon="faCheck" v-if="type === 'success'"/> <fa :icon="faQuestionCircle" v-if="type === 'question'"/>
<fa :icon="faTimesCircle" v-if="type === 'error'"/> <fa :icon="faSpinner" pulse v-if="type === 'waiting'"/>
<fa :icon="faExclamationTriangle" v-if="type === 'warning'"/> </div>
<fa :icon="faInfoCircle" v-if="type === 'info'"/> <header v-if="title" v-html="title"></header>
<fa :icon="faQuestionCircle" v-if="type === 'question'"/> <header v-if="title == null && user">{{ $t('enterUsername') }}</header>
<fa :icon="faSpinner" pulse v-if="type === 'waiting'"/> <div class="body" v-if="text" v-html="text"></div>
</div> <mk-input v-if="input" v-model:value="inputValue" autofocus :type="input.type || 'text'" :placeholder="input.placeholder" @keydown="onInputKeydown"></mk-input>
<header v-if="title" v-html="title"></header> <mk-input v-if="user" v-model:value="userInputValue" autofocus @keydown="onInputKeydown"><template #prefix>@</template></mk-input>
<header v-if="title == null && user">{{ $t('enterUsername') }}</header> <mk-select v-if="select" v-model:value="selectedValue" autofocus>
<div class="body" v-if="text" v-html="text"></div> <template v-if="select.items">
<mk-input v-if="input" v-model:value="inputValue" autofocus :type="input.type || 'text'" :placeholder="input.placeholder" @keydown="onInputKeydown"></mk-input> <option v-for="item in select.items" :value="item.value">{{ item.text }}</option>
<mk-input v-if="user" v-model:value="userInputValue" autofocus @keydown="onInputKeydown"><template #prefix>@</template></mk-input> </template>
<mk-select v-if="select" v-model:value="selectedValue" autofocus> <template v-else>
<template v-if="select.items"> <optgroup v-for="groupedItem in select.groupedItems" :label="groupedItem.label">
<option v-for="item in select.items" :value="item.value">{{ item.text }}</option> <option v-for="item in groupedItem.items" :value="item.value">{{ item.text }}</option>
</template> </optgroup>
<template v-else> </template>
<optgroup v-for="groupedItem in select.groupedItems" :label="groupedItem.label"> </mk-select>
<option v-for="item in groupedItem.items" :value="item.value">{{ item.text }}</option> <div class="buttons" v-if="!iconOnly && (showOkButton || showCancelButton) && !actions">
</optgroup> <mk-button inline @click="ok" v-if="showOkButton" primary :autofocus="!input && !select && !user" :disabled="!canOk">{{ (showCancelButton || input || select || user) ? $t('ok') : $t('gotIt') }}</mk-button>
</template> <mk-button inline @click="cancel" v-if="showCancelButton || input || select || user">{{ $t('cancel') }}</mk-button>
</mk-select> </div>
<div class="buttons" v-if="!iconOnly && (showOkButton || showCancelButton) && !actions"> <div class="buttons" v-if="actions">
<mk-button inline @click="ok" v-if="showOkButton" primary :autofocus="!input && !select && !user" :disabled="!canOk">{{ (showCancelButton || input || select || user) ? $t('ok') : $t('gotIt') }}</mk-button> <mk-button v-for="action in actions" inline @click="() => { action.callback(); close(); }" :primary="action.primary" :key="action.text">{{ action.text }}</mk-button>
<mk-button inline @click="cancel" v-if="showCancelButton || input || select || user">{{ $t('cancel') }}</mk-button> </div>
</div> </template>
<div class="buttons" v-if="actions"> </div>
<mk-button v-for="action in actions" inline @click="() => { action.callback(); close(); }" :primary="action.primary" :key="action.text">{{ action.text }}</mk-button> </x-modal>
</div>
</template>
</div>
</transition>
</div>
</template> </template>
<script lang="ts"> <script lang="ts">
@ -57,9 +52,11 @@ import MkInput from './ui/input.vue';
import MkSelect from './ui/select.vue'; import MkSelect from './ui/select.vue';
import MkSignin from './signin.vue'; import MkSignin from './signin.vue';
import parseAcct from '../../misc/acct/parse'; import parseAcct from '../../misc/acct/parse';
import XModal from './modal.vue';
export default defineComponent({ export default defineComponent({
components: { components: {
XModal,
MkButton, MkButton,
MkInput, MkInput,
MkSelect, MkSelect,
@ -122,7 +119,7 @@ export default defineComponent({
data() { data() {
return { return {
closing: false, showing: true,
inputValue: this.input && this.input.default ? this.input.default : null, inputValue: this.input && this.input.default ? this.input.default : null,
userInputValue: 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, 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: { methods: {
done(canceled, result?) { done(canceled, result?) {
this.closing = true; this.showing = false;
this.$store.commit('dialogDone', { id: this.id, result: { canceled, result } }); this.$store.commit('dialogDone', { id: this.id, result: { canceled, result } });
}, },
@ -211,97 +208,68 @@ export default defineComponent({
</script> </script>
<style lang="scss" scoped> <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 { .mk-dialog {
display: flex; display: block;
align-items: center;
justify-content: center;
position: fixed; position: fixed;
z-index: 30000; margin: auto;
top: 0; padding: 32px;
left: 0; min-width: 320px;
width: 100%; max-width: 480px;
height: 100%; box-sizing: border-box;
width: calc(100% - 32px);
text-align: center;
background: var(--panel);
border-radius: var(--radius);
&.iconOnly > .main { &.iconOnly {
min-width: 0; min-width: 0;
width: initial; width: initial;
} }
> .main { > .icon {
display: block; font-size: 32px;
position: fixed;
margin: auto;
padding: 32px;
min-width: 320px;
max-width: 480px;
box-sizing: border-box;
width: calc(100% - 32px);
text-align: center;
background: var(--panel);
border-radius: var(--radius);
> .icon { &.success {
font-size: 32px; color: var(--accent);
&.success {
color: var(--accent);
}
&.error {
color: #ec4137;
}
&.warning {
color: #ecb637;
}
> * {
display: block;
margin: 0 auto;
}
& + header {
margin-top: 16px;
}
} }
> header { &.error {
margin: 0 0 8px 0; color: #ec4137;
font-weight: bold;
font-size: 20px;
& + .body {
margin-top: 8px;
}
} }
> .body { &.warning {
margin: 16px 0 0 0; color: #ecb637;
} }
> .buttons { > * {
display: block;
margin: 0 auto;
}
& + header {
margin-top: 16px; margin-top: 16px;
}
}
> * { > header {
margin: 0 8px; margin: 0 0 8px 0;
} font-weight: bold;
font-size: 20px;
& + .body {
margin-top: 8px;
}
}
> .body {
margin: 16px 0 0 0;
}
> .buttons {
margin-top: 16px;
> * {
margin: 0 8px;
} }
} }
} }

View File

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

View File

@ -1,5 +1,5 @@
<template> <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="ebkgoccj" :class="{ noPadding }" @keydown="onKeydown" :style="{ width: `${width}px`, height: `${height}px` }">
<div class="header"> <div class="header">
<button class="_button" v-if="withOkButton" @click="close()"><fa :icon="faTimes"/></button> <button class="_button" v-if="withOkButton" @click="close()"><fa :icon="faTimes"/></button>

View File

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