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
8 changed files
with
112 additions
and
12 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
'use strict'; | ||
|
||
import React, { Component, PropTypes } from 'react'; | ||
import ItemTypes from './ItemTypes'; | ||
import { configureDragDrop } from 'react-dnd'; | ||
|
||
const style = { | ||
border: '1px dashed gray', | ||
backgroundColor: 'white', | ||
padding: '0.5rem', | ||
margin: '0.5rem', | ||
width: '15rem' | ||
}; | ||
|
||
const handleStyle = { | ||
backgroundColor: 'green', | ||
width: '1rem', | ||
height: '1rem', | ||
display: 'inline-block', | ||
marginRight: '0.5rem' | ||
}; | ||
|
||
const propTypes = { | ||
isDragging: PropTypes.bool.isRequired, | ||
connectDragSource: PropTypes.func.isRequired | ||
}; | ||
|
||
class Box extends Component { | ||
render() { | ||
const { isDragging, connectDragSource } = this.props; | ||
const opacity = isDragging ? 0.4 : 1; | ||
|
||
return ( | ||
<div style={{ ...style, opacity }}> | ||
<div style={handleStyle} | ||
ref={connectDragSource} /> | ||
|
||
Drag me by the handle | ||
</div> | ||
); | ||
} | ||
} | ||
Box.propTypes = propTypes; | ||
|
||
const boxSource = { | ||
beginDrag() { | ||
return {}; | ||
} | ||
}; | ||
|
||
export default configureDragDrop(Box, { | ||
getHandlers(props, sourceFor) { | ||
return sourceFor(ItemTypes.BOX, boxSource); | ||
}, | ||
|
||
getProps(connect, monitor, source) { | ||
return { | ||
connectDragSource: connect(source), | ||
isDragging: monitor.isDragging(source) | ||
}; | ||
} | ||
}); |
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,22 @@ | ||
'use strict'; | ||
|
||
import React, { PropTypes, Component } from 'react'; | ||
import { configureDragDropContext, DragDropContext, HTML5Backend } from 'react-dnd'; | ||
import Box from './Box'; | ||
import shuffle from 'lodash/collection/shuffle'; | ||
|
||
class Container extends Component { | ||
render() { | ||
return ( | ||
<div> | ||
<div style={{ marginTop: '2rem' }}> | ||
<Box /> | ||
</div> | ||
</div> | ||
); | ||
} | ||
} | ||
|
||
export default configureDragDropContext(Container, { | ||
backend: HTML5Backend | ||
}); |
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,5 @@ | ||
'use strict'; | ||
|
||
export default { | ||
BOX: 'box' | ||
}; |
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,15 @@ | ||
'use strict'; | ||
|
||
import React from 'react'; | ||
import Container from './Container'; | ||
|
||
export default class CustomizeHandles { | ||
render() { | ||
return ( | ||
<div> | ||
<Container /> | ||
<hr /> | ||
</div> | ||
); | ||
} | ||
} |
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