fix: dialog

This commit is contained in:
ThatOneCalculator 2023-02-18 15:34:41 -08:00
parent a1a6937785
commit 9c5dc7b3f2
No known key found for this signature in database
GPG Key ID: 8703CACD01000000
1 changed files with 97 additions and 92 deletions

View File

@ -1,21 +1,21 @@
<template>
<MkModal ref="modal" :prefer-type="'dialog'" :z-priority="'high'" @click="done(true)" @closed="emit('closed')">
<div class="mk-dialog">
<div v-if="icon" class="icon">
<MkModal ref="modal" :prefer-type="'dialog'" :z-priority="'high'" @click="done(true)" @closed="emit('closed')">
<div :class="$style.root">
<div v-if="icon" :class="$style.icon">
<i :class="icon"></i>
</div>
<div v-else-if="!input && !select" class="icon" :class="type">
<i v-if="type === 'success'" class="ph-check-bold ph-lg"></i>
<i v-else-if="type === 'error'" class="ph-circle-wavy-warning-bold ph-lg"></i>
<i v-else-if="type === 'warning'" class="ph-warning-bold ph-lg"></i>
<i v-else-if="type === 'info'" class="ph-info-bold ph-lg"></i>
<i v-else-if="type === 'question'" class="ph-question-bold ph-lg"></i>
<i v-else-if="type === 'waiting'" class="ph-circle-notch-bold ph-lg fa-pulse"></i>
<div v-else-if="!input && !select" :class="[$style.icon, $style['type_' + type]]">
<i v-if="type === 'success'" :class="$style.iconInner" class="ph-check-bold ph-lg"></i>
<i v-else-if="type === 'error'" :class="$style.iconInner" class="ph-circle-wavy-warning-bold ph-lg"></i>
<i v-else-if="type === 'warning'" :class="$style.iconInner" class="ph-warning-bold ph-lg"></i>
<i v-else-if="type === 'info'" :class="$style.iconInner" class="ph-info-bold ph-lg"></i>
<i v-else-if="type === 'question'" :class="$style.iconInner" class="ph-circle-notch-bold ph-lg"></i>
<MkLoading v-else-if="type === 'waiting'" :class="$style.iconInner" :em="true"/>
</div>
<header v-if="title"><Mfm :text="title"/></header>
<div v-if="text" class="body"><Mfm :text="text"/></div>
<header v-if="title" :class="$style.title"><Mfm :text="title"/></header>
<div v-if="text" :class="$style.text"><Mfm :text="text"/></div>
<MkInput v-if="input" v-model="inputValue" autofocus :type="input.type || 'text'" :placeholder="input.placeholder || undefined" @keydown="onInputKeydown">
<template v-if="input.type === 'password'" #prefix><i class="ph-lock-bold ph-lg"></i></template>
<template v-if="input.type === 'password'" #prefix><i class="ph-password-bold ph-lg"></i></template>
</MkInput>
<MkSelect v-if="select" v-model="selectedValue" autofocus>
<template v-if="select.items">
@ -27,7 +27,7 @@
</optgroup>
</template>
</MkSelect>
<div v-if="(showOkButton || showCancelButton) && !actions" class="buttons">
<div v-if="(showOkButton || showCancelButton) && !actions" :class="$style.buttons">
<div v-if="!isYesNo">
<MkButton v-if="showOkButton" inline primary :autofocus="!input && !select" @click="ok">{{ (showCancelButton || input || select) ? i18n.ts.ok : i18n.ts.gotIt }}</MkButton>
<MkButton v-if="showCancelButton || input || select" inline @click="cancel">{{ i18n.ts.cancel }}</MkButton>
@ -37,15 +37,15 @@
<MkButton v-if="showCancelButton || input || select" inline @click="cancel">{{ i18n.ts.no }}</MkButton>
</div>
</div>
<div v-if="actions" class="buttons">
<MkButton v-for="action in actions" :key="action.text" inline :primary="action.primary" @click="() => { action.callback(); close(); }">{{ action.text }}</MkButton>
<div v-if="actions" :class="$style.buttons">
<MkButton v-for="action in actions" :key="action.text" inline :primary="action.primary" @click="() => { action.callback(); modal?.close(); }">{{ action.text }}</MkButton>
</div>
</div>
</MkModal>
</MkModal>
</template>
<script lang="ts" setup>
import { onBeforeUnmount, onMounted, ref } from 'vue';
import { onBeforeUnmount, onMounted, ref, shallowRef } from 'vue';
import MkModal from '@/components/MkModal.vue';
import MkButton from '@/components/MkButton.vue';
import MkInput from '@/components/form/input.vue';
@ -88,12 +88,16 @@ const props = withDefaults(defineProps<{
showOkButton?: boolean;
showCancelButton?: boolean;
isYesNo?: boolean;
cancelableByBgClick?: boolean;
okText?: string;
cancelText?: string;
}>(), {
type: 'info',
showOkButton: true,
showCancelButton: false,
isYesNo: false,
cancelableByBgClick: true,
});
@ -102,7 +106,7 @@ const emit = defineEmits<{
(ev: 'closed'): void;
}>();
const modal = ref<InstanceType<typeof MkModal>>();
const modal = shallowRef<InstanceType<typeof MkModal>>();
const inputValue = ref(props.input?.default || null);
const selectedValue = ref(props.select?.default || null);
@ -151,9 +155,10 @@ onBeforeUnmount(() => {
});
</script>
<style lang="scss" scoped>
.mk-dialog {
<style lang="scss" module>
.root {
position: relative;
margin: auto;
padding: 32px;
min-width: 320px;
max-width: 480px;
@ -161,56 +166,56 @@ onBeforeUnmount(() => {
text-align: center;
background: var(--panel);
border-radius: var(--radius);
}
> .icon {
font-size: 32px;
.icon {
font-size: 24px;
&.info {
color: #55c4dd;
}
&.success {
color: var(--success);
}
&.error {
color: var(--error);
}
&.warning {
color: var(--warn);
}
> * {
display: block;
margin: 0 auto;
}
& + header {
margin-top: 16px;
}
}
> header {
margin: 0 0 8px 0;
font-weight: bold;
font-size: 20px;
& + .body {
& + .title {
margin-top: 8px;
}
}
}
> .body {
margin: 16px 0 0 0;
}
.iconInner {
display: block;
margin: 0 auto;
}
> .buttons {
margin-top: 16px;
.type_info {
color: var(--accent);
}
> * {
margin: 0 8px;
}
.type_success {
color: var(--success);
}
.type_error {
color: var(--error);
}
.type_warning {
color: var(--warn);
}
.title {
margin: 0 0 8px 0;
font-weight: bold;
font-size: 1.1em;
& + .text {
margin-top: 8px;
}
}
.text {
margin: 16px 0 0 0;
}
.buttons {
margin-top: 16px;
display: flex;
gap: 8px;
flex-wrap: wrap;
justify-content: center;
}
</style>