diff --git a/docs/stories/desktop/components/product-carousel/07-custom-image-ratio.stories.tsx b/docs/stories/desktop/components/product-carousel/07-custom-image-ratio.stories.tsx new file mode 100644 index 0000000..0c5f3ee --- /dev/null +++ b/docs/stories/desktop/components/product-carousel/07-custom-image-ratio.stories.tsx @@ -0,0 +1,78 @@ +import { ProductCarousel } from '@sima-land/moleculas/desktop/components/product-carousel'; +import { ProductInfo, Parts } from '@sima-land/moleculas/common/components/product-info'; +import { ReactNode } from 'react'; +import { Layout } from '@sima-land/ui-nucleons/layout'; +import { Stepper } from '@sima-land/ui-nucleons/stepper'; +import FavSVG from '@sima-land/ui-quarks/icons/24x24/Stroked/Favorite'; +import ComparisonAddSVG from '@sima-land/ui-quarks/icons/24x24/Stroked/ComparisonAdd'; +import { items } from './fixture'; + +export const meta = { + category: 'desktop/ProductCarousel', + title: 'Неквадратные картинки', + parameters: { + layout: 'fullscreen', + }, +}; + +const Placeholder = () => ( +
+); + +const DemoBlock = ({ children }: { children: ReactNode }) => ( + + + {children} + + +); + +export default function CustomImageRatio() { + return ( + + + {items.map((item, index) => ( + + + + + + + + + {item.name} + + + + + + + + ))} + + + ); +} diff --git a/src/common/components/product-info/__test__/product-info.test.tsx b/src/common/components/product-info/__test__/product-info.test.tsx index ef08cdb..54ce994 100644 --- a/src/common/components/product-info/__test__/product-info.test.tsx +++ b/src/common/components/product-info/__test__/product-info.test.tsx @@ -5,6 +5,7 @@ import FavoriteSVG from '@sima-land/ui-quarks/icons/24x24/Stroked/Favorite'; import MagnifierPlusSVG from '@sima-land/ui-quarks/icons/24x24/Stroked/MagnifierPlus'; import { Badge } from '../../badge'; import { Stepper } from '@sima-land/ui-nucleons/stepper'; +import { createRef } from 'react'; describe('ProductInfo', () => { it('should render all parts', () => { @@ -505,4 +506,20 @@ describe('ProductInfo', () => { expect(queryAllByTestId('product-image-link')).toHaveLength(1); expect(queryAllByTestId('product-image')).toHaveLength(0); }); + + it('Parts.Image should handle "anchorRef" prop', () => { + const anchorRef = createRef(); + + render( + + + , + ); + + expect(anchorRef.current instanceof HTMLAnchorElement).toBe(true); + }); }); diff --git a/src/common/components/product-info/parts/image.tsx b/src/common/components/product-info/parts/image.tsx index f8b7b22..387ff00 100644 --- a/src/common/components/product-info/parts/image.tsx +++ b/src/common/components/product-info/parts/image.tsx @@ -18,6 +18,7 @@ export function ProductInfoImage({ children, anchorProps, sliderProps, + anchorRef, ...restProps }: ProductInfoImageProps) { const { restriction } = useContext(ProductInfoContext); @@ -34,6 +35,7 @@ export function ProductInfoImage({ ; + /** Прочие атрибуты элемента-ссылки. */ anchorProps?: AnchorHTMLAttributes; + /** Свойства слайдера. */ sliderProps?: HoverSliderProps; } diff --git a/src/desktop/components/product-carousel/product-carousel.tsx b/src/desktop/components/product-carousel/product-carousel.tsx index 3fc3238..aedb0d2 100644 --- a/src/desktop/components/product-carousel/product-carousel.tsx +++ b/src/desktop/components/product-carousel/product-carousel.tsx @@ -35,6 +35,8 @@ export function ProductCarousel({ onInViewport, onNeedRequest, children, + controlProps, + itemImageRatio = 1, }: ProductCarouselProps) { const layer = useLayer(); const needBigArrows = useMedia('(min-width: 1600px)'); @@ -82,10 +84,12 @@ export function ProductCarousel({ size: needBigArrows ? 'l' : 's', style: { zIndex: layer + 2, // чтобы кнопки были над HoverCard - top: `${itemWidth / 2}px`, + top: `${(itemWidth * itemImageRatio) / 2}px`, + ...controlProps?.style, }, + ...controlProps, } - : undefined + : controlProps } renderItem={(item: ReactNode, realIndex) => (