Skip to content

Commit 7caa216

Browse files
authored
feat: add progress bar animation (#509)
* add progress bar animation * fix formatting
1 parent 2ffae54 commit 7caa216

File tree

1 file changed

+40
-16
lines changed

1 file changed

+40
-16
lines changed

src/components/AboutUs/RoadmapSection.tsx

Lines changed: 40 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,32 @@
1-
import React from 'react';
2-
import { motion } from 'framer-motion';
1+
import React, { useRef } from 'react';
2+
import { motion, useScroll, useTransform } from 'framer-motion';
33
import { roadmapItems, roadmapContent } from '@/constants/aboutUs/roadmap';
44

55
const RoadmapSection: React.FC = () => {
6+
const sectionRef = useRef<HTMLElement>(null);
7+
const timelineRef = useRef<HTMLDivElement>(null);
8+
const mobileTimelineRef = useRef<HTMLDivElement>(null);
9+
10+
const { scrollYProgress } = useScroll({
11+
target: sectionRef,
12+
offset: ['start end', 'end start'],
13+
});
14+
15+
const progressHeight = useTransform(
16+
scrollYProgress,
17+
[0, 0.8],
18+
['0%', '100%'],
19+
);
20+
21+
const mobileProgressHeight = useTransform(
22+
scrollYProgress,
23+
[0, 0.8],
24+
['0%', '100%'],
25+
);
26+
627
return (
728
<section
29+
ref={sectionRef}
830
id={roadmapContent.sectionId}
931
className="w-full py-24 bg-white dark:bg-gray-900"
1032
>
@@ -45,13 +67,14 @@ const RoadmapSection: React.FC = () => {
4567
</motion.p>
4668
</div>
4769

48-
<div className="hidden md:block relative w-full mt-20">
70+
<div
71+
ref={timelineRef}
72+
className="hidden md:block relative w-full mt-20"
73+
>
74+
<div className="absolute top-0 bottom-0 left-1/2 w-0.5 bg-gray-200 dark:bg-gray-600/50 transform -translate-x-1/2" />
4975
<motion.div
50-
className="absolute top-0 bottom-0 left-1/2 w-0.5 bg-gray-200 dark:bg-gray-600/50 transform -translate-x-1/2"
51-
initial={{ scaleY: 0, transformOrigin: 'top' }}
52-
whileInView={{ scaleY: 1 }}
53-
viewport={{ once: true }}
54-
transition={{ duration: 1.2 }}
76+
className="absolute top-0 left-1/2 w-0.5 bg-gradient-to-b from-blue-500 via-purple-500 to-red-500 transform -translate-x-1/2 origin-top"
77+
style={{ height: progressHeight }}
5578
/>
5679

5780
{/* Roadmap items */}
@@ -102,18 +125,19 @@ const RoadmapSection: React.FC = () => {
102125
</div>
103126

104127
{/* Mobile Timeline - Single Column */}
105-
<div className="md:hidden relative w-full mt-16">
128+
<div
129+
ref={mobileTimelineRef}
130+
className="md:hidden relative w-full mt-16"
131+
>
106132
<div className="flex flex-col items-start space-y-12">
107-
{/* Vertical connecting line */}
108-
<motion.div
133+
<div
109134
className="absolute top-0 bottom-0 left-5 w-0.5 bg-slate-200 dark:bg-gray-700 h-full"
110135
style={{ zIndex: 1 }}
111-
initial={{ scaleY: 0, transformOrigin: 'top' }}
112-
whileInView={{ scaleY: 1 }}
113-
viewport={{ once: true }}
114-
transition={{ duration: 1.2 }}
115136
/>
116-
137+
<motion.div
138+
className="absolute top-0 left-5 w-0.5 bg-gradient-to-b from-blue-500 via-purple-500 to-red-500 origin-top"
139+
style={{ height: mobileProgressHeight, zIndex: 2 }}
140+
/>
117141
{roadmapItems.map((item, index) => (
118142
<motion.div
119143
key={index}

0 commit comments

Comments
 (0)