-
-
Notifications
You must be signed in to change notification settings - Fork 36
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
1 parent
f7b2f64
commit 6a5607c
Showing
15 changed files
with
288 additions
and
413 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
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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,37 +1,26 @@ | ||
import React, { PureComponent } from 'react'; | ||
import PropTypes from 'prop-types'; | ||
import { DropTarget } from 'react-dnd'; | ||
import React from 'react'; | ||
import { useDrop } from 'react-dnd'; | ||
|
||
const spec = { | ||
drop: (props, monitor) => { | ||
const message = `Dropped: ${monitor.getItem().color}`; | ||
document.getElementById('console').innerHTML += `${message}<br />`; | ||
}, | ||
}; | ||
|
||
function collect(connect, monitor) { | ||
return { | ||
connectDropTarget: connect.dropTarget(), | ||
isOver: monitor.isOver(), | ||
canDrop: monitor.canDrop(), | ||
}; | ||
} | ||
const Basket = () => { | ||
const [collectedProps, drop] = useDrop({ | ||
accept: 'card', | ||
drop: (item) => { | ||
const message = `Dropped: ${item.color}`; | ||
document.getElementById('console').innerHTML += `${message}<br />`; | ||
}, | ||
collect: (monitor) => { | ||
return { | ||
isOver: monitor.isOver(), | ||
canDrop: monitor.canDrop(), | ||
}; | ||
}, | ||
}); | ||
|
||
class Basket extends PureComponent { | ||
static propTypes = { | ||
connectDropTarget: PropTypes.func.isRequired, | ||
isOver: PropTypes.bool.isRequired, | ||
canDrop: PropTypes.bool.isRequired, | ||
} | ||
const isOver = collectedProps.isOver; | ||
const canDrop = collectedProps.canDrop; | ||
const style = {backgroundColor: (isOver && canDrop) ? '#f3f3f3' : '#cccccc', border: '1px dashed black'}; | ||
|
||
render() { | ||
const isOver = this.props.isOver; | ||
const canDrop = this.props.canDrop; | ||
const connectDropTarget = this.props.connectDropTarget; | ||
const style = { backgroundColor: (isOver && canDrop) ? '#f3f3f3' : '#cccccc', border: '1px dashed black' }; | ||
|
||
return connectDropTarget(<div className="square" style={style} />); | ||
} | ||
} | ||
return <div className="square" style={style} ref={drop} />; | ||
}; | ||
|
||
export default DropTarget('square', spec, collect)(Basket); | ||
export default Basket; |
Oops, something went wrong.