Drag-list-react
A HOC component of Drag&Drop,Touch enabled and Reordering list for React.
Install
npm install drag-list-react --save
Usage
import React from 'react';
import DragList from 'drag-list-react';
const list=[
{
id:1,
name:'Item1'
},{
id:2,
name:'Item2'
},{
id:3,
name:'Item3'
},{
id:4,
name:'Item4'
}
]
const listItem=({name})=>(
<div className={styles.nameTag}>{name}</div>
)
const Placeholder=(props)=>(
<div className={styles.placeholder} {...props}></div>
)
const App = () => {
const List = DragList(listItem,Placeholder);
return (
<List />
)
};
API
Properties
name | type | default | description |
---|
type | String | | Type of drag list.The list will be horizontal when it is set inline . |
isLongPress | Boolean | false | Should dragging be triggered by long pressing or not |
delay | Number | 300(ms) | The delay time of long pressing |
gutter | Number | 0 | The spacing between two items |
onDragBegin | Function(item,index,element) | | Prams: item is the dragging element of your data array; index is the index of the dragging item in your data array; element is the real DOM node of your dragging item. |
onDragEnd | Function(list) | | Param: list is the final list when dragging ends. |