@@ -5,48 +5,70 @@ var React = require('react'),
55 { DragDropMixin } = require ( 'react-dnd' ) ,
66 { PropTypes } = React ;
77
8- var OuterDustbin = React . createClass ( {
8+ var Dustbin = React . createClass ( {
99 mixins : [ DragDropMixin ] ,
1010
11+ propTypes : {
12+ greedy : PropTypes . bool
13+ } ,
14+
1115 getInitialState ( ) {
1216 return {
13- lastDroppedItem : null
17+ didDrop : null ,
18+ didDropOnCurrent : null
1419 } ;
1520 } ,
1621
1722 statics : {
1823 configureDragDrop ( register ) {
1924 var dropTarget = {
25+ enter ( ) {
26+ // TODO
27+ } ,
28+
29+ over ( ) {
30+ // TODO
31+ } ,
32+
33+ leave ( ) {
34+ // TODO
35+ } ,
36+
2037 acceptDrop ( component , item , e , isHandled ) {
21- if ( component . props . checkIsHandled && isHandled ) {
22- return false ;
38+ if ( ! component . props . greedy && isHandled ) {
39+ return ;
2340 }
2441
2542 component . setState ( {
26- lastDroppedItem : item
43+ didDrop : true ,
44+ didDropOnCurrent : ! isHandled
2745 } ) ;
2846 }
2947 } ;
3048
31- register ( ItemTypes . GLASS , {
49+ register ( ItemTypes . BOX , {
3250 dropTarget : dropTarget
3351 } ) ;
3452 }
3553 } ,
3654
3755 render ( ) {
38- var dropStates = [ ItemTypes . GLASS ] . map ( this . getDropState ) ,
56+ var { isOver, isOverCurrent, isDragging } = this . getDropState ( ItemTypes . BOX ) ,
57+ { greedy } = this . props ,
58+ { didDrop, didDropOnCurrent } = this . state ,
3959 backgroundColor = 'rgba(0, 0, 0, .5)' ,
40- prop = this . props . stopDeepHover ? 'isOverCurrent ' : 'isHovering ' ;
60+ text = greedy ? 'greedy ' : 'lazy ' ;
4161
42- if ( dropStates . some ( s => s [ prop ] ) ) {
62+ if ( isOverCurrent || isOver && greedy ) {
4363 backgroundColor = 'darkgreen' ;
44- } else if ( dropStates . some ( s => s . isDragging ) ) {
64+ text = greedy ? 'active (greedy)' : 'active (lazy)' ;
65+ } else if ( isDragging ) {
4566 backgroundColor = 'darkkhaki' ;
67+ text = 'dragging' ;
4668 }
4769
4870 return (
49- < div { ...this . dropTargetFor . apply ( this , [ ItemTypes . GLASS ] ) }
71+ < div { ...this . dropTargetFor ( ItemTypes . BOX ) }
5072 style = { {
5173 border : '2px solid green' ,
5274 minHeight : '12rem' ,
@@ -59,13 +81,10 @@ var OuterDustbin = React.createClass({
5981 float : 'left'
6082 } } >
6183
62- { dropStates . some ( s => s . isHovering ) ?
63- 'Release to drop' :
64- 'This dustbin accepts: ' + [ ItemTypes . GLASS ] . join ( ', ' )
65- }
84+ { text }
6685
67- { this . state . lastDroppedItem &&
68- < p > Last dropped: { JSON . stringify ( this . state . lastDroppedItem ) } </ p >
86+ { didDrop &&
87+ < span > · did drop { didDropOnCurrent && ' (on current)' } </ span >
6988 }
7089
7190 < div >
@@ -76,4 +95,4 @@ var OuterDustbin = React.createClass({
7695 }
7796} ) ;
7897
79- module . exports = OuterDustbin ;
98+ module . exports = Dustbin ;
0 commit comments