primevue-mirror/doc/toast/HeadlessDoc.vue

225 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-20 12:14:38 +00:00
<section class="flex p-4 gap-4 w-full bg-black/90" style="border-radius: 10px">
2024-05-21 11:17:35 +00:00
<i class="pi pi-cloud-upload text-green-400 text-2xl"></i>
2024-05-20 12:14:38 +00:00
<div class="flex flex-col gap-4 w-full">
2023-10-25 15:56:34 +00:00
<p class="m-0 font-semibold text-base text-white">{{ message.summary }}</p>
2024-05-21 11:17:35 +00:00
<p class="m-0 text-base text-white">{{ message.detail }}</p>
2024-05-20 12:14:38 +00:00
<div class="flex flex-col gap-2">
2023-10-25 15:56:34 +00:00
<ProgressBar :value="progress" :showValue="false" :style="{ height: '4px' }"></ProgressBar>
<label class="text-right text-xs text-white">{{ progress }}% uploaded...</label>
</div>
2024-05-20 12:14:38 +00:00
<div class="flex gap-4 mb-4">
2024-01-24 10:49:32 +00:00
<Button label="Another Upload?" text class="py-1 px-2" @click="closeCallback"></Button>
<Button label="Cancel" text class="text-white py-1 px-2" @click="closeCallback"></Button>
2023-10-25 15:56:34 +00:00
</div>
</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-20 12:14:38 +00:00
<section class="flex p-4 gap-4 w-full bg-black/90" style="border-radius: 10px">
2023-10-25 15:56:34 +00:00
<i class="pi pi-cloud-upload text-primary-500 text-2xl"></i>
2024-05-20 12:14:38 +00:00
<div class="flex flex-col gap-4 w-full">
2023-10-25 15:56:34 +00:00
<p class="m-0 font-semibold text-base text-white">{{ message.summary }}</p>
2024-05-20 12:14:38 +00:00
<p class="m-0 text-base text-surface-700">{{ message.detail }}</p>
<div class="flex flex-col gap-2">
2023-10-25 15:56:34 +00:00
<ProgressBar :value="progress" :showValue="false" :style="{ height: '4px' }"></ProgressBar>
<label class="text-right text-xs text-white">{{ progress }}% uploaded...</label>
</div>
2024-05-20 12:14:38 +00:00
<div class="flex gap-4 mb-4">
2024-01-24 10:49:32 +00:00
<Button label="Another Upload?" text class="py-1 px-2" @click="closeCallback"></Button>
<Button label="Cancel" text class="text-white py-1 px-2" @click="closeCallback"></Button>
2023-10-25 15:56:34 +00:00
</div>
</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-20 12:14:38 +00:00
<section class="flex p-4 gap-4 w-full bg-black/90" style="border-radius: 10px">
2023-10-25 15:56:34 +00:00
<i class="pi pi-cloud-upload text-primary-500 text-2xl"></i>
2024-05-20 12:14:38 +00:00
<div class="flex flex-col gap-4 w-full">
2023-10-25 15:56:34 +00:00
<p class="m-0 font-semibold text-base text-white">{{ message.summary }}</p>
2024-05-20 12:14:38 +00:00
<p class="m-0 text-base text-surface-700">{{ message.detail }}</p>
<div class="flex flex-col gap-2">
2023-10-25 15:56:34 +00:00
<ProgressBar :value="progress" :showValue="false" :style="{ height: '4px' }"></ProgressBar>
<label class="text-right text-xs text-white">{{ progress }}% uploaded...</label>
</div>
2024-05-20 12:14:38 +00:00
<div class="flex gap-4 mb-4">
2024-01-24 10:49:32 +00:00
<Button label="Another Upload?" text class="py-1 px-2" @click="closeCallback"></Button>
<Button label="Cancel" text class="text-white py-1 px-2" @click="closeCallback"></Button>
2023-10-25 15:56:34 +00:00
</div>
</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) {
this.$toast.add({ severity: 'custom', summary: 'Uploading your files.', group: 'headless' });
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-20 12:14:38 +00:00
<section class="flex p-4 gap-4 w-full bg-black/90" style="border-radius: 10px">
2023-10-25 15:56:34 +00:00
<i class="pi pi-cloud-upload text-primary-500 text-2xl"></i>
2024-05-20 12:14:38 +00:00
<div class="flex flex-col gap-4 w-full">
2023-10-25 15:56:34 +00:00
<p class="m-0 font-semibold text-base text-white">{{ message.summary }}</p>
2024-05-20 12:14:38 +00:00
<p class="m-0 text-base text-surface-700">{{ message.detail }}</p>
<div class="flex flex-col gap-2">
2023-10-25 15:56:34 +00:00
<ProgressBar :value="progress" :showValue="false" :style="{ height: '4px' }"></ProgressBar>
<label class="text-right text-xs text-white">{{ progress }}% uploaded...</label>
</div>
2024-05-20 12:14:38 +00:00
<div class="flex gap-4 mb-4">
2024-01-24 10:49:32 +00:00
<Button label="Another Upload?" text class="py-1 px-2" @click="closeCallback"></Button>
<Button label="Cancel" text class="text-white py-1 px-2" @click="closeCallback"></Button>
2023-10-25 15:56:34 +00:00
</div>
</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) {
toast.add({ severity: 'custom', summary: 'Uploading your files.', group: 'headless' });
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) {
this.$toast.add({ severity: 'custom', summary: 'Uploading your files.', group: 'headless' });
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>