import React, { Children, useCallback } from "react"; import { motion } from "framer-motion"; import { Grid } from "../grid"; import { Box } from "../box"; const ChildWrapper: React.FC<{ children: React.ReactNode; childIndex: number; onFocus: (index: number) => void; firstElementRef: React.RefObject; }> = ({ children, childIndex, firstElementRef, onFocus }) => { const onDragStart = useCallback((e: React.MouseEvent) => { e.preventDefault(); }, []); const onFocusHandler = useCallback(() => { onFocus(childIndex); }, [childIndex, onFocus]); return ( {children} ); }; interface Props extends Omit, "columns" | "onDragEnd"> { viewWindowHeight: number; viewWindowWidth: number; gridWidth: number; gridX: number; rows: number; children: Array; firstElementRef: React.RefObject; transition?: React.ComponentProps["transition"]; onDragEnd: React.ComponentProps["onDragEnd"]; onItemFocus: (index: number) => void; disableDrag: boolean; } // eslint-disable-next-line max-lines-per-function export const BaseCarousel: React.FC = ({ viewWindowHeight, viewWindowWidth, gridWidth, gridX, rows, children, firstElementRef, transition = { type: "spring", stiffness: 300, damping: 30 }, onItemFocus, onDragEnd, onMouseDown, onMouseUp, disableDrag, ...gridProps }) => { const onScroll: React.UIEventHandler = useCallback((e) => { e.currentTarget.scrollLeft = 0; }, []); return ( {Children.map(children, (child, i) => { return ( {child} ); })} ); };