BetterDiscordApp-v2/client/src/ui/components/BdModals.vue

64 lines
2.0 KiB
Vue
Raw Normal View History

2018-02-07 13:21:51 +01:00
/**
* BetterDiscord Modals Component
* Copyright (c) 2015-present Jiiks/JsSucks - https://github.com/Jiiks / https://github.com/JsSucks
* All rights reserved.
* https://betterdiscord.net
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
2018-02-07 12:52:59 +01:00
<template>
<div class="bd-modals-container">
<div v-for="(modal, index) in modals.stack" :key="`bd-modal-${modal.id}`">
<div class="bd-backdrop" :class="{'bd-backdrop-out': closing}" :style="{opacity: index === 0 ? undefined : 0}"></div>
2018-02-13 18:37:05 +01:00
<div class="bd-modal-wrap" :style="{transform: `scale(${downscale(index + 1, 0.2)})`, opacity: downscale(index + 1, 1)}">
2018-02-13 17:44:07 +01:00
<div class="bd-modal-close-area" @click="closeModal(modal)"></div>
<keep-alive><component :is="modal.component" /></keep-alive>
2018-02-13 17:44:07 +01:00
</div>
2018-02-07 12:52:59 +01:00
</div>
</div>
</template>
2018-02-07 12:52:59 +01:00
<script>
// Imports
import { Events } from 'modules';
2018-02-13 17:44:07 +01:00
import { Modals } from 'ui';
import { Modal } from './common';
import { MiError } from './common/MaterialIcon';
import ErrorModal from './bd/modals/ErrorModal.vue';
2018-02-07 12:52:59 +01:00
export default {
2018-02-13 17:44:07 +01:00
components: {
Modal, MiError
},
2018-02-07 12:52:59 +01:00
data() {
return {
2018-02-13 17:44:07 +01:00
modals: Modals,
eventListener: null
};
2018-02-07 12:52:59 +01:00
},
computed: {
closing() {
return !this.modals.stack.find(m => !m.closing);
}
},
2018-02-13 17:44:07 +01:00
created() {
Events.on('bd-refresh-modals', this.eventListener = () => {
this.$forceUpdate();
2018-02-07 12:52:59 +01:00
});
},
2018-02-13 17:44:07 +01:00
destroyed() {
if (this.eventListener) Events.off('bd-refresh-modals', this.eventListener);
},
2018-02-07 12:52:59 +01:00
methods: {
2018-02-13 17:44:07 +01:00
closeModal(modal) {
modal.close();
2018-02-07 17:02:27 +01:00
},
2018-02-13 18:37:05 +01:00
downscale(index, times) {
return 1 - ((this.modals.stack.filter(m => !m.closing).length - index) * times);
2018-02-07 12:52:59 +01:00
}
}
}
</script>