Debian Codegraph @

node/@patternfly/react-core/src/deprecated/components/DragDrop/DragDrop.tsx

raw
1 import { createContext } from 'react';
2 export interface DraggableItemPosition {
3 /** Parent droppableId */
4 droppableId: string;
5 /** Index of item in parent Droppable */
6 index: number;
7 }
8
9 export const DragDropContext = createContext({
10 onDrag: (_source: DraggableItemPosition) => true as boolean,
11 onDragMove: (_source: DraggableItemPosition, _dest?: DraggableItemPosition) => {},
12 onDrop: (_source: DraggableItemPosition, _dest?: DraggableItemPosition) => false as boolean
13 });
14
15 interface DragDropProps {
16 /** Potentially Droppable and Draggable children */
17 children?: React.ReactNode;
18 /** Callback for drag event. Return true to allow drag, false to disallow. */
19 onDrag?: (source: DraggableItemPosition) => boolean;
20 /** Callback on mouse move while dragging. */
21 onDragMove?: (source: DraggableItemPosition, dest?: DraggableItemPosition) => void;
22 /** Callback for drop event. Return true to allow drop, false to disallow. */
23 onDrop?: (source: DraggableItemPosition, dest?: DraggableItemPosition) => boolean;
24 }
25
26 export const DragDrop: React.FunctionComponent<DragDropProps> = ({
27 children,
28 onDrag = () => true,
29 onDragMove = () => {},
30 onDrop = () => false
31 }: DragDropProps) => (
32 <DragDropContext.Provider value={{ onDrag, onDragMove, onDrop }}>{children}</DragDropContext.Provider>
33 );
34 DragDrop.displayName = 'DragDrop';