1.1.9 • Published 3 years ago

easy-react-dnd v1.1.9

Weekly downloads
-
License
MIT
Repository
github
Last release
3 years ago

Installation

$ npm i easy-react-dnd

Demo

https://master.d34ix3fbmn7czh.amplifyapp.com/

Usage

The only required prop is the onItemSwitch prop. It is your responsability to update the state that renders the EasyItem components.

import React, { Component } from 'react'
import { EasyDraggable, EasyItem } from 'react-easy-dnd'

class App extends Component {
  constructor(props) {
    super(props)
    this.state = {
      itemArray: ['Test 1', 'Test 2', 'Test 3']
    }
  }

  _handleDragStart = (key) => {
    // Getting the key of the item being draged
  }
  _handleDragStop = (index) => {
    // Getting index of final position
  }

  /*
   * This function is required to keep persistance
   */
  _handleItemSwitch = (newArray) => {
    // Getting the new array of items
    // Get key with newArray[index].key
    let temp = []
    for (const item of newArray) {
      temp.push(item.key)
    }
    this.setState({ itemArray: temp })
  }

  _handleItemHover = (key, index) => {
    // key and index of hovered item
  }

  render() {
    return (
      <EasyDraggable
        cursor='grab'
        hSpacing='10px'
        vSpacing='10px'
        transition="ease"
        onDragStart={this._handleDragStart}
        onDragStop={this._handleDragStop}
        onItemSwitch={this._handleItemSwitch} //Required
        onItemHover={this._handleSwitch}
        itemsPerRow={2}
      >
        {this.state.itemArray.map((item) => (
          <EasyItem key={item}>
            <div className='box'>{item}</div>
          </EasyItem>
        ))}
      </EasyDraggable>
    )
  }
}
export default App

EasyDraggable Props

Appearance props

propTypeDefault valueDescription
itemsPerRownumber1The amount of items per row (columns per rows)
transitionstringnoneTransition animation . Ease or opacity
handleHTML componentnoneA handle that allow dragging from a specific point
hSpacingstring0pxHorizontal spacing between items (ex:12px)
vSpacingstring0pxVertical spacing between rows (ex:12px)
cursorstringautoThe cursor used on drag (cursor style property, ex : grab,pointer, ...)

Events props

propTypeparameter(s)Description
onDragStartfuntionThe key of the item being dragedWhen drag starts
onDragStopfuntionThe key of the final positionWhen drag stops
onItemSwitchfuntionThe new array of itemsWhen an item switch. This is required to keep persistance
onItemHoverfuntionkey (key of hovered item), index (index of hovered item)When an item is hovered

EasyItem Props

propTypeDefault valueRequiredDescription
keynumber/stringnonenoUnique id for the item

Credits

Adam Pinheiro

Authors

  • Adam Pinheiro

Ressources used

1.1.9

3 years ago

1.1.8

3 years ago

1.1.7

3 years ago

1.1.6

3 years ago

1.1.5

3 years ago

1.1.4

3 years ago

1.1.3

3 years ago

1.1.2

3 years ago

1.1.1

3 years ago

1.1.0

3 years ago

1.0.9

3 years ago

1.0.8

3 years ago

1.0.7

3 years ago

1.0.6

3 years ago

1.0.5

3 years ago

1.0.4

3 years ago

1.0.3

3 years ago

1.0.2

3 years ago

1.0.1

3 years ago

1.0.0

3 years ago