@restart/ui
Advanced tools
Comparing version 1.5.2 to 1.5.3
@@ -7,2 +7,3 @@ import React from 'react'; | ||
initial: boolean; | ||
isStale: () => boolean; | ||
} | ||
@@ -9,0 +10,0 @@ export type TransitionHandler = (options: TransitionFunctionOptions) => void | Promise<void>; |
@@ -24,9 +24,14 @@ "use strict"; | ||
if (!ref.current) { | ||
return; | ||
return undefined; | ||
} | ||
let stale = false; | ||
handleTransition({ | ||
in: inProp, | ||
element: ref.current, | ||
initial: isInitialRef.current | ||
initial: isInitialRef.current, | ||
isStale: () => stale | ||
}); | ||
return () => { | ||
stale = true; | ||
}; | ||
}, [inProp, handleTransition]); | ||
@@ -56,2 +61,7 @@ (0, _react.useEffect)(() => { | ||
const [exited, setExited] = (0, _react.useState)(!inProp); | ||
// TODO: I think this needs to be in an effect | ||
if (inProp && exited) { | ||
setExited(false); | ||
} | ||
const ref = useTransition({ | ||
@@ -61,4 +71,4 @@ in: !!inProp, | ||
const onFinish = () => { | ||
if (options.isStale()) return; | ||
if (options.in) { | ||
setExited(false); | ||
onEntered == null ? void 0 : onEntered(options.element, options.initial); | ||
@@ -70,3 +80,6 @@ } else { | ||
}; | ||
Promise.resolve(transition(options)).then(onFinish); | ||
Promise.resolve(transition(options)).then(onFinish, error => { | ||
if (!options.in) setExited(true); | ||
throw error; | ||
}); | ||
} | ||
@@ -73,0 +86,0 @@ }); |
@@ -7,2 +7,3 @@ import React from 'react'; | ||
initial: boolean; | ||
isStale: () => boolean; | ||
} | ||
@@ -9,0 +10,0 @@ export type TransitionHandler = (options: TransitionFunctionOptions) => void | Promise<void>; |
@@ -15,9 +15,14 @@ import useMergedRefs from '@restart/hooks/useMergedRefs'; | ||
if (!ref.current) { | ||
return; | ||
return undefined; | ||
} | ||
let stale = false; | ||
handleTransition({ | ||
in: inProp, | ||
element: ref.current, | ||
initial: isInitialRef.current | ||
initial: isInitialRef.current, | ||
isStale: () => stale | ||
}); | ||
return () => { | ||
stale = true; | ||
}; | ||
}, [inProp, handleTransition]); | ||
@@ -47,2 +52,7 @@ useEffect(() => { | ||
const [exited, setExited] = useState(!inProp); | ||
// TODO: I think this needs to be in an effect | ||
if (inProp && exited) { | ||
setExited(false); | ||
} | ||
const ref = useTransition({ | ||
@@ -52,4 +62,4 @@ in: !!inProp, | ||
const onFinish = () => { | ||
if (options.isStale()) return; | ||
if (options.in) { | ||
setExited(false); | ||
onEntered == null ? void 0 : onEntered(options.element, options.initial); | ||
@@ -61,3 +71,6 @@ } else { | ||
}; | ||
Promise.resolve(transition(options)).then(onFinish); | ||
Promise.resolve(transition(options)).then(onFinish, error => { | ||
if (!options.in) setExited(true); | ||
throw error; | ||
}); | ||
} | ||
@@ -64,0 +77,0 @@ }); |
{ | ||
"name": "@restart/ui", | ||
"version": "1.5.2", | ||
"version": "1.5.3", | ||
"description": "Utilities for creating robust overlay components", | ||
@@ -5,0 +5,0 @@ "author": { |
Sorry, the diff of this file is too big to display
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
348507
8355