Setup test component for drag and drop hook.

This commit is contained in:
Jay
2025-07-23 17:57:08 -04:00
parent 2737c6bf9e
commit bf9818a9aa
3 changed files with 217 additions and 0 deletions
+52
View File
@@ -0,0 +1,52 @@
import { useState, useRef, useCallback, useEffect } from "react";
type Position = {
x: number;
y: number;
};
type DragAndDropConfig = {
longPressEnabled?: boolean;
longPressDelay?: number;
dragHandleSelector?: string;
};
type DragAndDropState = {
isDragging: boolean;
currentIndex: number | null;
targetIndex: number | null;
};
export function useDragAndDrop<T>(
items: T[],
onReorder: (newOrder: T[]) => void,
config: DragAndDropConfig = {},
) {
const {
longPressEnabled = false,
longPressDelay = 300,
dragHandleSelector,
} = config;
const itemRefs = useRef<(HTMLElement | null)[]>([]);
const containerRef = useRef<HTMLElement | null>(null);
const [dragState, setDragState] = useState<DragAndDropState>({
isDragging: false,
currentIndex: null,
targetIndex: null,
});
const getItemProps = (index: number) => {
return { style: {} };
};
return {
containerRef,
itemRefs,
isDragging: dragState.isDragging,
currentIndex: dragState.currentIndex,
targetIndex: dragState.targetIndex,
getItemProps,
};
}