リストを持っていますので、反応ドラッグ可能な要素を使って要素(divs)をそのリストからドラッグできます。 React-draggableは、元の要素をドラッグ可能にします(意味をなさない)が、元の要素のコピー(クローン)をドラッグし、元の要素をそのまま保持する必要がある。 したがって、要素を含むエンティティリストがあります。各要素には、元のシフトを複製することを望む親要素リストを呼び出すイベントがあり、元の要素をドラッグ可能な要素でラップしてドラッグ可能にします。それをドラッグ&ドロップすると、画面上の別の要素にアタッチして、マウスカーソルのある中心に最初の位置を置きたいと思います。 最後にやりたいことは、要素が「間違った」場所にドロップされた場合、元の位置に戻るようにアニメートする必要があるということです。もともとはJqueryで書かれていて、jquery-uiを使ってこのようなことをする方法はわかっていましたが、私はちょっとした反応をしていました。ドラッグするために反応要素をクローンする方法
var Scheduler = require('scheduler/components/Scheduler');
var ShiftTypeDiv = require('scheduler/components/ShiftType');
var Draggable = ReactDraggable;
var ShiftTypes = React.createClass({
getInitialState: function() {
return ({
shiftTypes: SchedulerStore.getShiftTypes(),
clonedItem: null
})
},
handleStart: function (event, ui) {
console.log('handleStart: ', event);
console.log('Position: ', ui.position);
},
cloneShiftBeforeDrag: function (item) {
console.log('cloning', item);
React.cloneElement(item);
ReactDOM.findDOMNode
this.setState({
clonedItem: item
});
},
handleDrag: function (event, ui) {
console.log('handledrag: ',ui);
console.log('dragging');
},
handleStop: function (event, ui) {
console.log('handleStop: ', event);
console.log('Position: ', ui.position);
},
render: function() {
var self = this;
shiftTypesJSX = this.state.shiftTypes.map(function(shiftType,index) {
return (
<ShiftTypeDiv shiftType={shiftType} key={index} cloneShiftBeforeDrag={self.cloneShiftBeforeDrag.bind(null, shiftType)} />
)
});
return (
<div >
<div className="box-header">
<ul>
<li className="title title-name">Shift Templates</li>
<li className="title edit-link"></li>
</ul>
</div>
<div className="box-content" data-onboarding-item="2">
<Draggable
handle=".ui-draggable"
zIndex={100}
onStart={this.handleStart}
onDrag={this.handleDrag}
onStop={this.handleStop}
>
<div className="draggable-custom-shift ui-draggable ui-draggable-handle"><strong>New Shift</strong></div>
</Draggable>
</div>
<div className="box-content" id="shift-templates">
<div className="row-fluid">
<div id="shift-types-list" className="span12">
<div className="input-group shift-type-filter-form">
<input type="text" className="span12" id="shift-type-filter" placeholder="Filter shift templates" />
<i className="icon-remove-sign" id="remove-shift-type-filter"></i>
</div>
<div id="shift_types" >
{shiftTypesJSX}
</div>
</div>
</div>
</div>
</div>
)
}
})
module.exports = ShiftTypes;
var Scheduler = require('scheduler/components/Scheduler').default;
var Draggable = ReactDraggable;
var ShiftTypeDiv = React.createClass({
handleStart: function (event, ui) {
console.log('cloning');
this.props.cloneShiftBeforeDrag(this);
},
handleDrag: function (event, ui) {
console.log('handledrag: ',ui);
console.log('dragging');
},
handleStop: function (event, ui) {
console.log('handleStop: ', event);
console.log('Position: ', ui);
this.setState({
})
},
render: function() {
shiftType = this.props.shiftType;
return (
<Draggable
bounds="body"
zIndex={100}
onStart={this.handleStart}
onDrag={this.handleDrag}
onStop={this.handleStop}
position={null}
>
<div className="draggable-shift-type ui-draggable ui-draggable-handle" data-shift-type-id={shiftType.id}>
{shiftType.name} <span dangerouslySetInnerHTML={{__html:shiftType.start_time + '-' + shiftType.end_time}}></span>
</div>
</Draggable>
)
}
})
module.exports = ShiftTypeDiv;