-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Expand file tree
/
Copy pathLoadingBarDivider.tsx
More file actions
52 lines (45 loc) · 1.33 KB
/
LoadingBarDivider.tsx
File metadata and controls
52 lines (45 loc) · 1.33 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
import { AnimatePresence, useAnimate, usePresence } from "framer-motion";
import { useEffect } from "react";
type LoadingBarDividerProps = {
isLoading: boolean;
};
export function LoadingBarDivider({ isLoading }: LoadingBarDividerProps) {
return (
<div className="relative h-px w-full overflow-hidden bg-grid-bright">
<AnimationDivider isLoading={isLoading} />
</div>
);
}
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 (
<AnimatePresence>
{isLoading && (
<div
ref={scope}
className="width-0 absolute left-0 top-0 h-full bg-gradient-to-r from-transparent from-5% via-blue-500 to-transparent to-95%"
/>
)}
</AnimatePresence>
);
}