Skip to content

Commit

Permalink
Add Swiper
Browse files Browse the repository at this point in the history
  • Loading branch information
sainthiago committed Sep 7, 2022
1 parent d3c6a4c commit 3574106
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/components/Carousel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ const Carousel = (props: CarouselProps) => {

const [isLoading, setIsLoading] = useState(true);
const [currentIndex, setCurrentIndex] = useState(startIndex ?? 0);
const [dragStart, setDragStart] = useState(0);

const ref = useRef<HTMLImageElement | null>(null);

Expand Down Expand Up @@ -99,6 +100,15 @@ const Carousel = (props: CarouselProps) => {
onLoad={() => {
setTimeout(() => setIsLoading(false), 1000);
}}
onDragStart={(e) => setDragStart(e.clientX)}
onDragEnd={(e) => {
if (dragStart > e.clientX) {
scrollToRight();
return;
}

scrollToLeft();
}}
/>
</div>
</>
Expand Down

0 comments on commit 3574106

Please sign in to comment.