ldx-widgets
Version:
widgets
38 lines (32 loc) • 990 B
JavaScript
(function() {
var Draggable, React, div;
React = require('react');
div = React.DOM.div;
Draggable = React.createClass({
displayName: 'Draggable',
getDefaultProps: function() {
return {
centerOnCursor: true
};
},
render: function() {
var centerOnCursor, className, component, height, options, position, ref, width, x, y;
ref = this.props, position = ref.position, component = ref.component, options = ref.options, className = ref.className, centerOnCursor = ref.centerOnCursor, height = ref.height, width = ref.width;
x = position.x, y = position.y;
if (centerOnCursor) {
x = x - width / 2;
y = y - (height - height / 2);
}
return div({
className: "draggable " + (className || ''),
style: {
top: y,
left: x,
height: height,
width: width
}
}, component(options));
}
});
module.exports = Draggable;
}).call(this);