diff --git a/src/components/toast/Toast.vue b/src/components/toast/Toast.vue
index 90b88f93e..3025e0c44 100755
--- a/src/components/toast/Toast.vue
+++ b/src/components/toast/Toast.vue
@@ -2,7 +2,7 @@
-
+
diff --git a/src/components/toast/ToastMessage.vue b/src/components/toast/ToastMessage.vue
index ed1cb245a..b7c3ef8d0 100755
--- a/src/components/toast/ToastMessage.vue
+++ b/src/components/toast/ToastMessage.vue
@@ -1,11 +1,14 @@
-
-
-
{{message.summary}}
-
{{message.detail}}
-
+
+
+
+
{{message.summary}}
+
{{message.detail}}
+
+
+
@@ -20,7 +23,8 @@ export default {
name: 'ToastMessage',
emits: ['close'],
props: {
- message: null
+ message: null,
+ template: null
},
closeTimeout: null,
mounted() {
diff --git a/src/views/toast/ToastDemo.vue b/src/views/toast/ToastDemo.vue
index a5914de86..22cf32bc4 100755
--- a/src/views/toast/ToastDemo.vue
+++ b/src/views/toast/ToastDemo.vue
@@ -9,6 +9,26 @@
+
+
+
+
+
+
{{slotProps.message.summary}}
+
{{slotProps.message.detail}}
+
+
+
+
+
+
Severities
@@ -27,6 +47,10 @@
Remove All
+
+ Template
+
+
@@ -73,6 +97,15 @@ export default {
this.$toast.add({severity:'info', summary:'Message 2', detail:'Message 2 Content', life: 3000});
this.$toast.add({severity:'info', summary:'Message 3', detail:'Message 3 Content', life: 3000});
},
+ showTemplate() {
+ this.$toast.add({severity: 'warn', summary: 'Are you sure?', detail: 'Proceed to confirm', group: 'bc'});
+ },
+ onConfirm() {
+ this.$toast.removeGroup('bc');
+ },
+ onReject() {
+ this.$toast.removeGroup('bc');
+ },
clear() {
this.$toast.removeAllGroups();
}
diff --git a/src/views/toast/ToastDoc.vue b/src/views/toast/ToastDoc.vue
index 1301591c8..23f9e12f0 100755
--- a/src/views/toast/ToastDoc.vue
+++ b/src/views/toast/ToastDoc.vue
@@ -176,6 +176,32 @@ this.$toast.add({severity:'success', summary: 'Specific Message', group: 'mykey'
Clearing Messages
removeGroup(group) clears the messages for a specific Toast whereas removeAllGroups() method clears all messages.
+
Templating
+
Templating allows customizing the content where the message instance is available as the implicit variable.
+
+<Toast position="bottom-center" group="bc">
+ <template #message="slotProps">
+ <div class="p-d-flex p-flex-column">
+ <div class="p-text-center">
+ <i class="pi pi-exclamation-triangle" style="font-size: 3rem"></i>
+ <h4>{{slotProps.message.summary}}</h4>
+ <p>{{slotProps.message.detail}}</p>
+ </div>
+ <div class="p-grid p-fluid">
+ <div class="p-col-6">
+ <Button class="p-button-success" label="Yes" @click="onConfirm" />
+ </div>
+ <div class="p-col-6">
+ <Button class="p-button-secondary" label="No" @click="onReject" />
+ </div>
+ </div>
+ </div>
+ </template>
+</Toast>
+
+
+
+
Responsive
Toast styling can be adjusted per screen size with the breakpoints option. The value of breakpoints should be an object literal whose keys are the maximum screen sizes and values are the styles per screen. In example below, width of the toast messages cover the whole page on screens whose widths is smaller than 921px.
@@ -292,6 +318,26 @@ export default {
+
+
+
+
+
+
{{slotProps.message.summary}}
+
{{slotProps.message.detail}}
+
+
+
+
+
+
Severities
@@ -310,6 +356,9 @@ export default {
Remove All
+
+ Template
+
@@ -351,6 +400,15 @@ export default {
this.$toast.add({severity:'info', summary:'Message 2', detail:'Message 2 Content', life: 3000});
this.$toast.add({severity:'info', summary:'Message 3', detail:'Message 3 Content', life: 3000});
},
+ showTemplate() {
+ this.$toast.add({severity: 'warn', summary: 'Are you sure?', detail: 'Proceed to confirm', group: 'bc'});
+ },
+ onConfirm() {
+ this.$toast.removeGroup('bc');
+ },
+ onReject() {
+ this.$toast.removeGroup('bc');
+ },
clear() {
this.$toast.removeAllGroups();
}
@@ -382,6 +440,26 @@ button {
+
+
+
+
+
+
{{slotProps.message.summary}}
+
{{slotProps.message.detail}}
+
+
+
+
+
+
Severities
@@ -400,6 +478,9 @@ button {
Remove All
+
+ Template
+
@@ -441,12 +522,21 @@ export default defineComponent({
toast.add({severity:'info', summary:'Message 2', detail:'Message 2 Content', life: 3000});
toast.add({severity:'info', summary:'Message 3', detail:'Message 3 Content', life: 3000});
}
+ const showTemplate = () => {
+ toast.add({severity: 'warn', summary: 'Are you sure?', detail: 'Proceed to confirm', group: 'bc'});
+ }
+ const onConfirm = () => {
+ toast.removeGroup('bc');
+ }
+ const onReject = () => {
+ toast.removeGroup('bc');
+ }
const clear = () => {
toast.removeAllGroups();
}
return { showSuccess, showInfo, showWarn, showError, showTopLeft, showBottomLeft,
- showBottomRight, showSticky, showMultiple, clear };
+ showBottomRight, showSticky, showMultiple, showTemplate, onConfirm, onReject, clear };
}
});
<\\/script>