MCPcopy Index your code
hub / github.com/adobe/react-spectrum / useDrop

Function useDrop

packages/react-aria/src/dnd/useDrop.ts:104–428  ·  view source on GitHub ↗
(options: DropOptions)

Source from the content-addressed store, hash-verified

102 * based drag and drop, in addition to full parity for keyboard and screen reader users.
103 */
104export function useDrop(options: DropOptions): DropResult {
105 let {hasDropButton, isDisabled} = options;
106 let [isDropTarget, setDropTarget] = useState(false);
107 let state = useRef<{
108 x: number;
109 y: number;
110 dragOverElements: Set<Element>;
111 dropEffect: DataTransfer['dropEffect'];
112 allowedOperations: DROP_OPERATION;
113 dropActivateTimer: ReturnType<typeof setTimeout> | undefined;
114 }>({
115 x: 0,
116 y: 0,
117 dragOverElements: new Set<Element>(),
118 dropEffect: 'none',
119 allowedOperations: DROP_OPERATION.all,
120 dropActivateTimer: undefined
121 }).current;
122
123 let fireDropEnter = (e: DragEvent) => {
124 setDropTarget(true);
125
126 if (typeof options.onDropEnter === 'function') {
127 let rect = (e.currentTarget as HTMLElement).getBoundingClientRect();
128 options.onDropEnter({
129 type: 'dropenter',
130 x: e.clientX - rect.x,
131 y: e.clientY - rect.y
132 });
133 }
134 };
135
136 let fireDropExit = (e: DragEvent) => {
137 setDropTarget(false);
138
139 if (typeof options.onDropExit === 'function') {
140 let rect = (e.currentTarget as HTMLElement).getBoundingClientRect();
141 options.onDropExit({
142 type: 'dropexit',
143 x: e.clientX - rect.x,
144 y: e.clientY - rect.y
145 });
146 }
147 };
148
149 let onDragOver = (e: DragEvent) => {
150 e.preventDefault();
151 e.stopPropagation();
152
153 let allowedOperations = getAllowedOperations(e);
154 if (
155 e.clientX === state.x &&
156 e.clientY === state.y &&
157 allowedOperations === state.allowedOperations
158 ) {
159 e.dataTransfer.dropEffect = state.dropEffect;
160 return;
161 }

Callers 6

useDroppableCollectionFunction · 0.90
DroppableFunction · 0.90
DialogButtonFunction · 0.90
DropZone.tsxFile · 0.90
DropTargetFunction · 0.90
PromptFieldFunction · 0.90

Calls 3

useEffectEventFunction · 0.90
useVirtualDropFunction · 0.90
getDropOperationMethod · 0.80

Tested by

no test coverage detected