npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

react-dnd-lite

v1.0.36

Published

Add drag and drop feature in your react app with minimal configuration using **react-dnd-lite**.

Downloads

2,052

Readme

React DND Lite

Add drag and drop feature in your react app with minimal configuration using react-dnd-lite.

Installation

Using NPM

$ npm install react-dnd-lite

Using YARN

$ yarn add react-dnd-lite

Basic concepts

DNDContainer - It is a wrapping element that handles all the drag and drop state management and give access to onDrop event. It internally uses react createContext api. Wrap your parent component inside the DNDContainer like so

App.tsx

import { DNDContainer, IElementDrop, IElementDragging, IElementDraggingOver } from 'react-dnd-lite'
import { Test } from './components/Test'

function App() {
  const onDrop = (e: IElementDrop) => console.log(e)
  const onDragStart = (e: IElementDragging) => console.log(e)
  const onDragOver = (e: IElementDraggingOver) => console.log(e)
  
  return (
    <DNDContainer onDrop={onDrop} onDragStart={onDragStart} onDragOver={onDragOver}>
      <Test />
    </DNDContainer>
  )
}

export default App

|API|Type|Required|Example| |---|----|--------|-------| |onDrop|function|false| (e: IElementDrop) => console.log(e) | |onDragStart|function|false| (e: IElementDragging) => console.log(e) | |onDragOver|function|false| (e: IElementDraggingOver) => console.log(e) |

DNDItem - It handles all the magic. DNDItem converts the children to a draggable item.

Test.tsx

import { DNDItem } from "react-dnd-lite"

export const Test = () => {
  return (
    <div className="container">
      <DNDItem id="1">
        <div className="box box-1">
          <span>Box 1</span>
        </div>
      </DNDItem>
      <DNDItem id="2">
        <div className="box box-2">
          <span>Box 2</span>
        </div>
      </DNDItem>
    </div>
  )
}

*Note: DNDItem accepts only HTMLElement as direct children. It may not work properly for React component or React Fragment as direct children.

|API|Type|Required|Example| |---|----|--------|-------| |id|string|true| id="some-id-1"| |isDraggable|boolean|false|isDraggable={true}|

Advance features

DNDHandler - It allows user to add drag handler to DNDItem. Wrap your handler element with this component like so...

Test.tsx

import { DNDHandler, DNDItem } from "react-dnd-lite"
import DragIcon from '../assets/DragIcon.svg'

export const Test = () => {
  return (
    <div className="container">
      <DNDItem id="1">
        <div className="box box-1">
          Box 1

          <DNDHandler id="1">
            <img src={DragIcon} className="drag-icon"/>
          </DNDHandler>
        </div>
      </DNDItem>
      <DNDItem id="2">
        <div className="box box-2">
          Box 2
        </div>
      </DNDItem>
    </div>
  )
}

*Note: DNDHandler accepts only HTMLElement as direct children. It may not work properly for React component or React Fragment as direct children.

|API|Type|Required|Example|Note| |---|----|--------|-------|----| |id|string|true| id="some-id-1"|Please note that id must be same with the DNDItem's id|

DNDIndicator - It allows user to add drop indicator to DNDItem. Place DNDIndicator component inside the DNDItem like so...

import { DNDHandler, DNDIndicator, DNDItem } from "react-dnd-lite"
import DragIcon from '../assets/DragIcon.svg'

export const Test = () => {
  return (
    <div className="container">
      <DNDItem id="1">
        <div className="box box-1">
          Box 1

          <DNDHandler id="1">
            <img src={DragIcon} className="drag-icon"/>
          </DNDHandler>
        </div>
      </DNDItem>
      <DNDItem id="2">
        <div className="box box-2">
          Box 2

          <DNDIndicator position="left" id="2" />
          <DNDIndicator position="right" id="2" />
        </div>
      </DNDItem>
    </div>
  )
}

|API|Type|Required|Example|Note| |---|----|--------|-------|----| |id|string|true| id="some-id-1"|Please note that id must be same with the DNDItem's id| |position|string|true| position="left"|Available options are left, right, bottom, top and element, Default is element| |className|string|false| className="my-dnd-indicator"|| |style|Object|false| style={{width: '20px', background: 'red'}}|| |hoveredStyle|Object|false| style={{width: '30px', background: 'green'}}||