fix: retain pending Toast and Table fidelity corrections

This commit is contained in:
maoyingjie
2026-10-25 21:24:09 +08:00
parent 2ce80b17da
commit a2ca6ed0b8
42 changed files with 2153 additions and 260 deletions
@@ -1,5 +1,16 @@
<script lang="ts">
import { defineComponent, h, inject, useAttrs, type PropType } from "vue";
import {
computed,
defineComponent,
h,
inject,
isVNode,
ref,
useAttrs,
watch,
type PropType,
type VNodeChild,
} from "vue";
import type { ToastVariants } from "@heroui-vue/styles";
import { toastContextKey } from "./context";
import {
@@ -9,6 +20,19 @@ import {
ToastWarningIcon,
} from "./icons";
/** Identity of the indicator payload: element type, or "default" for the built-in icon. */
function childrenKind(children: VNodeChild): unknown {
if (children == null || children === false) return "default";
if (Array.isArray(children)) {
const first = children.find(
(c) => isVNode(c) || (typeof c === "string" && c.trim() !== ""),
);
return first === undefined ? "default" : childrenKind(first as VNodeChild);
}
if (isVNode(children)) return children.type;
return "default";
}
export default defineComponent({
name: "ToastIndicator",
inheritAttrs: false,
@@ -22,6 +46,11 @@ export default defineComponent({
setup(props, { slots }) {
const attrs = useAttrs();
const ctx = inject(toastContextKey, null);
// Swap marker: animate content that replaces earlier content (promise
// settle) without animating the first paint.
const hasSwapped = ref(false);
let previousKind: unknown;
function defaultIcon() {
switch (props.variant) {
case "success":
@@ -34,16 +63,28 @@ export default defineComponent({
return h(ToastInfoIcon, { "data-slot": "toast-default-icon" });
}
}
return () =>
h(
return () => {
const custom = slots.default?.();
const kind = custom ? childrenKind(custom) : childrenKind(null);
if (previousKind === undefined) {
previousKind = kind;
} else if (previousKind !== kind) {
previousKind = kind;
hasSwapped.value = true;
}
return h(
props.as,
{
...attrs,
class: [ctx?.slots.value.indicator(), attrs.class],
"data-slot": "toast-indicator",
"data-swapped": hasSwapped.value || undefined,
},
slots.default?.() ?? [defaultIcon()],
custom ?? [defaultIcon()],
);
};
},
});
</script>