import { AnimatePresence, useAnimate, usePresence } from "framer-motion"; import { useEffect } from "react"; import { cn } from "~/utils/cn"; type LoadingBarDividerProps = { isLoading: boolean; className?: string; }; export function LoadingBarDivider({ isLoading, className }: LoadingBarDividerProps) { return (
); } export function AnimationDivider({ isLoading }: LoadingBarDividerProps) { const [scope, animate] = useAnimate(); const [isPresent, safeToRemove] = usePresence(); useEffect(() => { if (!scope.current) return; if (isPresent) { const enterAnimation = async () => { await animate( scope.current, { left: ["-100%", "100%"], width: "100%" }, { duration: 2, ease: "easeOut", repeat: Infinity } ); }; enterAnimation(); } else { const exitAnimation = async () => { await animate(scope.current, { opacity: 0 }); safeToRemove(); }; exitAnimation(); } }, [isPresent, isLoading]); return ( {isLoading && (
)} ); }