import React, { useState, useEffect, useRef } from 'react'; import { Skeleton } from 'antd'; import { CarouselWrapper } from './Carousel.styled'; import { RightOutlined, LeftOutlined, CloseOutlined, PictureOutlined, FireOutlined } from '@ant-design/icons'; import ReactResizeDetector from 'react-resize-detector'; export function Carousel({ ready, error, items, itemRenderer, itemRemove }) { const [slots, setSlots] = useState([]); const [carouselRef, setCarouselRef] = useState(false); const [itemIndex, setItemIndex] = useState(0); const [scrollLeft, setScrollLeft] = useState('hidden'); const [scrollRight, setScrollRight] = useState('hidden'); const FUDGE = 1; let carousel = useRef(); let itemWidth = useRef(new Map()); useEffect(() => { setScroll('smooth'); setArrows(); }, [itemIndex, items]); useEffect(() => { setScroll('auto'); }, [carouselRef]); const updateItemIndex = (val) => { setItemIndex((i) => { if (i + val < 0) { return 0; } return i + val; }) } const onLeft = () => { if (itemIndex > 0) { updateItemIndex(-1); } } const onRight = () => { if(itemIndex + 1 < items.length) { updateItemIndex(+1); } } const setScroll = (behavior) => { let pos = FUDGE; for (let i = 0; i < itemIndex; i++) { pos += itemWidth.current.get(i) + 32; } if (carousel.current) { carousel.current.scrollTo({ top: 0, left: pos, behavior }); } } const setArrows = () => { if (itemIndex == 0) { setScrollLeft('hidden'); } else { setScrollLeft('unset'); } if (itemIndex + 1 >= items.length) { setScrollRight('hidden'); } else { setScrollRight('unset'); } } const RemoveItem = ({ index }) => { if (itemRemove) { return