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
6 changed files
with
218 additions
and
1 deletion.
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 |
---|---|---|
@@ -0,0 +1,38 @@ | ||
'use strict'; | ||
|
||
var React = require('react'), | ||
OuterDustbin = require('./OuterDustbin'), | ||
InnerDustbin = require('./InnerDustbin'), | ||
makeItem = require('../_dustbin-interesting/makeItem'), | ||
ItemTypes = require('./ItemTypes'), | ||
{ NativeDragItemTypes } = require('react-dnd'); | ||
|
||
var Container = React.createClass({ | ||
renderItem(name, dropType) { | ||
var Item = makeItem(dropType); | ||
return <Item name={name} />; | ||
}, | ||
|
||
render() { | ||
return ( | ||
<div> | ||
<div style={{minHeight: '14rem', overflow: 'auto'}}> | ||
<OuterDustbin> | ||
<InnerDustbin /> | ||
</OuterDustbin> | ||
|
||
<OuterDustbin checkIsHandled | ||
stopDeepHover> | ||
<InnerDustbin /> | ||
</OuterDustbin> | ||
</div> | ||
|
||
<div style={{ minHeight: '2rem' }}> | ||
{this.renderItem('Glass', ItemTypes.GLASS)} | ||
</div> | ||
</div> | ||
); | ||
} | ||
}); | ||
|
||
module.exports = Container; |
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,70 @@ | ||
'use strict'; | ||
|
||
var React = require('react'), | ||
ItemTypes = require('./ItemTypes'), | ||
{ DragDropMixin } = require('react-dnd'), | ||
{ PropTypes } = React; | ||
|
||
var InnerDustbin = React.createClass({ | ||
mixins: [DragDropMixin], | ||
|
||
getInitialState() { | ||
return { | ||
lastDroppedItem: null | ||
}; | ||
}, | ||
|
||
statics: { | ||
configureDragDrop(register) { | ||
var dropTarget = { | ||
acceptDrop(component, item) { | ||
component.setState({ | ||
lastDroppedItem: item | ||
}); | ||
} | ||
}; | ||
|
||
register(ItemTypes.GLASS, { | ||
dropTarget: dropTarget | ||
}); | ||
} | ||
}, | ||
|
||
render() { | ||
var dropStates = [ItemTypes.GLASS].map(this.getDropState), | ||
backgroundColor = 'rgba(0, 0, 0, 1)'; | ||
|
||
if (dropStates.some(s => s.isHovering)) { | ||
backgroundColor = 'darkgreen'; | ||
} else if (dropStates.some(s => s.isDragging)) { | ||
backgroundColor = 'darkkhaki'; | ||
} | ||
|
||
return ( | ||
<div {...this.dropTargetFor.apply(this, [ItemTypes.GLASS])} | ||
style={{ | ||
border: '2px solid green', | ||
height: '12rem', | ||
width: '12rem', | ||
color: 'white', | ||
backgroundColor: backgroundColor, | ||
padding: '2rem', | ||
margin: '0.5rem', | ||
textAlign: 'center', | ||
float: 'left' | ||
}}> | ||
|
||
{dropStates.some(s => s.isHovering) ? | ||
'Release to drop' : | ||
'This dustbin accepts: ' + [ItemTypes.GLASS].join(', ') | ||
} | ||
|
||
{this.state.lastDroppedItem && | ||
<p>Last dropped: {JSON.stringify(this.state.lastDroppedItem)}</p> | ||
} | ||
</div> | ||
); | ||
} | ||
}); | ||
|
||
module.exports = InnerDustbin; |
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,7 @@ | ||
'use strict'; | ||
|
||
module.exports = { | ||
FOOD: 'food', | ||
GLASS: 'glass', | ||
PAPER: 'paper' | ||
}; |
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,79 @@ | ||
'use strict'; | ||
|
||
var React = require('react'), | ||
ItemTypes = require('./ItemTypes'), | ||
{ DragDropMixin } = require('react-dnd'), | ||
{ PropTypes } = React; | ||
|
||
var OuterDustbin = React.createClass({ | ||
mixins: [DragDropMixin], | ||
|
||
getInitialState() { | ||
return { | ||
lastDroppedItem: null | ||
}; | ||
}, | ||
|
||
statics: { | ||
configureDragDrop(register) { | ||
var dropTarget = { | ||
acceptDrop(component, item, e, isHandled) { | ||
if (component.props.checkIsHandled && isHandled) { | ||
return false; | ||
} | ||
|
||
component.setState({ | ||
lastDroppedItem: item | ||
}); | ||
} | ||
}; | ||
|
||
register(ItemTypes.GLASS, { | ||
dropTarget: dropTarget | ||
}); | ||
} | ||
}, | ||
|
||
render() { | ||
var dropStates = [ItemTypes.GLASS].map(this.getDropState), | ||
backgroundColor = 'rgba(0, 0, 0, .5)', | ||
prop = this.props.stopDeepHover ? 'isOverCurrent' : 'isHovering'; | ||
|
||
if (dropStates.some(s => s[prop])) { | ||
backgroundColor = 'darkgreen'; | ||
} else if (dropStates.some(s => s.isDragging)) { | ||
backgroundColor = 'darkkhaki'; | ||
} | ||
|
||
return ( | ||
<div {...this.dropTargetFor.apply(this, [ItemTypes.GLASS])} | ||
style={{ | ||
border: '2px solid green', | ||
minHeight: '12rem', | ||
minWidth: '12rem', | ||
color: 'white', | ||
backgroundColor: backgroundColor, | ||
padding: '2rem', | ||
margin: '0.5rem', | ||
textAlign: 'center', | ||
float: 'left' | ||
}}> | ||
|
||
{dropStates.some(s => s.isHovering) ? | ||
'Release to drop' : | ||
'This dustbin accepts: ' + [ItemTypes.GLASS].join(', ') | ||
} | ||
|
||
{this.state.lastDroppedItem && | ||
<p>Last dropped: {JSON.stringify(this.state.lastDroppedItem)}</p> | ||
} | ||
|
||
<div> | ||
{this.props.children} | ||
</div> | ||
</div> | ||
); | ||
} | ||
}); | ||
|
||
module.exports = OuterDustbin; |
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,20 @@ | ||
'use strict'; | ||
|
||
var React = require('react'), | ||
Container = require('./Container'); | ||
|
||
var DustbinNested = React.createClass({ | ||
render() { | ||
return ( | ||
<div> | ||
<Container /> | ||
<hr /> | ||
<p> | ||
Showcase how dropzones can react on hover | ||
</p> | ||
</div> | ||
); | ||
} | ||
}); | ||
|
||
module.exports = DustbinNested; |
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