primevue-mirror/doc/toast/TemplateDoc.vue

150 lines
5.2 KiB
Vue
Raw Normal View History

2023-02-28 08:29:30 +00:00
<template>
<DocSectionText v-bind="$attrs">
2023-10-25 15:56:34 +00:00
<p>Custom content inside a message is defined with the <i>content</i> template.</p>
2023-02-28 08:29:30 +00:00
</DocSectionText>
<div class="card flex justify-content-center">
2023-10-07 10:06:54 +00:00
<Toast position="bottom-center" group="bc" @close="onClose">
2023-02-28 08:29:30 +00:00
<template #message="slotProps">
2023-10-25 15:22:15 +00:00
<div class="flex flex-column align-items-start" style="flex: 1">
<div class="flex align-items-center gap-2">
<Avatar image="https://primefaces.org/cdn/primevue/images/avatar/amyelsner.png" shape="circle" />
<span class="font-bold text-900">Amy Elsner</span>
2023-02-28 08:29:30 +00:00
</div>
2023-10-25 15:22:15 +00:00
<div class="font-medium text-lg my-3 text-900">{{ slotProps.message.summary }}</div>
<Button severity="success" outlined class="p-button-sm" label="Reply" @click="onReply()"></Button>
2023-02-28 08:29:30 +00:00
</div>
</template>
</Toast>
2023-10-25 15:22:15 +00:00
<Button @click="showTemplate" label="View" />
2023-02-28 08:29:30 +00:00
</div>
<DocSectionCode :code="code" />
</template>
<script>
export default {
data() {
return {
2023-10-07 10:06:54 +00:00
visible: false,
2023-02-28 08:29:30 +00:00
code: {
2023-09-22 12:54:14 +00:00
basic: `
2023-10-07 10:06:54 +00:00
<Toast position="bottom-center" group="bc" @close="onClose">
2023-02-28 08:29:30 +00:00
<template #message="slotProps">
2023-10-25 15:22:15 +00:00
<div class="flex flex-column align-items-start" style="flex: 1">
<div class="flex align-items-center gap-2">
<Avatar image="/images/avatar/amyelsner.png" shape="circle" />
<span class="font-bold text-900">Amy Elsner</span>
2023-02-28 08:29:30 +00:00
</div>
2023-10-25 15:22:15 +00:00
<div class="font-medium text-lg my-3 text-900">{{ slotProps.message.summary }}</div>
<Button severity="success" outlined class="p-button-sm" label="Reply" @click="onReply()"></Button>
2023-02-28 08:29:30 +00:00
</div>
</template>
</Toast>
2023-10-25 15:22:15 +00:00
<Button @click="showTemplate" label="View" />
2023-10-15 09:38:39 +00:00
`,
2023-09-22 12:54:14 +00:00
options: `
<template>
2023-02-28 08:29:30 +00:00
<div class="card flex justify-content-center">
2023-10-07 10:06:54 +00:00
<Toast position="bottom-center" group="bc" @close="onClose">
2023-02-28 08:29:30 +00:00
<template #message="slotProps">
2023-10-25 15:22:15 +00:00
<div class="flex flex-column align-items-start" style="flex: 1">
<div class="flex align-items-center gap-2">
<Avatar image="https://primefaces.org/cdn/primevue/images/avatar/amyelsner.png" shape="circle" />
<span class="font-bold text-900">Amy Elsner</span>
2023-02-28 08:29:30 +00:00
</div>
2023-10-25 15:22:15 +00:00
<div class="font-medium text-lg my-3 text-900">{{ slotProps.message.summary }}</div>
<Button severity="success" outlined class="p-button-sm" label="Reply" @click="onReply()"></Button>
2023-02-28 08:29:30 +00:00
</div>
</template>
</Toast>
2023-10-25 15:22:15 +00:00
<Button @click="showTemplate" label="View" />
2023-02-28 08:29:30 +00:00
</div>
</template>
<script>
export default {
2023-10-07 10:06:54 +00:00
data() {
return {
visible: false
}
},
2023-02-28 08:29:30 +00:00
methods: {
showTemplate() {
2023-10-07 10:06:54 +00:00
if (!this.visible) {
2023-10-25 15:22:15 +00:00
this.$toast.add({ severity: 'success', summary: 'Can you send me the report?', group: 'bc' });
2023-10-07 10:06:54 +00:00
this.visible = true;
}
},
2023-10-25 15:22:15 +00:00
onReply() {
2023-10-07 10:06:54 +00:00
this.$toast.removeGroup('bc');
this.visible = false;
},
onClose() {
this.visible = false;
2023-02-28 08:29:30 +00:00
}
}
};
2023-10-15 09:38:39 +00:00
<\/script>
`,
2023-09-22 12:54:14 +00:00
composition: `
<template>
2023-02-28 08:29:30 +00:00
<div class="card flex justify-content-center">
2023-10-07 10:06:54 +00:00
<Toast position="bottom-center" group="bc" @close="onClose">
2023-02-28 08:29:30 +00:00
<template #message="slotProps">
2023-10-25 15:22:15 +00:00
<div class="flex flex-column align-items-start" style="flex: 1">
<div class="flex align-items-center gap-2">
<Avatar image="https://primefaces.org/cdn/primevue/images/avatar/amyelsner.png" shape="circle" />
<span class="font-bold text-900">Amy Elsner</span>
2023-02-28 08:29:30 +00:00
</div>
2023-10-25 15:22:15 +00:00
<div class="font-medium text-lg my-3 text-900">{{ slotProps.message.summary }}</div>
<Button severity="success" outlined class="p-button-sm" label="Reply" @click="onReply()"></Button>
2023-02-28 08:29:30 +00:00
</div>
</template>
</Toast>
2023-10-25 15:22:15 +00:00
<Button @click="showTemplate" label="View" />
2023-02-28 08:29:30 +00:00
</div>
</template>
<script setup>
import { useToast } from "primevue/usetoast";
2023-10-07 10:06:54 +00:00
import { ref } from 'vue';
2023-02-28 08:29:30 +00:00
const toast = useToast();
2023-10-07 10:06:54 +00:00
const visible = ref(false);
2023-02-28 08:29:30 +00:00
const showTemplate = () => {
2023-10-07 10:06:54 +00:00
if (!visible.value) {
2023-10-25 15:22:15 +00:00
toast.add({ severity: 'success', summary: 'Can you send me the report?', group: 'bc' });
2023-10-07 10:06:54 +00:00
visible.value = true;
}
2023-02-28 08:29:30 +00:00
};
2023-10-07 10:06:54 +00:00
2023-10-25 15:22:15 +00:00
const onReply = () => {
2023-10-07 10:06:54 +00:00
toast.removeGroup('bc');
visible.value = false;
}
const onClose = () => {
visible.value = false;
}
2023-10-15 09:38:39 +00:00
<\/script>
`
2023-02-28 08:29:30 +00:00
}
};
},
methods: {
showTemplate() {
2023-10-07 10:06:54 +00:00
if (!this.visible) {
2023-10-25 15:22:15 +00:00
this.$toast.add({ severity: 'success', summary: 'Can you send me the report?', group: 'bc' });
2023-10-07 10:06:54 +00:00
this.visible = true;
}
2023-02-28 08:29:30 +00:00
},
2023-10-25 15:22:15 +00:00
onReply() {
2023-02-28 08:29:30 +00:00
this.$toast.removeGroup('bc');
2023-10-07 10:06:54 +00:00
this.visible = false;
},
onClose() {
this.visible = false;
2023-02-28 08:29:30 +00:00
}
}
};
</script>