Added 5 toast max shown
This commit is contained in:
parent
1c1257f3db
commit
4cbb445301
|
@ -1,12 +1,15 @@
|
||||||
|
.toast-holder {
|
||||||
|
position: fixed;
|
||||||
|
left: 50vw;
|
||||||
|
transform: translate(-50%, 0);
|
||||||
|
bottom: 50px;
|
||||||
|
z-index: 1;
|
||||||
|
}
|
||||||
|
|
||||||
.toast {
|
.toast {
|
||||||
display: flex;
|
display: flex;
|
||||||
padding: 10px;
|
padding: 10px;
|
||||||
overflow-y: auto;
|
overflow-y: auto;
|
||||||
position: fixed;
|
|
||||||
left: 50vw;
|
|
||||||
transform: translate(-50%, 0);
|
|
||||||
bottom: 100px;
|
|
||||||
z-index: 1;
|
|
||||||
background-color: var(--primary-input-color);
|
background-color: var(--primary-input-color);
|
||||||
opacity: 0;
|
opacity: 0;
|
||||||
border-radius: 20px;
|
border-radius: 20px;
|
||||||
|
|
|
@ -5,9 +5,13 @@ export default Vue.extend({
|
||||||
name: 'FtToast',
|
name: 'FtToast',
|
||||||
data: function () {
|
data: function () {
|
||||||
return {
|
return {
|
||||||
isOpen: false,
|
toasts: [
|
||||||
message: '',
|
{isOpen: false, message: '', action: null, timeout: null},
|
||||||
action: () => {},
|
{isOpen: false, message: '', action: null, timeout: null},
|
||||||
|
{isOpen: false, message: '', action: null, timeout: null},
|
||||||
|
{isOpen: false, message: '', action: null, timeout: null},
|
||||||
|
{isOpen: false, message: '', action: null, timeout: null}
|
||||||
|
],
|
||||||
queue: [],
|
queue: [],
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
@ -15,27 +19,32 @@ export default Vue.extend({
|
||||||
FtToastEvents.$on('toast.open', this.open)
|
FtToastEvents.$on('toast.open', this.open)
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
performAction: function () {
|
performAction: function (index) {
|
||||||
this.action()
|
this.toasts[index].action()
|
||||||
this.close()
|
this.close(index)
|
||||||
},
|
},
|
||||||
close: function () {
|
close: function (index) {
|
||||||
this.isOpen = false
|
clearTimeout(this.toasts[index].timeout);
|
||||||
|
this.toasts[index].isOpen = false
|
||||||
if(this.queue.length !== 0) {
|
if(this.queue.length !== 0) {
|
||||||
const toast = this.queue.shift()
|
const toast = this.queue.shift()
|
||||||
this.open(toast.message, toast.action)
|
this.open(toast.message, toast.action)
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
open: function (message, action) {
|
open: function (message, action) {
|
||||||
if (this.isOpen) {
|
for(let i = this.toasts.length - 1; i >= 0 ; i--){
|
||||||
this.queue.push({ message: message, action: action })
|
if (!this.toasts[i].isOpen) {
|
||||||
return
|
return this.showToast(message, action, i)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
this.message = message
|
this.queue.push({ message: message, action: action })
|
||||||
this.action = action || (() => {});
|
|
||||||
this.isOpen = true
|
|
||||||
setTimeout(this.close, 2000)
|
|
||||||
},
|
},
|
||||||
|
showToast: function(message, action, index) {
|
||||||
|
this.toasts[index].message = message
|
||||||
|
this.toasts[index].action = action || (() => {})
|
||||||
|
this.toasts[index].isOpen = true
|
||||||
|
this.toasts[index].timeout = setTimeout(this.close, 2000, index)
|
||||||
|
}
|
||||||
},
|
},
|
||||||
beforeDestroy: function () {
|
beforeDestroy: function () {
|
||||||
FtToastEvents.$off('toast.open', this.open)
|
FtToastEvents.$off('toast.open', this.open)
|
||||||
|
|
|
@ -1,11 +1,15 @@
|
||||||
<template>
|
<template>
|
||||||
<div
|
<div class="toast-holder">
|
||||||
ref="toast"
|
<div
|
||||||
class="toast"
|
v-for="(toast, index) in toasts"
|
||||||
:class="{ closed: !isOpen, open: isOpen }"
|
:key="'toast-' + index"
|
||||||
@click="performAction()"
|
class="toast"
|
||||||
>
|
:class="{ closed: !toast.isOpen, open: toast.isOpen }"
|
||||||
<p class="message"> {{ message }} </p></div>
|
@click="performAction(index)"
|
||||||
|
>
|
||||||
|
<p class="message">{{ toast.message }}</p>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script src="./ft-toast.js" />
|
<script src="./ft-toast.js" />
|
||||||
|
|
Loading…
Reference in New Issue