1
- import Sortable , { SortableOnEndEvent } from "../src" ;
1
+ import Sortable from "../src" ;
2
2
import { createStore } from 'solid-js/store'
3
+ import { JSX } from "solid-js" ;
3
4
4
5
const App = ( ) => {
5
6
6
- const itemStyles = { background : 'green' , padding : "10px" , minWidth : "100px" , margin : "5px" , "border-radius" : "4px" , color : "white" } ;
7
+ const itemStyles : JSX . CSSProperties = { "user-select" : "none" , background : 'green' , padding : "10px" , "min-width" : "100px" , margin : "5px" , "border-radius" : "4px" , color : "white" } ;
7
8
const containerStyles = { display : "inline-block" , background : 'gray' , padding : "10px" , "border-radius" : "4px" } ;
8
9
9
10
const [ items , setItems ] = createStore ( [
@@ -12,19 +13,19 @@ const App = () => {
12
13
{ id : 2 , name : 2 } ,
13
14
{ id : 3 , name : 3 } ,
14
15
] )
15
-
16
- const onEnd = ( event : SortableOnEndEvent < typeof items [ 0 ] > ) => {
17
- // event.movedItem -> the item that was moved
18
- // event.newList -> the new list of items
19
- // event.oldIndex -> the index of the item that was moved
20
- // event.newIndex -> the index of the item that was moved to
21
-
22
- setItems ( event . newList ) ;
23
- }
16
+ const [ items2 , setItems2 ] = createStore ( [
17
+ { id : 4 , name : 4 } ,
18
+ { id : 5 , name : 5 } ,
19
+ { id : 6 , name : 6 } ,
20
+ { id : 7 , name : 7 } ,
21
+ ] )
24
22
25
23
return (
26
24
< div style = { containerStyles } >
27
- < Sortable items = { items } onEnd = { onEnd } >
25
+ < Sortable idField = "id" style = { { background : "darkgray" } } items = { items } setItems = { setItems } >
26
+ { item => < div style = { itemStyles } > { item . name } { Math . random ( ) } </ div > }
27
+ </ Sortable >
28
+ < Sortable idField = "id" style = { { background : "darkgray" , "margin-top" : "102px" } } items = { items2 } setItems = { setItems2 } >
28
29
{ item => < div style = { itemStyles } > { item . name } { Math . random ( ) } </ div > }
29
30
</ Sortable >
30
31
</ div >
0 commit comments