@aria-ui/presence
Advanced tools
Comparing version 0.0.15 to 0.0.16
// src/use-presence.ts | ||
import { | ||
createSignal, | ||
useEffect, | ||
useEventListener | ||
useEffect | ||
} from "@aria-ui/core"; | ||
import { getEventTarget } from "@zag-js/dom-query"; | ||
function usePresence(element, open) { | ||
@@ -20,16 +18,25 @@ const visible = createSignal(open.peek()); | ||
visible.set(true); | ||
} else if (getAnimationName(element) === "none") { | ||
visible.set(false); | ||
return; | ||
} | ||
}); | ||
useEventListener(element, "animationend", (event) => { | ||
if (getAnimationName(element).includes(event.animationName) && getEventTarget(event) === element && !open.peek()) { | ||
const animations = element.getAnimations(); | ||
if (animations.length === 0) { | ||
visible.set(false); | ||
return; | ||
} | ||
let canceled = false; | ||
Promise.all(animations.map((animation) => animation.finished)).then(() => { | ||
if (!canceled) { | ||
visible.set(false); | ||
} | ||
}).catch((error) => { | ||
throw new Error("[aria-ui] Failed to wait for animation to finish", { | ||
cause: error | ||
}); | ||
}); | ||
return () => { | ||
canceled = true; | ||
}; | ||
}); | ||
return visible; | ||
} | ||
function getAnimationName(element) { | ||
return getComputedStyle(element).animationName || "none"; | ||
} | ||
function show(element) { | ||
@@ -36,0 +43,0 @@ if (element.style.display === "none") { |
{ | ||
"name": "@aria-ui/presence", | ||
"type": "module", | ||
"version": "0.0.15", | ||
"version": "0.0.16", | ||
"private": false, | ||
@@ -18,7 +18,7 @@ "sideEffects": false, | ||
"dependencies": { | ||
"@zag-js/dom-query": "^0.74.2", | ||
"@zag-js/dom-query": "^0.77.0", | ||
"@aria-ui/core": "^0.0.19" | ||
}, | ||
"devDependencies": { | ||
"tsup": "^8.3.0", | ||
"tsup": "^8.3.5", | ||
"typescript": "^5.6.3" | ||
@@ -25,0 +25,0 @@ }, |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
3070
57
+ Added@zag-js/dom-query@0.77.1(transitive)
Updated@zag-js/dom-query@^0.77.0