fix: retain pending Toast and Table fidelity corrections
This commit is contained in:
@@ -3,10 +3,12 @@ import { onBeforeUnmount } from "vue";
|
||||
import {
|
||||
Button,
|
||||
ToastProvider,
|
||||
createToastFunction,
|
||||
ToastQueue,
|
||||
type ToastContentValue,
|
||||
} from "@heroui-vue/components";
|
||||
import type { ToastVariants } from "@heroui-vue/styles";
|
||||
|
||||
type Placement = NonNullable<ToastVariants["placement"]>;
|
||||
|
||||
const placements = [
|
||||
"top start",
|
||||
@@ -17,31 +19,42 @@ const placements = [
|
||||
"bottom end",
|
||||
] as const;
|
||||
|
||||
// One queue + provider per placement so the toast is actually mounted
|
||||
// into that corner of the viewport.
|
||||
const instances = placements.map((placement) => {
|
||||
const queue = new ToastQueue<ToastContentValue>({ maxVisibleToasts: 2 });
|
||||
return { placement, queue, toast: createToastFunction(queue) };
|
||||
// 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();
|
||||
});
|
||||
onBeforeUnmount(() =>
|
||||
instances.forEach((instance) => instance.queue.destroy()),
|
||||
);
|
||||
|
||||
function showToast(placement: Placement) {
|
||||
placementQueues[placement].add({
|
||||
description: "活动已创建",
|
||||
title: "活动已创建",
|
||||
variant: "default",
|
||||
});
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div class="flex flex-wrap gap-3">
|
||||
<template v-for="inst in instances" :key="inst.placement">
|
||||
<Button
|
||||
variant="secondary"
|
||||
@click="inst.toast(`位置:${inst.placement}`, { timeout: 3000 })"
|
||||
>
|
||||
{{ inst.placement }}
|
||||
</Button>
|
||||
<ToastProvider
|
||||
:queue="inst.queue"
|
||||
:placement="inst.placement"
|
||||
to="body"
|
||||
/>
|
||||
<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>
|
||||
|
||||
Reference in New Issue
Block a user