1
1
import extend from 'lodash/extend' ;
2
2
import random from 'lodash/random' ;
3
+ import uniq from 'lodash/uniq' ;
3
4
import React from 'react' ;
4
5
import ReactDOM from 'react-dom' ;
5
6
import Sortable from '../../src' ;
@@ -9,7 +10,10 @@ class App extends React.Component {
9
10
state = {
10
11
simpleList : [ 1 , 2 , 3 , 4 , 5 , 6 ] ,
11
12
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 : [ ]
13
17
} ;
14
18
15
19
addMoreItems ( ) {
@@ -40,6 +44,15 @@ class App extends React.Component {
40
44
const groupRight = this . state . groupRight . map ( ( val , key ) => (
41
45
< div key = { key } data-id = { val } > { val } </ div >
42
46
) ) ;
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
+ ) ) ;
43
56
44
57
return (
45
58
< div >
@@ -72,11 +85,10 @@ class App extends React.Component {
72
85
< Sortable
73
86
ref = "group-left"
74
87
className = "block-list"
75
- sort = { false }
76
88
group = { {
77
89
name : 'shared' ,
78
- pull : 'clone' ,
79
- put : false
90
+ pull : true ,
91
+ put : true
80
92
} }
81
93
onChange = { ( items ) => {
82
94
this . setState ( { groupLeft : items } ) ;
@@ -91,7 +103,7 @@ class App extends React.Component {
91
103
className = "block-list"
92
104
group = { {
93
105
name : 'shared' ,
94
- pull : false ,
106
+ pull : true ,
95
107
put : true
96
108
} }
97
109
onChange = { ( items ) => {
@@ -103,6 +115,82 @@ class App extends React.Component {
103
115
</ div >
104
116
</ div >
105
117
</ 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 >
106
194
</ div >
107
195
) ;
108
196
}
0 commit comments