@@ -3,24 +3,15 @@ import random from 'lodash/random';
33import React from 'react' ;
44import ReactDOM from 'react-dom' ;
55import Sortable from '../../src' ;
6- import SimpleList from './simple-list' ;
7- import SharedGroup from './shared-group' ;
86import store from './store' ;
97
108class App extends React . Component {
119 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' ]
1413 } ;
1514
16- componentDidMount ( ) {
17- store . on ( 'change' , ( ) => {
18- this . setState ( {
19- simpleList : store . get ( 'simpleList' ) ,
20- sharedGroup : store . get ( 'sharedGroup' )
21- } ) ;
22- } ) ;
23- }
2415 addMoreItems ( ) {
2516 const items = [
2617 'Apple' ,
@@ -37,23 +28,30 @@ class App extends React.Component {
3728 'Strawberry'
3829 ] ;
3930 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 ] ) } ) ;
4332 }
4433 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+
4544 return (
4645 < div >
4746 < div className = "container-fluid" >
4847 < div className = "title" > Simple List</ div >
4948 < div className = "row" >
5049 < 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 >
5755 </ div >
5856 </ div >
5957 </ div >
@@ -70,20 +68,37 @@ class App extends React.Component {
7068 </ div >
7169 < div className = "row" >
7270 < 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
7779 } }
78- />
80+ onChange = { ( items ) => {
81+ this . setState ( { groupLeft : items } ) ;
82+ } }
83+ >
84+ { groupLeft }
85+ </ Sortable >
7986 </ div >
8087 < 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 } ) ;
8598 } }
86- />
99+ >
100+ { groupRight }
101+ </ Sortable >
87102 </ div >
88103 </ div >
89104 </ div >
0 commit comments