0.1.0 • Published 1 year ago

react-dndzone v0.1.0

Weekly downloads
-
License
MIT
Repository
github
Last release
1 year ago

Introduction

Javascript Library for drag and drop

Installation

npm i react-dndzone

Usage/Examples

import DNDZone from 'react-dndzone'


function App(){

  function onDragEnter(dragElement, dropElement){
    ...
  }
  function onDragLeave(dragElement, dropElement){
    ...
  }
  function onDrop(dragElement, dropElement){
    ...
  }

  return(
    <DNDZone  dragClass="drag" dropClass="drop" onDragEnter={onDragEnter} onDragLeave={onDragLeave} onDrop={onDrop}>
      <div style={{display:'grid', gridTemplateColumns:"1fr 1fr 1fr 1fr", columnGap:'4px'}}>
        <div style={{width:"100px", height:"100px", background:"gray"}} className="drag">Drag 1!</div>
        <div style={{width:"100px", height:"100px", background:"gray"}} className="drag">Drag 2!</div>
        <div style={{width:"100px", height:"100px", background:"gray"}} className="drag">Drag 3!</div>
        <div style={{width:"100px", height:"100px", background:"gray"}} className="drag">Drag 4!</div>
      </div>
      <div style={{marginTop:"24px", display:'grid', gridTemplateColumns:"1fr 1fr 1fr 1fr", columnGap:'4px'}}>
        <div style={{width:"100px", height:"100px", background:"blue"}} className="drop">drop 1!</div>
        <div style={{width:"100px", height:"100px", background:"blue"}} className="drop">drop 2!</div>
        <div style={{width:"100px", height:"100px", background:"blue"}} className="drop">drop 3!</div>
        <div style={{width:"100px", height:"100px", background:"blue"}} className="drop">drop 4!</div>
      </div>
    </DNDZone>

  )
}

Documentation

Documentation

Prop NameDescriptionDefault
dragClass*className of elements that need to be dragged!type=string-
dropClass*className of elements on which the drag element is dropped!type=string-
revertIf this value is set to false, the drag item will not revert to its initial position upon being dropped!type=booleantrue
dragZIndexThis specifies the initial z-index value of the drag item when it is being dragged!type=number1000
onDropThis function will execute when the drag item is dropped onto the drop item!((dragItem: HTMLElement, drapItem: HTMLElement) => void) \| null-
onDragEnterThis function will execute when the drag item enters over the drop item!((dragItem: HTMLElement, drapItem: HTMLElement) => void) \| null-
onDragLeaveThis function will execute when the drag item is no longer over the drop item!((dragItem: HTMLElement, drapItem: HTMLElement) => void) \| null-

License

MIT

0.1.0

1 year ago

0.0.2

1 year ago

0.0.1

1 year ago