This commit is contained in:
2024-07-20 09:32:01 +03:00
parent 5c6e7cf5f5
commit 54c9ca8908
48 changed files with 1057 additions and 87 deletions

View File

@@ -0,0 +1,34 @@
import {forwardRef, RefObject, useContext, useRef} from "react";
import {getRouterContext, Outlet} from "@tanstack/react-router";
import {motion, useIsPresent} from "framer-motion";
import {cloneDeep} from "lodash";
const AnimatedOutlet = forwardRef<HTMLDivElement>((_, ref) => {
const RouterContext = getRouterContext();
const routerContext = useContext(RouterContext);
const renderedContext = useRef(routerContext);
const isPresent = useIsPresent();
if (isPresent) {
renderedContext.current = cloneDeep(routerContext);
}
return (
<motion.div ref={ref}
initial={{x: "-100%"}}
animate={{x: 0}}
transition={{duration: 0.3}}
onAnimationComplete={()=>{
(ref as RefObject<HTMLDivElement>).current?.style.removeProperty("transform")
}}
>
<RouterContext.Provider value={renderedContext.current}>
<Outlet/>
</RouterContext.Provider>
</motion.div>
);
});
export default AnimatedOutlet