forked from clauderic/react-sortable-hoc
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
52 lines (47 loc) · 1.34 KB
/
index.js
File metadata and controls
52 lines (47 loc) · 1.34 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
import 'babel-polyfill';
import React, {Component} from 'react';
import {render} from 'react-dom';
import {SortableContainer, SortableElement, arrayMove} from './src/index';
import range from 'lodash/range';
import random from 'lodash/random';
const SortableItem = SortableElement(({height, value}) => (
<div style={{
position: 'relative',
width: '100%',
display: 'block',
padding: 20,
borderBottom: '1px solid #DEDEDE',
boxSizing: 'border-box',
WebkitUserSelect: 'none',
height: height
}}>
Item {value}
</div>
));
const SortableList = SortableContainer(({items}) => (
<div>
{items.map(({height, value}, index) => <SortableItem key={`item-${index}`} index={index} value={value} height={height}/>)}
</div>
));
class Example extends Component {
state = {
items: range(100).map((value) => {
return {
value,
height: random(49, 120)
};
})
};
onSortEnd = ({oldIndex, newIndex}) => {
let {items} = this.state;
arrayMove(items, oldIndex, newIndex);
this.setState({items});
};
render() {
const {items} = this.state;
return <SortableList items={items} onSortEnd={this.onSortEnd} />;
}
}
render(<Example />,
document.getElementById('root')
)