primevue-mirror/doc/toast/HeadlessDoc.vue

221 lines
8.6 KiB
Vue
Raw Normal View History

2023-10-25 15:56:34 +00:00
<template>
<DocSectionText v-bind="$attrs">
<p>Headless mode is enabled by defining a <i>container</i> slot that lets you implement entire toast UI instead of the default elements.</p>
</DocSectionText>
2024-05-20 12:14:38 +00:00
<div class="card flex justify-center">
2023-10-25 15:56:34 +00:00
<Toast position="top-center" group="headless" @close="visible = false">
2023-10-31 13:03:45 +00:00
<template #container="{ message, closeCallback }">
2024-05-26 09:41:32 +00:00
<section class="flex flex-col p-4 gap-4 w-full bg-primary/70 rounded-xl">
<div class="flex items-center gap-5">
2024-05-26 09:42:56 +00:00
<i class="pi pi-cloud-upload text-white dark:text-black text-2xl"></i>
<span class="font-bold text-base text-white dark:text-black">{{ message.summary }}</span>
2024-05-26 09:41:32 +00:00
</div>
<div class="flex flex-col gap-2">
<ProgressBar :value="progress" :showValue="false" :style="{ height: '4px' }" pt:value:class="!bg-primary-50 dark:!bg-primary-900" class="!bg-primary/80"></ProgressBar>
2024-05-26 09:42:56 +00:00
<label class="text-sm font-bold text-white dark:text-black">{{ progress }}% uploaded</label>
2024-05-26 09:41:32 +00:00
</div>
<div class="flex gap-4 mb-4 justify-end">
<Button label="Another Upload?" size="small" @click="closeCallback"></Button>
<Button label="Cancel" size="small" @click="closeCallback"></Button>
2023-10-25 15:56:34 +00:00
</div>
</section>
</template>
</Toast>
<Button @click="show" label="View" />
</div>
<DocSectionCode :code="code" />
</template>
<script>
export default {
data() {
return {
visible: false,
progress: 0,
interval: null,
code: {
basic: `
<Toast position="top-center" group="headless" @close="visible = false">
2023-10-31 13:03:45 +00:00
<template #container="{ message, closeCallback }">
2024-05-26 09:41:32 +00:00
<section class="flex flex-col p-4 gap-4 w-full bg-primary/70 rounded-xl">
<div class="flex items-center gap-5">
2024-05-26 09:42:56 +00:00
<i class="pi pi-cloud-upload text-white dark:text-black text-2xl"></i>
<span class="font-bold text-base text-white dark:text-black">{{ message.summary }}</span>
2024-05-26 09:41:32 +00:00
</div>
<div class="flex flex-col gap-2">
<ProgressBar :value="progress" :showValue="false" :style="{ height: '4px' }" pt:value:class="!bg-primary-50 dark:!bg-primary-900" class="!bg-primary/80"></ProgressBar>
2024-05-26 09:42:56 +00:00
<label class="text-sm font-bold text-white dark:text-black">{{ progress }}% uploaded</label>
2024-05-26 09:41:32 +00:00
</div>
<div class="flex gap-4 mb-4 justify-end">
<Button label="Another Upload?" size="small" @click="closeCallback"></Button>
<Button label="Cancel" size="small" @click="closeCallback"></Button>
2023-10-25 15:56:34 +00:00
</div>
</section>
</template>
</Toast>
<Button @click="show" label="View" />
`,
options: `
<template>
2024-05-20 12:14:38 +00:00
<div class="card flex justify-center">
2023-10-25 15:56:34 +00:00
<Toast position="top-center" group="headless" @close="visible = false">
2023-10-31 13:03:45 +00:00
<template #container="{ message, closeCallback }">
2024-05-26 09:41:32 +00:00
<section class="flex flex-col p-4 gap-4 w-full bg-primary/70 rounded-xl">
<div class="flex items-center gap-5">
2024-05-26 09:42:56 +00:00
<i class="pi pi-cloud-upload text-white dark:text-black text-2xl"></i>
<span class="font-bold text-base text-white dark:text-black">{{ message.summary }}</span>
2024-05-26 09:41:32 +00:00
</div>
<div class="flex flex-col gap-2">
<ProgressBar :value="progress" :showValue="false" :style="{ height: '4px' }" pt:value:class="!bg-primary-50 dark:!bg-primary-900" class="!bg-primary/80"></ProgressBar>
2024-05-26 09:42:56 +00:00
<label class="text-sm font-bold text-white dark:text-black">{{ progress }}% uploaded</label>
2024-05-26 09:41:32 +00:00
</div>
<div class="flex gap-4 mb-4 justify-end">
<Button label="Another Upload?" size="small" @click="closeCallback"></Button>
<Button label="Cancel" size="small" @click="closeCallback"></Button>
2023-10-25 15:56:34 +00:00
</div>
</section>
</template>
</Toast>
<Button @click="show" label="View" />
</div>
</template>
<script>
export default {
data() {
return {
visible: false,
progress: 0,
interval: null
}
},
beforeUnmount() {
if (this.interval) {
clearInterval(this.interval);
}
},
methods: {
show() {
if (!this.visible) {
2024-05-30 07:50:17 +00:00
this.$toast.add({ severity: 'custom', summary: 'Uploading your files.', group: 'headless', styleClass: 'backdrop-blur-lg rounded-2xl' });
2023-10-25 15:56:34 +00:00
this.visible = true;
this.progress = 0;
if (this.interval) {
clearInterval(this.interval);
}
this.interval = setInterval(() => {
if (this.progress <= 100) {
this.progress = this.progress + 20;
}
if (this.progress >= 100) {
this.progress = 100;
2023-11-01 09:10:00 +00:00
clearInterval(this.interval);
2023-10-25 15:56:34 +00:00
}
}, 1000);
}
}
}
};
<\/script>
`,
composition: `
<template>
2024-05-20 12:14:38 +00:00
<div class="card flex justify-center">
2023-10-25 15:56:34 +00:00
<Toast position="top-center" group="headless" @close="visible = false">
2023-10-31 13:03:45 +00:00
<template #container="{ message, closeCallback }">
2024-05-26 09:41:32 +00:00
<section class="flex flex-col p-4 gap-4 w-full bg-primary/70 rounded-xl">
<div class="flex items-center gap-5">
2024-05-26 09:42:56 +00:00
<i class="pi pi-cloud-upload text-white dark:text-black text-2xl"></i>
<span class="font-bold text-base text-white dark:text-black">{{ message.summary }}</span>
2024-05-26 09:41:32 +00:00
</div>
<div class="flex flex-col gap-2">
<ProgressBar :value="progress" :showValue="false" :style="{ height: '4px' }" pt:value:class="!bg-primary-50 dark:!bg-primary-900" class="!bg-primary/80"></ProgressBar>
2024-05-26 09:42:56 +00:00
<label class="text-sm font-bold text-white dark:text-black">{{ progress }}% uploaded</label>
2024-05-26 09:41:32 +00:00
</div>
<div class="flex gap-4 mb-4 justify-end">
<Button label="Another Upload?" size="small" @click="closeCallback"></Button>
<Button label="Cancel" size="small" @click="closeCallback"></Button>
2023-10-25 15:56:34 +00:00
</div>
</section>
</template>
</Toast>
<Button @click="show" label="View" />
</div>
</template>
<script setup>
import { useToast } from "primevue/usetoast";
import { ref, onUnmounted } from 'vue';
const toast = useToast();
const visible = ref(false);
const progress = ref(0);
const interval = ref();
onUnmounted(() => {
if (interval.value) {
clearInterval(interval.value);
}
})
const show = () => {
if (!visible.value) {
2024-05-30 07:50:17 +00:00
toast.add({ severity: 'custom', summary: 'Uploading your files.', group: 'headless', styleClass: 'backdrop-blur-lg rounded-2xl' });
2023-10-25 15:56:34 +00:00
visible.value = true;
progress.value = 0;
if (interval.value) {
clearInterval(interval.value);
}
interval.value = setInterval(() => {
if (progress.value <= 100) {
progress.value = progress.value + 20;
}
if (progress.value >= 100) {
progress.value = 100;
clearInterval(interval.value);
}
}, 1000);
}
};
<\/script>
`
}
};
},
beforeUnmount() {
if (this.interval) {
clearInterval(this.interval);
}
},
methods: {
show() {
if (!this.visible) {
2024-05-30 07:50:17 +00:00
this.$toast.add({ severity: 'custom', summary: 'Uploading your files.', group: 'headless', styleClass: 'backdrop-blur-lg rounded-2xl' });
2023-10-25 15:56:34 +00:00
this.visible = true;
this.progress = 0;
if (this.interval) {
clearInterval(this.interval);
}
this.interval = setInterval(() => {
if (this.progress <= 100) {
this.progress = this.progress + 20;
}
if (this.progress >= 100) {
this.progress = 100;
2023-11-01 09:10:00 +00:00
clearInterval(this.interval);
2023-10-25 15:56:34 +00:00
}
}, 1000);
}
}
}
};
</script>