| 18 | }; |
| 19 | |
| 20 | @DropTarget([Colors.YELLOW, Colors.BLUE], ColorTarget, (connect, monitor) => ({ |
| 21 | connectDropTarget: connect.dropTarget(), |
| 22 | isOver: monitor.isOver(), |
| 23 | canDrop: monitor.canDrop(), |
| 24 | draggingColor: monitor.getItemType(), |
| 25 | })) |
| 26 | class TargetBox extends Component { |
| 27 | static propTypes = { |
| 28 | isOver: PropTypes.bool.isRequired, |
| 29 | canDrop: PropTypes.bool.isRequired, |
| 30 | draggingColor: PropTypes.string, |
| 31 | lastDroppedColor: PropTypes.string, |
| 32 | connectDropTarget: PropTypes.func.isRequired, |
| 33 | onDrop: PropTypes.func.isRequired, |
| 34 | }; |
| 35 | |
| 36 | render() { |
| 37 | const { canDrop, isOver, draggingColor, lastDroppedColor, connectDropTarget } = this.props; |
| 38 | const opacity = isOver ? 1 : 0.7; |
| 39 | |
| 40 | let backgroundColor = '#fff'; |
| 41 | switch (draggingColor) { |
| 42 | case Colors.BLUE: |
| 43 | backgroundColor = 'lightblue'; |
| 44 | break; |
| 45 | case Colors.YELLOW: |
| 46 | backgroundColor = 'lightgoldenrodyellow'; |
| 47 | break; |
| 48 | default: |
| 49 | break; |
| 50 | } |
| 51 | |
| 52 | return connectDropTarget( |
| 53 | <div style={{ ...style, backgroundColor, opacity }}> |
| 54 | |
| 55 | <p>Drop here.</p> |
| 56 | |
| 57 | {!canDrop && lastDroppedColor && |
| 58 | <p>Last dropped: {lastDroppedColor}</p> |
| 59 | } |
| 60 | </div>, |
| 61 | ); |
| 62 | } |
| 63 | } |
| 64 | |
| 65 | export default class StatefulTargetBox extends Component { |
| 66 | constructor(props) { |
nothing calls this directly
no test coverage detected