Skip to content

Commit 5d91893

Browse files
committed
Add delay to nav progress animation
1 parent fdadf77 commit 5d91893

File tree

1 file changed

+32
-23
lines changed

1 file changed

+32
-23
lines changed

Diff for: app/components/layout/NavigationProgressBar.tsx

+32-23
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import {useNavigation} from '@remix-run/react';
22
import {useNProgress} from '@tanem/react-nprogress';
3-
4-
import {cn} from '~/lib/utils';
3+
import {AnimatePresence, m} from 'framer-motion';
54

65
export function NavigationProgressBar() {
76
const navigation = useNavigation();
@@ -11,27 +10,37 @@ export function NavigationProgressBar() {
1110
});
1211

1312
return (
14-
<div
15-
className={cn([isFinished ? 'opacity-0' : 'opacity-100'])}
16-
style={{
17-
transition: `opacity ${animationDuration}ms linear`,
18-
}}
19-
>
20-
<div
21-
className="fixed left-0 top-0 z-[1042] h-[3px] w-full rounded-r-full bg-primary"
22-
style={{
23-
marginLeft: `${(-1 + progress) * 100}%`,
24-
transition: `margin-left ${animationDuration}ms linear`,
25-
}}
26-
>
27-
<div
28-
className="absolute right-0 block h-full w-[100px] translate-y-[-4px] rotate-3 opacity-100"
29-
style={{
30-
boxShadow:
31-
'0 0 10px rgb(var(--primary)), 0 0 5px rgb(var(--primary))',
13+
<AnimatePresence>
14+
{!isFinished && (
15+
<m.div
16+
animate={{opacity: 1}}
17+
exit={{opacity: 0}}
18+
initial={{opacity: 0}}
19+
transition={{
20+
delay: 0.15,
21+
duration: animationDuration / 1000,
3222
}}
33-
/>
34-
</div>
35-
</div>
23+
>
24+
<m.div
25+
animate={{
26+
marginLeft: `${(-1 + progress) * 100}%`,
27+
transition: {
28+
duration: animationDuration / 1000,
29+
ease: 'linear',
30+
},
31+
}}
32+
className="fixed left-0 top-0 z-[1042] h-[3px] w-full rounded-r-full bg-primary"
33+
>
34+
<div
35+
className="absolute right-0 block h-full w-[100px] translate-y-[-4px] rotate-3 opacity-100"
36+
style={{
37+
boxShadow:
38+
'0 0 10px rgb(var(--primary)), 0 0 5px rgb(var(--primary))',
39+
}}
40+
/>
41+
</m.div>
42+
</m.div>
43+
)}
44+
</AnimatePresence>
3645
);
3746
}

0 commit comments

Comments
 (0)