mizzkey/src/client/components/modal.vue

76 lines
1.5 KiB
Vue
Raw Normal View History

<template>
2020-09-05 14:52:36 +02:00
<div class="mk-modal" v-hotkey.global="keymap" :style="{ pointerEvents: showing ? 'auto' : 'none' }">
2020-02-06 11:11:14 +01:00
<transition :name="$store.state.device.animation ? 'bg-fade' : ''" appear>
2020-09-05 14:52:36 +02:00
<div class="bg _modalBg" ref="bg" v-if="showing" @click="$emit('click')"></div>
</transition>
2020-09-05 14:52:36 +02:00
<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>
<script lang="ts">
2020-07-23 20:15:32 +02:00
import { defineComponent } from 'vue';
2020-07-23 20:15:32 +02:00
export default defineComponent({
2020-09-05 14:52:36 +02:00
emits: ['click', 'esc'],
props: {
2020-09-05 14:52:36 +02:00
showing: {
type: Boolean,
required: true,
},
canClose: {
type: Boolean,
required: false,
default: true,
},
},
2020-02-16 14:46:18 +01:00
computed: {
keymap(): any {
return {
2020-09-05 14:52:36 +02:00
'esc': () => this.$emit('esc'),
2020-02-16 14:46:18 +01:00
};
},
},
});
</script>
<style lang="scss" scoped>
.modal-enter-active, .modal-leave-active {
transition: opacity 0.3s, transform 0.3s !important;
}
2020-09-05 14:52:36 +02:00
.modal-enter-from, .modal-leave-to {
pointer-events: none;
opacity: 0;
transform: scale(0.9);
}
.bg-fade-enter-active, .bg-fade-leave-active {
transition: opacity 0.3s !important;
}
2020-09-05 14:52:36 +02:00
.bg-fade-enter-from, .bg-fade-leave-to {
opacity: 0;
}
.mk-modal {
> .bg {
z-index: 10000;
}
> .content {
position: fixed;
z-index: 10000;
top: 0;
bottom: 0;
left: 0;
right: 0;
max-width: calc(100% - 16px);
max-height: calc(100% - 16px);
overflow: auto;
2020-09-05 14:52:36 +02:00
display: flex;
justify-content: center;
align-items: center;
}
}
</style>