-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Expand file tree
/
Copy pathindex.tsx
More file actions
137 lines (128 loc) · 4.11 KB
/
index.tsx
File metadata and controls
137 lines (128 loc) · 4.11 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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
import React, { useState, useEffect } from 'react';
import clsx from 'clsx';
import styles from './styles.module.css';
import TestimonialItem from '@site/src/components/Testimonials/TestimonialItem';
const items = [
{
author: 'Marc Rousavy',
company: 'Margelo',
body: 'We’ve used Reanimated and Gesture Handler for a ton of apps already - it’s amazingly simple yet poweful! 😍',
link: 'https://twitter.com/mrousavy/status/1754909520571019756',
image: {
alt: 'marc rousavy',
src: 'https://pbs.twimg.com/profile_images/1713946397391667200/l-LXWNl2_400x400.jpg',
},
},
{
author: 'Andrew Lo',
company: 'Shopify',
body: 'They enable us app devs to make our users feel delight, have fun, and enjoy using our apps more.',
link: 'https://twitter.com/alotoronto/status/1754905332709576823',
image: {
alt: 'andrew lo',
src: 'https://pbs.twimg.com/profile_images/870388069819707393/WSdiZCDG_400x400.jpg',
},
},
{
author: 'Mo Gorhom',
body: `Reanimated and Gesture Handler are the reason why I shifted my focus from native (objc&java) development to React Native 🖤.`,
link: 'https://twitter.com/gorhom/status/1754974706782896465',
image: {
alt: 'mo gorhom',
src: 'https://pbs.twimg.com/profile_images/1699071865996869632/R09iQ1T5_400x400.jpg',
},
},
{
author: 'Brandon Austin',
body: `I’ve built dozens of apps, each and every one of them have used both Reanimated and Gesture Handler at different levels of complexity.`,
link: 'https://twitter.com/bran_aust/status/1754907731536863670',
image: {
alt: 'brandon austin',
src: 'https://pbs.twimg.com/profile_images/1886569538356977664/HSO3O8hT_400x400.jpg',
},
},
];
const TestimonialList = () => {
const [activeIndex, setActiveIndex] = useState(0);
useEffect(() => {
const updateHeight = () => {
const testimonialContainer = document.querySelector<HTMLElement>(
`.testimonialContainer-${activeIndex}`
);
const testimonialSlides =
document.querySelector<HTMLElement>('.testimonialSlides');
if (
testimonialContainer.childElementCount === 1 &&
testimonialSlides.offsetHeight > testimonialContainer.offsetHeight
) {
return;
}
testimonialSlides.style.height = `${testimonialContainer.offsetHeight}px`;
};
updateHeight();
window.addEventListener('resize', updateHeight);
return () => {
window.removeEventListener('resize', updateHeight);
};
}, [activeIndex]);
const handleDotClick = (index) => {
setActiveIndex(index);
};
const renderedItems = [];
for (let i = 0; i < items.length; i += 2) {
renderedItems.push(
<div
className={clsx(
`testimonialContainer-${i / 2}`,
styles.testimonialPair
)}
key={i}>
<TestimonialItem
company={items[i].company}
image={items[i].image}
link={items[i].link}
author={items[i].author}>
{items[i].body}
</TestimonialItem>
{i + 1 < items.length && (
<TestimonialItem
company={items[i + 1].company}
image={items[i + 1].image}
link={items[i + 1].link}
author={items[i + 1].author}>
{items[i + 1].body}
</TestimonialItem>
)}
</div>
);
}
return (
<div className={styles.testimonialSlides}>
<div className="testimonialSlides">
{renderedItems.map((item, idx) => (
<div
key={idx}
className={clsx(
styles.testimonialSlide,
activeIndex === idx ? styles.activeTestimonialSlide : ''
)}>
{item}
</div>
))}
</div>
<div className={styles.dotsContainer}>
{renderedItems.map((_, idx) => (
<span
key={idx}
className={clsx(
styles.dot,
idx === activeIndex && styles.activeDot
)}
onClick={() => handleDotClick(idx)}
/>
))}
</div>
</div>
);
};
export default TestimonialList;