import { Box, Button, ChevronRight, HStack, IconButton, VStack, } from '@metafam/ds'; import type { PropsWithChildren } from 'react'; import React, { useEffect } from 'react'; import { useBoundingRect } from '#lib/hooks/useBoundingRect'; import { useCarouselContext } from './CarouselContext'; export const Slider: React.FC = ({ children }) => { const { setTrackIsActive, setSliderWidth, setActiveItem, activeItem, constraint, itemWidth, positions, gap, hidePositions, itemsToShow, defaultCarousel, } = useCarouselContext(); const [ref, { width }] = useBoundingRect(); const itemsCount = positions.length; useEffect( () => setSliderWidth(Math.round(width ?? 0)), [width, setSliderWidth], ); const handleFocus = () => setTrackIsActive(true); return ( {children} {!defaultCarousel && positions.length > constraint && ( } aria-label="Previous" fontSize={{ base: '7xl', xl: '9xl' }} onClick={() => { setTrackIsActive(true); setActiveItem(activeItem - 1); }} onFocus={handleFocus} color="gray.200" variant="link" minW={0} maxW={{ base: 5, lg: 'inherit' }} isDisabled={activeItem === 0} opacity={activeItem === 0 ? '0!important' : 1} cursor={activeItem === 0 ? 'default!important' : 'pointer'} pointerEvents="all" transform="scaleX(-1)" transition="opacity 0.2s ease-in-out" /> } aria-label="Next" fontSize={{ base: '7xl', xl: '9xl' }} onClick={() => { setTrackIsActive(true); setActiveItem(activeItem + 1); }} onFocus={handleFocus} color="gray.200" variant="link" minW={0} maxW={{ base: 5, lg: 'inherit' }} isDisabled={activeItem + itemsToShow >= itemsCount} cursor={ activeItem + itemsToShow >= itemsCount ? 'default!important' : 'pointer' } opacity={activeItem + itemsToShow >= itemsCount ? '0!important' : 1} pointerEvents="all" transition="opacity 0.2s ease-in-out" /> )} {!hidePositions && defaultCarousel && positions.length > constraint && ( {positions.map((_, index) => { if (!defaultCarousel && index <= itemsCount / 3) { return ( ); } return ( ); })} )} {/* {hidePositions && !defaultCarousel && isMobile && positions.length > constraint && ( {positions.map((_, index) => { if (!defaultCarousel && index <= itemsCount / 3) { return ( ); } return ( ); })} )} */} ); };