From cab773cb2e2e94692fef90fc756ce6fc4637ab07 Mon Sep 17 00:00:00 2001 From: Daniil034 Date: Sat, 18 May 2024 21:27:12 +0300 Subject: [PATCH] fix: pause video on scroll --- .../TestimonialsSection.tsx | 28 ++++++++++++++++--- .../TestimonialItem/TestimonialItem.tsx | 20 +++++++++---- src/shared/components/Carousel/Carousel.tsx | 28 ++++++++++--------- 3 files changed, 54 insertions(+), 22 deletions(-) diff --git a/src/sections/TestimonialsSection/TestimonialsSection.tsx b/src/sections/TestimonialsSection/TestimonialsSection.tsx index 712794c..8bc7d16 100644 --- a/src/sections/TestimonialsSection/TestimonialsSection.tsx +++ b/src/sections/TestimonialsSection/TestimonialsSection.tsx @@ -1,9 +1,13 @@ +'use client' + import {Container} from "@/shared/components/Container/Container"; import styles from './TestimonialsSection.module.css'; import {Carousel} from "@/shared/components/Carousel/Carousel"; import {TestimonialItem, TestimonialItemProps} from "@/sections/TestimonialsSection/components/TestimonialItem/TestimonialItem"; +import {ComponentProps, useRef} from "react"; +import Slider from "react-slick"; -const testimonialsSrc: TestimonialItemProps[] = [ +const testimonialsSrc: Omit[] = [ { src: "drop/videos/1.mp4", clientName: "Имя клиента", @@ -27,13 +31,29 @@ const testimonialsSrc: TestimonialItemProps[] = [ ] export function TestimonialsSection() { + const videosRef = useRef>([]) + const newRef = useRef(null) + + const settings: ComponentProps = { + infinite: false, + beforeChange(currentSlide: number, nextSlide: number) { + videosRef.current[currentSlide].pause(); + } + } + + const handlePause = () => { + console.log(newRef.current) + newRef!.current!.pause() + } + return (

Посмотрите отзывы от наших клиентов

- - {testimonialsSrc.map(item => ( - + + {testimonialsSrc.map((item, index) => ( + ))}
diff --git a/src/sections/TestimonialsSection/components/TestimonialItem/TestimonialItem.tsx b/src/sections/TestimonialsSection/components/TestimonialItem/TestimonialItem.tsx index abbebcf..864acf3 100644 --- a/src/sections/TestimonialsSection/components/TestimonialItem/TestimonialItem.tsx +++ b/src/sections/TestimonialsSection/components/TestimonialItem/TestimonialItem.tsx @@ -1,17 +1,24 @@ import styles from './TestimonialItem.module.css' +import {forwardRef, Ref} from "react"; export type TestimonialItemProps = { src: string, keyPhrase: string, - clientName: string + clientName: string, + index: number }; -export function TestimonialItem(props: TestimonialItemProps) { - const {src, keyPhrase, clientName, ...otherProps} = props; +export const TestimonialItem = forwardRef((props: TestimonialItemProps, ref: Ref) => { + const {src, keyPhrase, clientName, index, ...otherProps} = props; + + if (typeof ref === 'function') { + return + } + return (
-
); -}; \ No newline at end of file + +}); + +TestimonialItem.displayName = "TestimonialItem" \ No newline at end of file diff --git a/src/shared/components/Carousel/Carousel.tsx b/src/shared/components/Carousel/Carousel.tsx index 4c408ab..0f1b034 100644 --- a/src/shared/components/Carousel/Carousel.tsx +++ b/src/shared/components/Carousel/Carousel.tsx @@ -8,24 +8,26 @@ import sliderArrowLeft from "@/shared/assets/icons/sliderArrowLeft.svg"; import sliderArrowRight from "@/shared/assets/icons/sliderArrowRight.svg"; type Props = { - children: ReactNode + children: ReactNode, + settings?: ComponentProps }; -const settings: ComponentProps = { - infinite: true, - speed: 500, - slidesToShow: 1, - slidesToScroll: 1, - lazyLoad: 'progressive', - prevArrow: {''}/, - nextArrow: {''}/, - dots: true -}; +export function Carousel({children, settings}: Props) { + const defaultSettings: ComponentProps = { + infinite: true, + speed: 500, + slidesToShow: 1, + slidesToScroll: 1, + lazyLoad: 'progressive', + prevArrow: {''}/, + nextArrow: {''}/, + dots: true, + ...settings + }; -export function Carousel({children}: Props) { return (
- + {children}