Skip to content

Commit f4752cc

Browse files
committed
Count testimonials to fix grid layout (why was this hardcoded??)
1 parent a53347c commit f4752cc

File tree

3 files changed

+21
-6
lines changed

3 files changed

+21
-6
lines changed

src/components/common-sections/testimonials/components/marquee.tsx

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,13 @@ const Marquee = dynamic(() => import('react-fast-marquee').then(e => e.default),
1313

1414
interface MarqueeWrapperProps {
1515
children: ReactNode;
16+
columnsCount: number;
1617
}
1718

18-
export const MarqueeWrapper = ({ children }: MarqueeWrapperProps) => {
19+
export const MarqueeWrapper = ({
20+
children,
21+
columnsCount
22+
}: MarqueeWrapperProps) => {
1923
const isMobile = useIsMobile();
2024
const [isRunning, setIsRunning] = useState(true);
2125

@@ -29,7 +33,11 @@ export const MarqueeWrapper = ({ children }: MarqueeWrapperProps) => {
2933

3034
return (
3135
<Marquee pauseOnHover={!isMobile} play={isRunning}>
32-
<StyledTestimonialGrid onTouchStart={pause} onTouchEnd={play}>
36+
<StyledTestimonialGrid
37+
$columnsCount={columnsCount}
38+
onTouchStart={pause}
39+
onTouchEnd={play}
40+
>
3341
{children}
3442
</StyledTestimonialGrid>
3543
</Marquee>

src/components/common-sections/testimonials/components/testimonials.tsx

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,12 @@ import { getGithubDownloadStats } from '@/lib/services/get-github-download-stats
1010
export const TestimonialsGrid = async () => {
1111
const userDownloads = await getGithubDownloadStats();
1212
const testimonalsData = allTestimonials.concat(allTestimonials);
13-
const testimonialsChunkedData = Array.from({ length: Math.ceil(testimonalsData.length / 3) }, (_, index) =>
13+
14+
const chunkCount = Math.ceil(testimonalsData.length / 3);
15+
16+
const testimonialsChunkedData = Array.from({
17+
length: Math.ceil(testimonalsData.length / 3)
18+
}, (_, index) =>
1419
testimonalsData.slice(index * 3, index * 3 + 3),
1520
);
1621

@@ -24,7 +29,7 @@ export const TestimonialsGrid = async () => {
2429
$align="center"
2530
/>
2631

27-
<MarqueeWrapper>
32+
<MarqueeWrapper columnsCount={chunkCount}>
2833
{testimonialsChunkedData.map((testimonialChunk, rowIndex) => (
2934
<div key={rowIndex}>
3035
{testimonialChunk.map((testimonial, colIndex) => {

src/components/common-sections/testimonials/testimonials.styles.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,10 @@ export const StyledAuthorDetails = styled.cite`
5757
}
5858
`;
5959

60-
export const StyledTestimonialGrid = styled.div`
61-
--grid-items: 36;
60+
export const StyledTestimonialGrid = styled.div<{
61+
$columnsCount: number;
62+
}>`
63+
--grid-items: ${({ $columnsCount }) => $columnsCount};
6264
display: grid;
6365
grid-template-columns: repeat(var(--grid-items), 343px);
6466
gap: 16px;

0 commit comments

Comments
 (0)