fix: use window.getComputedStyle if element.computedStyleMap is not defined

This commit is contained in:
p-sw 2024-05-26 19:33:53 +09:00
parent 5b87eda4d6
commit de9b27b1c9

View File

@ -188,12 +188,34 @@ const ToastTemplate = ({
return () => clearTimeout(timeout); return () => clearTimeout(timeout);
} }
if (toastData.life === "dead") { if (toastData.life === "dead") {
const transitionDuration = ref.current let transitionDuration: {
?.computedStyleMap()
?.get("transition-duration") as {
value: number; value: number;
unit: string; unit: string;
}; } | null;
if (!ref.current) {
transitionDuration = null;
console.log("not found current");
} else if (ref.current.computedStyleMap !== undefined) {
transitionDuration = ref.current
.computedStyleMap()
.get("transition-duration") as { value: number; unit: string };
console.log(
`calculated transition duration via computedStyleMap ${transitionDuration}`
);
} else {
const style = /(\d+(\.\d+)?)(.+)/.exec(
window.getComputedStyle(ref.current).transitionDuration
);
transitionDuration = style
? {
value: parseFloat(style[1] ?? "0"),
unit: style[3] ?? style[2] ?? "s",
}
: null;
console.log(
`calculated transition duration via getComputedStyle ${JSON.stringify(transitionDuration)}`
);
}
if (!transitionDuration) { if (!transitionDuration) {
delete toasts[id]; delete toasts[id];
notify(); notify();