Skip to content

Commit 3587046

Browse files
committed
Sortable options as props
1 parent eebdcde commit 3587046

File tree

1 file changed

+23
-3
lines changed

1 file changed

+23
-3
lines changed

src/index.jsx

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,24 +2,42 @@ import React from 'react';
22
import ReactDOM from 'react-dom';
33
import Sortable from 'sortablejs';
44

5-
const store ={
5+
const store = {
66
nextSibling: null,
77
activeComponent: null
88
};
99

10+
const extend = (target, ...sources) => {
11+
target = target || {};
12+
for (let index = 0; index < sources.length; index++) {
13+
let obj = sources[index];
14+
if (!obj) {
15+
continue;
16+
}
17+
for (let key in obj) {
18+
if (obj.hasOwnProperty(key)) {
19+
target[key] = obj[key];
20+
}
21+
}
22+
}
23+
return target;
24+
};
25+
1026
export default class extends React.Component {
1127
static propTypes = {
28+
options: React.PropTypes.object,
1229
onChange: React.PropTypes.func,
1330
tag: React.PropTypes.string
1431
};
1532
static defaultProps = {
33+
options: {},
1634
tag: 'div'
1735
};
1836

1937
sortable = null;
2038

2139
componentDidMount() {
22-
const { children, className, ...options } = this.props;
40+
const options = extend({}, this.props.options);
2341

2442
[
2543
'onStart',
@@ -45,7 +63,9 @@ export default class extends React.Component {
4563
evt.from.insertBefore(evt.item, store.nextSibling);
4664

4765
if (remote !== this) {
48-
if ((typeof remote.props.group === 'object') && (remote.props.group.pull === 'clone')) {
66+
const remoteOptions = remote.props.options || {};
67+
68+
if ((typeof remoteOptions.group === 'object') && (remoteOptions.group.pull === 'clone')) {
4969
// Remove the node with the same data-reactid
5070
evt.item.parentNode.removeChild(evt.item);
5171
}

0 commit comments

Comments
 (0)