0.9.18 • Published 4 years ago

@darthbane/react-drag v0.9.18

Weekly downloads
15
License
MIT
Repository
-
Last release
4 years ago

React-Drag

A Library for Drag and Drop interactions in react.

Run npm i @darthbane/react-drag to install.

There are four things you can import from this library: 1) Draggable 2) Dragsurface 3) ReactDragManager 4) getDefaultManager.

Draggable:

This is a react component that makes a draggable component out of all it's children. Below is an example:

\ This text is draggable! \

If you wish to make it interactive, you will need to add an item prop. The item prop is an object that must contain a className key which is a string of classes seperated by a space, and may contain a data object which can contain any values. So for example:

\<Draggable item={{className: "SOME_CLASSNAME SOME_OTHER_CLASSNAME", data: {id: 3, value: 100}}}> \ \

DragSurface:

This is a react component that makes a surface component out of all it's children. The surface interacts with all items that share it's item classNames. Below is an example:

\<Draggable item={{className: "red blue", data: {id: 13, color: "purple"}}}> \ \

\<Draggable item={{className: "green blue", data: {id: 2, color: "greenish blue"}}}> \ \

\<Dragsurface item={{className: "blue orange", data: {value: 100}}}> \ \

\<Dragsurface item={{className: "green", data: {onEnter: SOME_FUNCTION}}}> \ \

In this example, the drag surface with a class name of blue will interact with both draggble components. While the drag surface with a class name of green will only interact with the second draggable component.All though these interactions take place, you will need to add event listeners to listen for them.

ReactDragManager:

A manager that keeps track of all draggable and drag surface components and their interactions. Generally, it is not necessary to create one, but rather use the built in defualt one.

getDefualtManager:

This function when invoked will return the defualt ReactDragManager. Once retrieved, you may add event listeners to it to take advantage of the interactions. So for example:

const manager = getDefaultManager(); manager.addEventListener("DRAG_ENTERED", "CLASS_NAME", (dragItem, dragSurface) => { CODE TO RUN WHEN INVOKED (when interaction takes place with said item and surface) });

0.9.17

4 years ago

0.9.18

4 years ago

0.9.12

4 years ago

0.9.13

4 years ago

0.9.14

4 years ago

0.9.15

4 years ago

0.9.11

4 years ago

0.9.16

4 years ago

0.9.10

4 years ago

0.9.9

4 years ago

0.9.8

4 years ago

0.9.7

4 years ago

0.9.6

4 years ago

0.9.5

4 years ago