drag to sort. support both pc and mobile
npm install @joyfulljs/dragsort
import DragItem, { DragHandle } from '@joyfulljs/dragsort';
import '@joyfulljs/dragsort/src/index.css';
// ...
handeSortChange = (list) => {
this.setState({ list });
};
render() {
const { list } = this.state;
return (
<div>
{list.map((item, index) => {
return (
<DragItem key={index} items={list} onChange={this.handeSortChange}>
{item.label}
{/* use default drag handle */ }
<DragHandle />
{/* customize drag handle
<DragHandle>Drag Me</DragHandle>
*/}
</DragItem>
);
})}
</div>
);
}
// ...
- It will use
DragItem
as the drag handle whenDragHandle
is omitted
MIT@elvinzhu