Created
January 30, 2018 12:09
-
-
Save liubko/e6467d259fcbf5c8549e2eebf7394ad2 to your computer and use it in GitHub Desktop.
reason dnd
This file contains hidden or 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
let component = ReasonReact.statelessComponent("Layout"); | |
let make = (~canDrop: bool, ~isOver: bool, ~connectDropTarget, _children) => { | |
...component, | |
render: _self => | |
connectDropTarget( | |
<div className="Layout"> | |
<p> | |
( | |
ReasonReact.stringToElement( | |
canDrop && isOver ? "Release to drop" : "Drag a box here" | |
) | |
) | |
</p> | |
</div> | |
) | |
}; | |
let default = | |
ReasonReact.wrapReasonForJs(~component, jsProps => | |
make( | |
~canDrop=Js.to_bool(jsProps##canDrop), | |
~isOver=Js.to_bool(jsProps##isOver), | |
~connectDropTarget=jsProps##connectDropTarget, | |
[||] | |
) | |
); |
This file contains hidden or 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
let dropTarget: ReasonReact.reactClass => ReasonReact.reactClass = [%bs.raw | |
{| | |
function(componentClass) { | |
const boxTarget = { | |
drop() { | |
return { name: 'Layout' } | |
}, | |
} | |
function collect(connect, monitor) { | |
return { | |
connectDropTarget: connect.dropTarget(), | |
isOver: monitor.isOver(), | |
canDrop: monitor.canDrop(), | |
}; | |
} | |
const DropTarget = require('react-dnd').DropTarget; | |
return DropTarget("LAYOUT", boxTarget, collect)(componentClass); | |
} | |
|} | |
]; | |
let wrapedReactClass = dropTarget(Layout.default); | |
let make = children => | |
ReasonReact.wrapJsForReason( | |
~reactClass=wrapedReactClass, | |
~props=Js.Obj.empty(), | |
children | |
); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment