-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
113 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,27 @@ | ||
import React from 'react'; | ||
import { useDrag } from 'react-dnd'; | ||
|
||
const MyDraggableComponent = ({ isDragging, text }) => { | ||
const [{ opacity }, dragRef] = useDrag( | ||
() => ({ | ||
type: 'card', | ||
collect: (monitor) => ({ | ||
opacity: monitor.isDragging() ? 0.5 : 1 | ||
}) | ||
const DraggableItem = ({ name }) => { | ||
const [{ isDragging }, drag] = useDrag({ | ||
item: { name }, | ||
type: 'draggable', | ||
collect: (monitor) => ({ | ||
isDragging: !!monitor.isDragging(), | ||
}), | ||
[] | ||
) | ||
}); | ||
return ( | ||
<div ref={dragRef} style={{ opacity }}> | ||
<label>Character Name<input type="text" name="name" id="characterName" /></label> | ||
<div | ||
className='item' | ||
ref={drag} | ||
style={{ opacity: isDragging ? 0.4 : 1 }}> | ||
<label> | ||
Character Name | ||
<input | ||
type="text" | ||
name="name" | ||
id="characterName"/></label> | ||
</div> | ||
) | ||
}; | ||
|
||
export default MyDraggableComponent; | ||
export default DraggableItem; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import React from 'react'; | ||
import { useDrop } from "react-dnd"; | ||
|
||
const DropDiv = ({type, items}) => { | ||
const [{ isOver }, drop] = useDrop(() => ({ | ||
accept: type, | ||
collect: (monitor) => ({ | ||
isOver: !!monitor.isOver(), | ||
}), | ||
})); | ||
console.log(items); | ||
if (items.length === 0) { | ||
<div | ||
ref={drop} | ||
className={`drop-div ${isOver ? "drop-over" : ""}`} | ||
> | ||
</div> | ||
} | ||
return ( | ||
<div | ||
ref={drop} | ||
className={`drop-div ${isOver ? "drop-over" : ""}`} | ||
> | ||
{items.map((item) => { | ||
return <div className="item" key={item.id}>{item.content}</div> | ||
})} | ||
</div> | ||
); | ||
}; | ||
|
||
export default DropDiv; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters