-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathDropArea.js
45 lines (42 loc) · 1.33 KB
/
DropArea.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
import React, { useEffect } from 'react';
import { useDrop } from 'react-dnd';
const DropArea = ({ onDropAreaReady, onDropComponent, selectedPage, children }) => {
const [{ isOver }, dropRef] = useDrop(
() => ({
accept: 'COMPONENT',
drop: (item, monitor) => {
console.log('Dropped Item:', item, 'on page:', selectedPage);
const offset = monitor.getClientOffset();
if (item && item.componentName) {
onDropComponent(item.componentName, offset);
} else {
console.error('Dropped item missing componentName:', item);
}
},
collect: (monitor) => ({
isOver: !!monitor.isOver(),
}),
}),
[selectedPage, onDropComponent] // Add dependencies here
);
useEffect(() => {
if (onDropAreaReady) {
onDropAreaReady();
}
}, [onDropAreaReady]);
return (
<div
ref={dropRef}
style={{
position: 'relative',
width: '100%',
height: '100%',
border: '1px solid #ccc',
background: isOver ? '#e6f7ff' : '#fff',
}}
>
{children}
</div>
);
};
export default DropArea;