| 20 | }; |
| 21 | |
| 22 | @DragSource(props => props.color, ColorSource, (connect, monitor) => ({ |
| 23 | connectDragSource: connect.dragSource(), |
| 24 | isDragging: monitor.isDragging(), |
| 25 | })) |
| 26 | class SourceBox extends Component { |
| 27 | static propTypes = { |
| 28 | connectDragSource: PropTypes.func.isRequired, |
| 29 | isDragging: PropTypes.bool.isRequired, |
| 30 | color: PropTypes.string.isRequired, |
| 31 | forbidDrag: PropTypes.bool.isRequired, |
| 32 | onToggleForbidDrag: PropTypes.func.isRequired, |
| 33 | children: PropTypes.node, |
| 34 | }; |
| 35 | |
| 36 | render() { |
| 37 | const { color, children, isDragging, connectDragSource, forbidDrag, onToggleForbidDrag } = this.props; |
| 38 | const opacity = isDragging ? 0.4 : 1; |
| 39 | |
| 40 | let backgroundColor; |
| 41 | switch (color) { |
| 42 | case Colors.YELLOW: |
| 43 | backgroundColor = 'lightgoldenrodyellow'; |
| 44 | break; |
| 45 | case Colors.BLUE: |
| 46 | backgroundColor = 'lightblue'; |
| 47 | break; |
| 48 | default: |
| 49 | break; |
| 50 | } |
| 51 | |
| 52 | return connectDragSource( |
| 53 | <div |
| 54 | style={{ |
| 55 | ...style, |
| 56 | backgroundColor, |
| 57 | opacity, |
| 58 | cursor: forbidDrag ? 'default' : 'move', |
| 59 | }} |
| 60 | > |
| 61 | <input |
| 62 | type="checkbox" |
| 63 | checked={forbidDrag} |
| 64 | onChange={onToggleForbidDrag} |
| 65 | /> |
| 66 | <small>Forbid drag</small> |
| 67 | {children} |
| 68 | </div>, |
| 69 | ); |
| 70 | } |
| 71 | } |
| 72 | |
| 73 | export default class StatefulSourceBox extends Component { |
| 74 | constructor(props) { |
nothing calls this directly
no test coverage detected