import React from 'react' import { useMemo } from 'react' import { useCarouselSetup } from '../hooks' import { BaseAnimatedCarouselProps } from '../types' import { CarouselIndicators, CarouselItem } from './Common' import { AnimatedDivContainer, CarouselContainer } from './Common/styleds' export default function AnimatedCarousel({ data, axis, colors, dimensions, touchAction, animationProps, indicatorOptions = { showIndicators: true }, children }: BaseAnimatedCarouselProps) { const { parentSizes, imageTransformations: defaultImageTransforms, setCarouselContainerRef } = useCarouselSetup(dimensions) const { bind, springs, state: { currentIndex, itemSize }, refCallbacks: { setItemSizeRef, setScrollingZoneRef } } = animationProps const calculatedSizes = useMemo( () => dimensions?.fillContainer ? { height: '100%', width: '100%' } : axis === 'x' ? { width: Math.max(itemSize, parentSizes?.width || 0) } : { height: Math.max(itemSize, parentSizes?.height || 0) }, [axis, dimensions?.fillContainer, itemSize, parentSizes?.height, parentSizes?.width] ) return ( { setCarouselContainerRef(node) setItemSizeRef(node) }} $fixedHeight={dimensions?.fixedSizes?.height || parentSizes?.height || parentSizes?.width} $touchAction={touchAction} > {indicatorOptions.showIndicators || (indicatorOptions?.position && ( ))} {/* CAROUSEL CONTENT */} {springs.map((interpolatedProps, index, { length }) => { if (!parentSizes?.width || !parentSizes?.height) return null const animatedStyleProps = { ...interpolatedProps, ...calculatedSizes } return ( {children({ index, defaultImageTransforms, isLast: index === length - 1 })} ) })} ) }