11import extend from 'lodash/extend' ;
22import random from 'lodash/random' ;
3+ import uniq from 'lodash/uniq' ;
34import React from 'react' ;
45import ReactDOM from 'react-dom' ;
56import Sortable from '../../src' ;
@@ -9,7 +10,10 @@ class App extends React.Component {
910 state = {
1011 simpleList : [ 1 , 2 , 3 , 4 , 5 , 6 ] ,
1112 groupLeft : [ 'Apple' , 'Banana' , 'Cherry' , 'Grape' ] ,
12- groupRight : [ 'Lemon' , 'Orange' , 'Pear' , 'Peach' ]
13+ groupRight : [ 'Lemon' , 'Orange' , 'Pear' , 'Peach' ] ,
14+ cloneUncontrolled : [ 'Apple' , 'Banana' , 'Cherry' , 'Guava' , 'Grape' , 'Kiwi' , 'Lemon' , 'Melon' , 'Orange' , 'Pear' , 'Peach' , 'Strawberry' ] ,
15+ cloneControlledSource : [ 'Apple' , 'Banana' , 'Cherry' , 'Guava' , 'Grape' , 'Kiwi' , 'Lemon' , 'Melon' , 'Orange' , 'Pear' , 'Peach' , 'Strawberry' ] ,
16+ cloneControlledTarget : [ ]
1317 } ;
1418
1519 addMoreItems ( ) {
@@ -40,6 +44,15 @@ class App extends React.Component {
4044 const groupRight = this . state . groupRight . map ( ( val , key ) => (
4145 < div key = { key } data-id = { val } > { val } </ div >
4246 ) ) ;
47+ const cloneUncontrolled = this . state . cloneUncontrolled . map ( ( val , key ) => (
48+ < li key = { key } data-id = { val } > { val } </ li >
49+ ) ) ;
50+ const cloneControlledSource = this . state . cloneControlledSource . map ( ( val , key ) => (
51+ < li key = { key } data-id = { val } > { val } </ li >
52+ ) ) ;
53+ const cloneControlledTarget = this . state . cloneControlledTarget . map ( ( val , key ) => (
54+ < li key = { key } data-id = { val } > { val } </ li >
55+ ) ) ;
4356
4457 return (
4558 < div >
@@ -72,11 +85,10 @@ class App extends React.Component {
7285 < Sortable
7386 ref = "group-left"
7487 className = "block-list"
75- sort = { false }
7688 group = { {
7789 name : 'shared' ,
78- pull : 'clone' ,
79- put : false
90+ pull : true ,
91+ put : true
8092 } }
8193 onChange = { ( items ) => {
8294 this . setState ( { groupLeft : items } ) ;
@@ -91,7 +103,7 @@ class App extends React.Component {
91103 className = "block-list"
92104 group = { {
93105 name : 'shared' ,
94- pull : false ,
106+ pull : true ,
95107 put : true
96108 } }
97109 onChange = { ( items ) => {
@@ -103,6 +115,82 @@ class App extends React.Component {
103115 </ div >
104116 </ div >
105117 </ div >
118+ < div className = "container-fluid" >
119+ < div className = "title" style = { { marginTop : 100 } } > Uncontrolled Component</ div >
120+ < h4 > Clone items from left to right with duplicate DOM elements.</ h4 >
121+ < div className = "row" >
122+ < div className = "col-sm-6" >
123+ < Sortable
124+ ref = "group-left"
125+ tag = "ul"
126+ className = "block-list"
127+ sort = { false }
128+ group = { {
129+ name : 'shared' ,
130+ pull : 'clone' ,
131+ put : false
132+ } }
133+ >
134+ { cloneUncontrolled }
135+ </ Sortable >
136+ </ div >
137+ < div className = "col-sm-6" >
138+ < Sortable
139+ ref = "group-right"
140+ tag = "ul"
141+ className = "block-list"
142+ group = { {
143+ name : 'shared' ,
144+ pull : false ,
145+ put : true
146+ } }
147+ >
148+ </ Sortable >
149+ </ div >
150+ </ div >
151+ </ div >
152+ < div className = "container-fluid" >
153+ < div className = "title" style = { { marginTop : 100 } } > Controlled Component</ div >
154+ < h4 > Clone items from left to right without duplication.</ h4 >
155+ < div className = "row" >
156+ < div className = "col-sm-6" >
157+ < Sortable
158+ ref = "group-left"
159+ tag = "ul"
160+ className = "block-list"
161+ sort = { false }
162+ group = { {
163+ name : 'shared' ,
164+ pull : 'clone' ,
165+ put : false
166+ } }
167+ onChange = { ( items ) => {
168+ this . setState ( { cloneControlledSource : items } ) ;
169+ } }
170+ >
171+ { cloneControlledSource }
172+ </ Sortable >
173+ </ div >
174+ < div className = "col-sm-6" >
175+ < Sortable
176+ ref = "group-right"
177+ tag = "ul"
178+ className = "block-list"
179+ group = { {
180+ name : 'shared' ,
181+ pull : false ,
182+ put : true
183+ } }
184+ onChange = { ( items ) => {
185+ items = uniq ( items ) ; // Remove duplicate items
186+ this . setState ( { cloneControlledTarget : items } ) ;
187+ } }
188+ >
189+ { cloneControlledTarget }
190+ </ Sortable >
191+ </ div >
192+ </ div >
193+ </ div >
106194 </ div >
107195 ) ;
108196 }
0 commit comments