From 58d0181db52e82b893418b47e700afc2f2ee41c1 Mon Sep 17 00:00:00 2001 From: krutoo Date: Mon, 2 Sep 2024 12:30:18 +0500 Subject: [PATCH] #290 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - product-carousel: добавлен проп needRequestOptions (minor) --- .../product-carousel/product-carousel.tsx | 15 ++++++++++++++- src/desktop/components/product-carousel/types.ts | 3 +++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/src/desktop/components/product-carousel/product-carousel.tsx b/src/desktop/components/product-carousel/product-carousel.tsx index aedb0d2..7614c02 100644 --- a/src/desktop/components/product-carousel/product-carousel.tsx +++ b/src/desktop/components/product-carousel/product-carousel.tsx @@ -22,6 +22,10 @@ const getSizeClasses = (size: ProductCarouselProps['itemSize']) => ] : []; +const defaultNeedRequestOptions: IntersectionObserverInit = { + rootMargin: '200px 0px 200px 0px', +}; + /** * Карусель рекомендованных товаров. * @param props Свойства. @@ -37,6 +41,7 @@ export function ProductCarousel({ children, controlProps, itemImageRatio = 1, + needRequestOptions = defaultNeedRequestOptions, }: ProductCarouselProps) { const layer = useLayer(); const needBigArrows = useMedia('(min-width: 1600px)'); @@ -54,7 +59,15 @@ export function ProductCarousel({ const itemWidth = useClientWidth(firstItemRef, [items.length]); // инициируем загрузку данных, когда компонент почти попал в зону видимости - const options = useMemo(() => ({ rootMargin: '200px 0px 200px 0px' }), []); + const { root, rootMargin, threshold } = needRequestOptions; + const options = useMemo( + () => ({ + root, + rootMargin, + threshold, + }), + [root, rootMargin, threshold], + ); useIntersection( rootRef, entry => { diff --git a/src/desktop/components/product-carousel/types.ts b/src/desktop/components/product-carousel/types.ts index 44eff12..3689c8a 100644 --- a/src/desktop/components/product-carousel/types.ts +++ b/src/desktop/components/product-carousel/types.ts @@ -25,6 +25,9 @@ export interface ProductCarouselProps { /** Сработает при попадании карусели в область достаточно близкую к viewport'у. */ onNeedRequest?: () => void; + /** Опции области, которая вызовет onNeedRequest. */ + needRequestOptions?: IntersectionObserverInit; + /** Предоставит свойства для элемента карусели. */ itemProps?: { style?: CSSProperties; className?: string };