import { useSortable } from "@dnd-kit/react/sortable"; import React, { useRef } from "react"; import { HStack } from "../../../primitives/stack"; import { cl } from "../../../utils/helpers"; import { useMergeRefs } from "../../../utils/hooks"; import { DataDragAndDropDragHandler } from "../drag-handler/DataDragAndDropDragHandler"; import { DataDragAndDropContext } from "../root/DataDragAndDrop.context"; interface DataDragAndDropItemProps extends React.HTMLAttributes { children: React.ReactNode; /** * Unique id */ id: string; /** * Index of the item being dragged */ index: number; } /** * TODO * * @see 🏷️ {@link DataDragAndDropItemProps} * @example * ```tsx * * TODO * * ``` */ const DataDragAndDropItem = React.forwardRef< HTMLDivElement, DataDragAndDropItemProps >(({ children, id, index, className, ...rest }, forwardedRef) => { const handleRef = useRef(null); const { ref, isDragging, isDropTarget } = useSortable({ id, index, handle: handleRef, }); const mergedRef = useMergeRefs(ref, forwardedRef); const context = React.useContext(DataDragAndDropContext); const mouseDragging = isDragging && context?.inputMethod === "mouse"; const mouseDropTarget = isDropTarget && context?.inputMethod === "mouse"; const keyboardDragging = isDragging && context?.inputMethod === "keyboard"; return ( {/* TODO Should this be a
  • ? */}
    {children}
    ); }); export default DataDragAndDropItem; export { DataDragAndDropItem }; export type { DataDragAndDropItemProps };