2019-08-14 09:48:44 +00:00
|
|
|
<template>
|
|
|
|
<transition-group name="toast-fade" tag="div" class="ui-snackbar-container">
|
2020-05-02 04:17:36 +00:00
|
|
|
<woot-snackbar
|
|
|
|
v-for="snackMessage in snackMessages"
|
2021-04-19 16:51:59 +00:00
|
|
|
:key="snackMessage.key"
|
|
|
|
:message="snackMessage.message"
|
2020-05-02 04:17:36 +00:00
|
|
|
/>
|
2019-08-14 09:48:44 +00:00
|
|
|
</transition-group>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<script>
|
|
|
|
import WootSnackbar from './Snackbar';
|
|
|
|
|
|
|
|
export default {
|
2020-05-02 04:17:36 +00:00
|
|
|
components: {
|
|
|
|
WootSnackbar,
|
|
|
|
},
|
2019-08-14 09:48:44 +00:00
|
|
|
props: {
|
|
|
|
duration: {
|
2020-05-02 04:17:36 +00:00
|
|
|
type: Number,
|
2019-08-14 09:48:44 +00:00
|
|
|
default: 2500,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
data() {
|
|
|
|
return {
|
|
|
|
snackMessages: [],
|
|
|
|
};
|
|
|
|
},
|
|
|
|
|
|
|
|
mounted() {
|
2021-11-30 05:15:36 +00:00
|
|
|
bus.$on('newToastMessage', this.onNewToastMessage);
|
|
|
|
},
|
|
|
|
beforeDestroy() {
|
|
|
|
bus.$off('newToastMessage', this.onNewToastMessage);
|
|
|
|
},
|
2021-11-30 18:57:44 +00:00
|
|
|
methods: {
|
|
|
|
onNewToastMessage(message) {
|
|
|
|
this.snackMessages.push({ key: new Date().getTime(), message });
|
|
|
|
window.setTimeout(() => {
|
|
|
|
this.snackMessages.splice(0, 1);
|
|
|
|
}, this.duration);
|
|
|
|
},
|
2019-08-14 09:48:44 +00:00
|
|
|
},
|
|
|
|
};
|
|
|
|
</script>
|