Fixed #9 - Auto z-index layering for Toast

pull/41/head
cagataycivici 2019-07-11 10:39:23 +03:00
parent de04fd88ba
commit e749db2c7b
2 changed files with 36 additions and 2 deletions

View File

@ -1,5 +1,5 @@
<template> <template>
<div :class="containerClass"> <div ref="container" :class="containerClass">
<transition-group name="p-toast-message" tag="div"> <transition-group name="p-toast-message" tag="div">
<ToastMessage v-for="msg of messages" :key="msg.id" :message="msg" @close="remove($event)"/> <ToastMessage v-for="msg of messages" :key="msg.id" :message="msg" @close="remove($event)"/>
</transition-group> </transition-group>
@ -9,15 +9,27 @@
<script> <script>
import ToastEventBus from './ToastEventBus'; import ToastEventBus from './ToastEventBus';
import ToastMessage from './ToastMessage'; import ToastMessage from './ToastMessage';
import DomHandler from '../utils/DomHandler';
var messageIdx = 0; var messageIdx = 0;
export default { export default {
props: { props: {
group: String, group: {
type: String,
default: null
},
position: { position: {
type: String, type: String,
default: 'topright' default: 'topright'
},
autoZIndex: {
type: Boolean,
default: true
},
baseZIndex: {
type: Number,
default: 0
} }
}, },
data() { data() {
@ -39,6 +51,11 @@ export default {
ToastEventBus.$on('remove-all-groups', () => { ToastEventBus.$on('remove-all-groups', () => {
this.messages = []; this.messages = [];
}); });
this.updateZIndex();
},
beforeUpdate() {
this.updateZIndex();
}, },
methods: { methods: {
add(message) { add(message) {
@ -58,6 +75,11 @@ export default {
} }
this.messages.splice(index, 1); this.messages.splice(index, 1);
},
updateZIndex() {
if (this.autoZIndex) {
this.$refs.container.style.zIndex = String(this.baseZIndex + DomHandler.generateZIndex());
}
} }
}, },
components: { components: {

View File

@ -178,6 +178,18 @@ this.$toast.removeAllGroups();
<td>string</td> <td>string</td>
<td>topright</td> <td>topright</td>
<td>Position of the toast in viewport, valid values are "topright", "topleft", "bottomleft" and "bottomright".</td> <td>Position of the toast in viewport, valid values are "topright", "topleft", "bottomleft" and "bottomright".</td>
</tr>
<tr>
<td>autoZIndex</td>
<td>boolean</td>
<td>true</td>
<td>Whether to automatically manage layering.</td>
</tr>
<tr>
<td>baseZIndex</td>
<td>number</td>
<td>0</td>
<td>Base zIndex value to use in layering.</td>
</tr> </tr>
</tbody> </tbody>
</table> </table>