@@ -3,24 +3,15 @@ import random from 'lodash/random';
3
3
import React from 'react' ;
4
4
import ReactDOM from 'react-dom' ;
5
5
import Sortable from '../../src' ;
6
- import SimpleList from './simple-list' ;
7
- import SharedGroup from './shared-group' ;
8
6
import store from './store' ;
9
7
10
8
class App extends React . Component {
11
9
state = {
12
- simpleList : store . get ( 'simpleList' ) ,
13
- sharedGroup : store . get ( 'sharedGroup' )
10
+ simpleList : [ 1 , 2 , 3 , 4 , 5 , 6 ] ,
11
+ groupLeft : [ 'Apple' , 'Banana' , 'Cherry' , 'Grape' ] ,
12
+ groupRight : [ 'Lemon' , 'Orange' , 'Pear' , 'Peach' ]
14
13
} ;
15
14
16
- componentDidMount ( ) {
17
- store . on ( 'change' , ( ) => {
18
- this . setState ( {
19
- simpleList : store . get ( 'simpleList' ) ,
20
- sharedGroup : store . get ( 'sharedGroup' )
21
- } ) ;
22
- } ) ;
23
- }
24
15
addMoreItems ( ) {
25
16
const items = [
26
17
'Apple' ,
@@ -37,23 +28,30 @@ class App extends React.Component {
37
28
'Strawberry'
38
29
] ;
39
30
const i = random ( 0 , items . length - 1 ) ;
40
- const sharedGroup = extend ( { } , this . state . sharedGroup ) ;
41
- sharedGroup . left = sharedGroup . left . concat ( items [ i ] ) ;
42
- this . setState ( { sharedGroup : sharedGroup } ) ;
31
+ this . setState ( { groupLeft : this . state . groupLeft . concat ( items [ i ] ) } ) ;
43
32
}
44
33
render ( ) {
34
+ const simpleList = this . state . simpleList . map ( ( val , key ) => (
35
+ < div key = { key } data-id = { val } > List Item { val } </ div >
36
+ ) ) ;
37
+ const groupLeft = this . state . groupLeft . map ( ( val , key ) => (
38
+ < div key = { key } data-id = { val } > { val } </ div >
39
+ ) ) ;
40
+ const groupRight = this . state . groupRight . map ( ( val , key ) => (
41
+ < div key = { key } data-id = { val } > { val } </ div >
42
+ ) ) ;
43
+
45
44
return (
46
45
< div >
47
46
< div className = "container-fluid" >
48
47
< div className = "title" > Simple List</ div >
49
48
< div className = "row" >
50
49
< div className = "col-sm-12" >
51
- < SimpleList
52
- items = { this . state . simpleList }
53
- onChange = { ( items , sortable ) => {
54
- store . set ( 'simpleList' , items ) ;
55
- } }
56
- />
50
+ < Sortable
51
+ className = "block-list"
52
+ >
53
+ { simpleList }
54
+ </ Sortable >
57
55
</ div >
58
56
</ div >
59
57
</ div >
@@ -70,20 +68,37 @@ class App extends React.Component {
70
68
</ div >
71
69
< div className = "row" >
72
70
< div className = "col-sm-6" >
73
- < SharedGroup
74
- items = { this . state . sharedGroup . left }
75
- onChange = { ( items , sortable ) => {
76
- store . replace ( 'sharedGroup.left' , items ) ;
71
+ < Sortable
72
+ ref = "group-left"
73
+ className = "block-list"
74
+ sort = { false }
75
+ group = { {
76
+ name : 'shared' ,
77
+ pull : 'clone' ,
78
+ put : false
77
79
} }
78
- />
80
+ onChange = { ( items ) => {
81
+ this . setState ( { groupLeft : items } ) ;
82
+ } }
83
+ >
84
+ { groupLeft }
85
+ </ Sortable >
79
86
</ div >
80
87
< div className = "col-sm-6" >
81
- < SharedGroup
82
- items = { this . state . sharedGroup . right }
83
- onChange = { ( items , sortable ) => {
84
- store . replace ( 'sharedGroup.right' , items ) ;
88
+ < Sortable
89
+ ref = "group-right"
90
+ className = "block-list"
91
+ group = { {
92
+ name : 'shared' ,
93
+ pull : true ,
94
+ put : true
95
+ } }
96
+ onChange = { ( items ) => {
97
+ this . setState ( { groupRight : items } ) ;
85
98
} }
86
- />
99
+ >
100
+ { groupRight }
101
+ </ Sortable >
87
102
</ div >
88
103
</ div >
89
104
</ div >
0 commit comments