1.0.5 • Published 7 years ago

drag-list-react v1.0.5

Weekly downloads
-
License
MIT
Repository
-
Last release
7 years ago

Drag-list-react

npm Build Status npm

A HOC component of Drag&Drop,Touch enabled and Reordering list for React.

demo

Install

npm install drag-list-react --save

Usage

import React from 'react';
import DragList from 'drag-list-react';

// Notice: Every item in your data list must contains property 'id'.
// DragList component uses 'id' as the key of array.
const list=[
  {
    id:1,
    name:'Item1'
  },{
    id:2,
    name:'Item2'
  },{
    id:3,
    name:'Item3'
  },{
    id:4,
    name:'Item4'
  }
]

// list item
// Each properties in data list will be passed to the children
const listItem=({name})=>(
  <div className={styles.nameTag}>{name}</div>
)

// Placeholder when dragging items
// Props is necessary because placeholder will receive style props from component.
const Placeholder=(props)=>(
  <div className={styles.placeholder} {...props}></div>  
)

const App = () => {
  // Use placeholder
  const List = DragList(listItem,Placeholder);
  // Or not use placeholder
  // const List = DragList(listItem);
  return (
    <List  />
  )
};

API

Properties

nametypedefaultdescription
disabledBooleanfalseDisabled dragging and dropping
typeStringType of drag list.The list will be horizontal when it is set inline.
isLongPressBooleanfalseShould dragging be triggered by long pressing or not
delayNumber300(ms)The delay time of long pressing
gutterNumber0The spacing between two items
onDragBeginFunction(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.
onDragEndFunction(list)Param: list is the final list when dragging ends.
1.0.5

7 years ago

1.0.4

7 years ago

1.0.3

7 years ago

1.0.2

7 years ago

1.0.1

7 years ago

1.0.0

7 years ago