Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

react-droplite

Package Overview
Dependencies
Maintainers
1
Versions
22
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

react-droplite

Fat free react drag and drop lists

  • 0.0.7-alfa
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
0
Maintainers
1
Weekly downloads
 
Created
Source

Droplite

Light react component to add drag and drop functionality to your lists.

Usage

Install the package with npm install droplite

There are four basic requirements

const MyComponent = (props) => {
  const [items, setItems] = useState(["A", "B", "C", "D"])

  // Requirement 1: add unique key
  const listItems = items.map(item =><li key={item}>{item}</li>)

  // Requirement 2: Implement on new order Handler
  const onNewOrder = (draggedItem, dropOntoItem) => {
    const newItemOrder = [...items]
    const draggedItemIndex = items.indexOf(draggedItem) 
    newItemOrder.splice(draggedItemIndex, 1)
    newItemOrder.splice(items.indexOf(dropOntoItem), 0, items[draggedItemIndex])
    setItems(newItemOrder)
  }

  // Requirement 3: Wrap the list with DragList HOC
  // Requirement 4: pass onNewOrder handler as prop
  return (
    <div>
      <DragList onNewOrder={onNewOrder}>
        {listItems}
      </DragList>
    </div>
  )
}

Samples

See Storybooks

Under the hood

Droplite depends on the HTML Drag and Drop API.

DragList component manages internal state of the drag and drop operation. The key function in DragList is the dragOverHandler that takes care of which element is being dragged over that can later be displaced. Once the onDragEndHandler is triggered, the current dragged element and the one below it (the draggedOver) are passed onto the onNewOrder handler.

Draggable is just a wrapper for your custom defined components that injects props and css classes that are required to start managing the drag and drop event listeners.

Support for mobile devices is not considered.

Todo

Smooth animations

Keywords

FAQs

Package last updated on 26 Aug 2019

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc