30
30
</div >
31
31
32
32
<div class =" ms-3 text-sm font-normal max-w-xs pr-2" v-if =" toast.messageHtml" v-html =" toast.messageHtml" ></div >
33
- <div class =" ms-3 text-sm font-normal max-w-xs pr-2" v-else >{{toast.message}}</div >
33
+ <div class =" ms-3 text-sm font-normal max-w-xs pr-2" v-else >
34
+ <div class =" flex flex-col items-center justify-center" >
35
+ {{toast.message}}
36
+ <div class =" flex justify-center mt-2 gap-2" >
37
+ <div v-for =" button in toast.buttons" class =" rounded-md bg-lightButtonsBackground hover:bg-lightButtonsHover text-lightButtonsText dark:bg-darkPrimary dark:hover:bg-darkButtonsBackground dark:text-darkButtonsText" >
38
+ <button @click =" onButtonClick(button.value)" class =" px-2 py-1 rounded hover:bg-black/5 dark:hover:bg-white/10" >
39
+ {{ button.label }}
40
+ </button >
41
+ </div >
42
+ </div >
43
+ </div >
44
+ </div >
34
45
<button @click =" closeToast" type =" button" class =" ms-auto -mx-1.5 -my-1.5 bg-lightToastCloseIconBackground text-lightToastCloseIcon hover:text-lightToastCloseIconHover rounded-lg focus:ring-2 focus:ring-lightToastCloseIconFocusRing p-1.5 hover:bg-lightToastCloseIconBackgroundHover inline-flex items-center justify-center h-8 w-8 dark:text-darkToastCloseIcon dark:hover:text-darkToastCloseIconHover dark:bg-darkToastCloseIconBackground dark:hover:bg-darkToastCloseIconBackgroundHover dark:focus:ring-darkToastCloseIconFocusRing" >
35
46
<svg class =" w-3 h-3" xmlns =" http://www.w3.org/2000/svg" fill =" none" viewBox =" 0 0 14 14" >
36
47
<path stroke =" currentColor" stroke-linecap =" round" stroke-linejoin =" round" stroke-width =" 2" d =" m1 1 6 6m0 0 6 6M7 7l6-6M7 7l-6 6" />
@@ -53,16 +64,28 @@ const props = defineProps<{
53
64
variant: string ;
54
65
id: string ;
55
66
timeout? : number | ' unlimited' ;
67
+ buttons? : { value: any ; label: string }[];
56
68
}
57
69
}>();
58
70
function closeToast() {
71
+ // resolve with undefined on close (X button)
72
+ toastStore .resolveToast (props .toast .id );
73
+ emit (' close' );
74
+ }
75
+
76
+ function onButtonClick(value : any ) {
77
+ toastStore .resolveToast (props .toast .id , value );
59
78
emit (' close' );
60
79
}
61
80
62
81
onMounted (() => {
63
82
if (props .toast .timeout === ' unlimited' ) return ;
64
83
else {
65
- setTimeout (() => {emit (' close' );}, (props .toast .timeout || 10 ) * 1e3 );
84
+ setTimeout (() => {
85
+ // resolve with undefined on auto-timeout
86
+ toastStore .resolveToast (props .toast .id );
87
+ emit (' close' );
88
+ }, (props .toast .timeout || 10 ) * 1e3 );
66
89
}
67
90
});
68
91
0 commit comments