@aria-ui/presence
Advanced tools
Comparing version 0.0.11 to 0.0.12
@@ -6,4 +6,4 @@ import { ConnectableElement, ReadonlySignal } from '@aria-ui/core'; | ||
*/ | ||
declare function usePresence(element: ConnectableElement, present: ReadonlySignal<boolean>): void; | ||
declare function usePresence(element: ConnectableElement, open: ReadonlySignal<boolean>): ReadonlySignal<boolean>; | ||
export { usePresence }; |
// src/use-presence.ts | ||
import { | ||
createSignal, | ||
useEffect, | ||
@@ -7,6 +8,6 @@ useEventListener | ||
import { getEventTarget } from "@zag-js/dom-query"; | ||
function usePresence(element, present) { | ||
function usePresence(element, open) { | ||
const visible = createSignal(open.peek()); | ||
useEffect(element, () => { | ||
const initialPresent = present.peek(); | ||
if (initialPresent) { | ||
if (visible.get()) { | ||
show(element); | ||
@@ -17,18 +18,15 @@ } else { | ||
}); | ||
const handleAnimationEnd = (event) => { | ||
if (getAnimationName(element).includes(event.animationName) && getEventTarget(event) === element && !present.peek()) { | ||
hide(element); | ||
useEffect(element, () => { | ||
if (open.get()) { | ||
visible.set(true); | ||
} else if (getAnimationName(element) === "none") { | ||
visible.set(false); | ||
} | ||
}; | ||
useEffect(element, () => handlePresentChange(element, present.get())); | ||
useEventListener(element, "animationend", handleAnimationEnd); | ||
} | ||
function handlePresentChange(element, present) { | ||
if (present) { | ||
show(element); | ||
} else { | ||
if (getAnimationName(element) === "none") { | ||
hide(element); | ||
}); | ||
useEventListener(element, "animationend", (event) => { | ||
if (getAnimationName(element).includes(event.animationName) && getEventTarget(event) === element && !open.peek()) { | ||
visible.set(false); | ||
} | ||
} | ||
}); | ||
return visible; | ||
} | ||
@@ -35,0 +33,0 @@ function getAnimationName(element) { |
{ | ||
"name": "@aria-ui/presence", | ||
"type": "module", | ||
"version": "0.0.11", | ||
"version": "0.0.12", | ||
"private": false, | ||
@@ -13,7 +13,7 @@ "sideEffects": false, | ||
"@aria-ui/core": "^0.0.16", | ||
"@zag-js/dom-query": "^0.58.0" | ||
"@zag-js/dom-query": "^0.59.0" | ||
}, | ||
"devDependencies": { | ||
"tsup": "^8.1.0", | ||
"typescript": "^5.5.2" | ||
"typescript": "^5.5.3" | ||
}, | ||
@@ -20,0 +20,0 @@ "publishConfig": { |
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
2932
50
+ Added@zag-js/dom-query@0.59.0(transitive)
Updated@zag-js/dom-query@^0.59.0