wip
This commit is contained in:
parent
cb965feab4
commit
32c4b079ba
|
@ -1,51 +1,46 @@
|
|||
<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">
|
||||
<template v-if="type == 'signin'">
|
||||
<mk-signin/>
|
||||
</template>
|
||||
<template v-else>
|
||||
<div class="icon" v-if="icon">
|
||||
<fa :icon="icon"/>
|
||||
</div>
|
||||
<div class="icon" v-else-if="!input && !select && !user" :class="type">
|
||||
<fa :icon="faCheck" v-if="type === 'success'"/>
|
||||
<fa :icon="faTimesCircle" v-if="type === 'error'"/>
|
||||
<fa :icon="faExclamationTriangle" v-if="type === 'warning'"/>
|
||||
<fa :icon="faInfoCircle" v-if="type === 'info'"/>
|
||||
<fa :icon="faQuestionCircle" v-if="type === 'question'"/>
|
||||
<fa :icon="faSpinner" pulse v-if="type === 'waiting'"/>
|
||||
</div>
|
||||
<header v-if="title" v-html="title"></header>
|
||||
<header v-if="title == null && user">{{ $t('enterUsername') }}</header>
|
||||
<div class="body" v-if="text" v-html="text"></div>
|
||||
<mk-input v-if="input" v-model:value="inputValue" autofocus :type="input.type || 'text'" :placeholder="input.placeholder" @keydown="onInputKeydown"></mk-input>
|
||||
<mk-input v-if="user" v-model:value="userInputValue" autofocus @keydown="onInputKeydown"><template #prefix>@</template></mk-input>
|
||||
<mk-select v-if="select" v-model:value="selectedValue" autofocus>
|
||||
<template v-if="select.items">
|
||||
<option v-for="item in select.items" :value="item.value">{{ item.text }}</option>
|
||||
</template>
|
||||
<template v-else>
|
||||
<optgroup v-for="groupedItem in select.groupedItems" :label="groupedItem.label">
|
||||
<option v-for="item in groupedItem.items" :value="item.value">{{ item.text }}</option>
|
||||
</optgroup>
|
||||
</template>
|
||||
</mk-select>
|
||||
<div class="buttons" v-if="!iconOnly && (showOkButton || showCancelButton) && !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 inline @click="cancel" v-if="showCancelButton || input || select || user">{{ $t('cancel') }}</mk-button>
|
||||
</div>
|
||||
<div class="buttons" v-if="actions">
|
||||
<mk-button v-for="action in actions" inline @click="() => { action.callback(); close(); }" :primary="action.primary" :key="action.text">{{ action.text }}</mk-button>
|
||||
</div>
|
||||
</template>
|
||||
</div>
|
||||
</transition>
|
||||
</div>
|
||||
<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>
|
||||
<template v-else>
|
||||
<div class="icon" v-if="icon">
|
||||
<fa :icon="icon"/>
|
||||
</div>
|
||||
<div class="icon" v-else-if="!input && !select && !user" :class="type">
|
||||
<fa :icon="faCheck" v-if="type === 'success'"/>
|
||||
<fa :icon="faTimesCircle" v-if="type === 'error'"/>
|
||||
<fa :icon="faExclamationTriangle" v-if="type === 'warning'"/>
|
||||
<fa :icon="faInfoCircle" v-if="type === 'info'"/>
|
||||
<fa :icon="faQuestionCircle" v-if="type === 'question'"/>
|
||||
<fa :icon="faSpinner" pulse v-if="type === 'waiting'"/>
|
||||
</div>
|
||||
<header v-if="title" v-html="title"></header>
|
||||
<header v-if="title == null && user">{{ $t('enterUsername') }}</header>
|
||||
<div class="body" v-if="text" v-html="text"></div>
|
||||
<mk-input v-if="input" v-model:value="inputValue" autofocus :type="input.type || 'text'" :placeholder="input.placeholder" @keydown="onInputKeydown"></mk-input>
|
||||
<mk-input v-if="user" v-model:value="userInputValue" autofocus @keydown="onInputKeydown"><template #prefix>@</template></mk-input>
|
||||
<mk-select v-if="select" v-model:value="selectedValue" autofocus>
|
||||
<template v-if="select.items">
|
||||
<option v-for="item in select.items" :value="item.value">{{ item.text }}</option>
|
||||
</template>
|
||||
<template v-else>
|
||||
<optgroup v-for="groupedItem in select.groupedItems" :label="groupedItem.label">
|
||||
<option v-for="item in groupedItem.items" :value="item.value">{{ item.text }}</option>
|
||||
</optgroup>
|
||||
</template>
|
||||
</mk-select>
|
||||
<div class="buttons" v-if="!iconOnly && (showOkButton || showCancelButton) && !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 inline @click="cancel" v-if="showCancelButton || input || select || user">{{ $t('cancel') }}</mk-button>
|
||||
</div>
|
||||
<div class="buttons" v-if="actions">
|
||||
<mk-button v-for="action in actions" inline @click="() => { action.callback(); close(); }" :primary="action.primary" :key="action.text">{{ action.text }}</mk-button>
|
||||
</div>
|
||||
</template>
|
||||
</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,97 +208,68 @@ 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;
|
||||
display: block;
|
||||
position: fixed;
|
||||
z-index: 30000;
|
||||
top: 0;
|
||||
left: 0;
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
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);
|
||||
|
||||
&.iconOnly > .main {
|
||||
&.iconOnly {
|
||||
min-width: 0;
|
||||
width: initial;
|
||||
}
|
||||
|
||||
> .main {
|
||||
display: block;
|
||||
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 {
|
||||
font-size: 32px;
|
||||
|
||||
> .icon {
|
||||
font-size: 32px;
|
||||
|
||||
&.success {
|
||||
color: var(--accent);
|
||||
}
|
||||
|
||||
&.error {
|
||||
color: #ec4137;
|
||||
}
|
||||
|
||||
&.warning {
|
||||
color: #ecb637;
|
||||
}
|
||||
|
||||
> * {
|
||||
display: block;
|
||||
margin: 0 auto;
|
||||
}
|
||||
|
||||
& + header {
|
||||
margin-top: 16px;
|
||||
}
|
||||
&.success {
|
||||
color: var(--accent);
|
||||
}
|
||||
|
||||
> header {
|
||||
margin: 0 0 8px 0;
|
||||
font-weight: bold;
|
||||
font-size: 20px;
|
||||
|
||||
& + .body {
|
||||
margin-top: 8px;
|
||||
}
|
||||
&.error {
|
||||
color: #ec4137;
|
||||
}
|
||||
|
||||
> .body {
|
||||
margin: 16px 0 0 0;
|
||||
&.warning {
|
||||
color: #ecb637;
|
||||
}
|
||||
|
||||
> .buttons {
|
||||
> * {
|
||||
display: block;
|
||||
margin: 0 auto;
|
||||
}
|
||||
|
||||
& + header {
|
||||
margin-top: 16px;
|
||||
}
|
||||
}
|
||||
|
||||
> * {
|
||||
margin: 0 8px;
|
||||
}
|
||||
> header {
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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>
|
||||
|
|
|
@ -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>
|
||||
|
|
|
@ -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
|
||||
});
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue