Files
heroui-vue/apps/docs/demos/toast-placements.vue
T

61 lines
1.4 KiB
Vue

<script setup lang="ts">
import { onBeforeUnmount } from "vue";
import {
Button,
ToastProvider,
ToastQueue,
type ToastContentValue,
} from "@heroui-vue/components";
import type { ToastVariants } from "@heroui-vue/styles";
type Placement = NonNullable<ToastVariants["placement"]>;
const placements = [
"top start",
"top",
"top end",
"bottom start",
"bottom",
"bottom end",
] as const;
// One queue + provider per placement so the toast mounts in that corner.
const placementQueues = Object.fromEntries(
placements.map((p) => [
p,
new ToastQueue<ToastContentValue>({ maxVisibleToasts: 3 }),
]),
) as Record<Placement, ToastQueue<ToastContentValue>>;
onBeforeUnmount(() => {
for (const q of Object.values(placementQueues)) q.destroy();
});
function showToast(placement: Placement) {
placementQueues[placement].add({
description: "活动已创建",
title: "活动已创建",
variant: "default",
});
}
</script>
<template>
<div class="flex h-full flex-col items-center justify-center gap-6">
<template v-for="p in placements" :key="p">
<ToastProvider :placement="p" :queue="placementQueues[p]" to="body" />
</template>
<div class="flex max-w-xs flex-wrap justify-center gap-2">
<Button
v-for="p in placements"
:key="p"
size="sm"
variant="secondary"
@click="showToast(p)"
>
{{ p }}
</Button>
</div>
</div>
</template>