-
Notifications
You must be signed in to change notification settings - Fork 456
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: added autoscrolling cards & ui fixes for testimonials
- Loading branch information
1 parent
1a9ff76
commit 420fe84
Showing
4 changed files
with
126 additions
and
91 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
'use client'; | ||
|
||
import { cn } from '@/lib/utils'; | ||
import React, { useEffect, useState } from 'react'; | ||
import { Tweet } from 'react-tweet'; | ||
|
||
export const InfiniteMovingCards = ({ | ||
items, | ||
direction = 'left', | ||
speed = 'fast', | ||
pauseOnHover = true, | ||
className, | ||
}: { | ||
items: string[]; | ||
direction?: 'left' | 'right'; | ||
speed?: 'fast' | 'normal' | 'slow'; | ||
pauseOnHover?: boolean; | ||
className?: string; | ||
}) => { | ||
const containerRef = React.useRef<HTMLDivElement>(null); | ||
const scrollerRef = React.useRef<HTMLUListElement>(null); | ||
|
||
useEffect(() => { | ||
addAnimation(); | ||
}, []); | ||
const [start, setStart] = useState(false); | ||
function addAnimation() { | ||
if (containerRef.current && scrollerRef.current) { | ||
const scrollerContent = Array.from(scrollerRef.current.children); | ||
|
||
scrollerContent.forEach((item) => { | ||
const duplicatedItem = item.cloneNode(true); | ||
if (scrollerRef.current) { | ||
scrollerRef.current.appendChild(duplicatedItem); | ||
} | ||
}); | ||
|
||
getDirection(); | ||
getSpeed(); | ||
setStart(true); | ||
} | ||
} | ||
const getDirection = () => { | ||
if (containerRef.current) { | ||
if (direction === 'left') { | ||
containerRef.current.style.setProperty( | ||
'--animation-direction', | ||
'forwards' | ||
); | ||
} else { | ||
containerRef.current.style.setProperty( | ||
'--animation-direction', | ||
'reverse' | ||
); | ||
} | ||
} | ||
}; | ||
const getSpeed = () => { | ||
if (containerRef.current) { | ||
if (speed === 'fast') { | ||
containerRef.current.style.setProperty('--animation-duration', '20s'); | ||
} else if (speed === 'normal') { | ||
containerRef.current.style.setProperty('--animation-duration', '40s'); | ||
} else { | ||
containerRef.current.style.setProperty('--animation-duration', '80s'); | ||
} | ||
} | ||
}; | ||
return ( | ||
<div | ||
ref={containerRef} | ||
className={cn( | ||
'scroller relative z-20 max-w-7xl overflow-hidden [mask-image:linear-gradient(to_right,transparent,white_20%,white_80%,transparent)]', | ||
className | ||
)} | ||
> | ||
<ul | ||
ref={scrollerRef} | ||
className={cn( | ||
' flex min-w-full shrink-0 gap-4 py-4 w-max flex-nowrap', | ||
start && 'animate-scroll ', | ||
pauseOnHover && 'hover:[animation-play-state:paused]' | ||
)} | ||
> | ||
{items.map((id, index) => ( | ||
<li | ||
className="w-[350px] min-h-fit max-w-full relative rounded-2xl flex-shrink-0 px-8 py-6 md:w-[450px]" | ||
// style={{ | ||
// background: | ||
// 'linear-gradient(180deg, var(--slate-800), var(--slate-900)', | ||
// }} | ||
key={index} | ||
> | ||
<Tweet id={id} /> | ||
</li> | ||
))} | ||
</ul> | ||
</div> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters