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

cheap-react-dnd

v1.0.1

Published

very simple and easy-to-use drag-and-drop library supporting mouse event and touch event

Downloads

49

Readme

cheap-react-dnd

NPM

A very simple and user-friendly drag-and-drop library that supports both mouse and touch events.

Table of Contents

Install

# Yarn
yarn add cheap-react-dnd

# NPM
npm install cheap-react-dnd

Quick Start

import Provider, {
  useDrop,
  useDrag,
  useData,
  operationType,
} from "cheap-react-dnd";
import React, { useRef } from "react";

const style = { width: 100, height: 100 };

const DragComponent = () => {
  const dropRef = useRef();
  useDrop({
    acceptKeys = ["*"],
    initData: { dropNo: 0 },
    ref: dropRef,
    onDrop: ({ dragState, setData, data, type }) => {},
  });
  return (
    <div style={style} ref={dropRef}>
      {" "}
      Drop here{" "}
    </div>
  );
};
const key = "drag-1";
const DragComponent = () => {
  const dragRef = useRef();
  useDrag({
    key: "drag-1",
    ref: dragRef,
    initData: { dragNo: 9 },
    onDrag: ({ data, setData, type, dropData }) => {},
  });
  return (
    <div style={style} ref={dragRef}>
      A drag
    </div>
  );
};

const AudienceComponent = () => {
  const data = useData(key);
  return <div>🥺</div>;
};
const App = () => (
  <Provider>
    <DragComponent />
    <DragComponent />
    <AudienceComponent />
  </Provider>
);

Usage

NOTE: React hooks require react and react-dom version 16.8.0 or higher.

Provider

A top-level component that all components utilizing useDrop, useDrag, and useData should be nested under the Provider.

| Props | Type | Description | | :-------: | :----------------: | :---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------: | | uniqueKey | String | Use this prop when you are working with multiple Providers. | | scale | Function | Object | When the outer element of the Provider uses the transform's scale property, it can lead to inaccurate drag positioning. To address this issue, you need to inform the Provider of the scaling ratios on both the horizontal and vertical axes. The default values are {x: 1, y: 1}. |

useDrag

Use this within components that is a drag source.

Parameter object includes :key, ref, initData, onDrag

key string required ref DOM reference initData initial data onDrag callback when dragging

useDrop

Parameter object includes :acceptKeys = ["*"], initData, ref, onDrop

acceptKeys string array required, determining what keys of the drag source can be accepted. if the drop target accepts all the keys of drag source, you specify it as ["*"] ref DOM reference initData initial data onDrop callback when dragging

Use this within components that is a drop target.

useData

Use this in any component under the Provider to subscribe to the state of a specific drag source.

Parameter string: key the data of drag source inited by useDrag

operationType

enum of state including: ONSTART, ONENTER, ONHOVER, ONLEAVE, ONDROP, ONEND

License

MIT © Facebook Inc.