Giter Site home page Giter Site logo

beizhedenglong / reactablejs Goto Github PK

View Code? Open in Web Editor NEW
63.0 5.0 9.0 1.33 MB

A react high-order component for interact.js(drag and drop, resizing and multi-touch gestures).

Home Page: https://beizhedenglong.github.io/reactablejs/

License: MIT License

JavaScript 13.45% TypeScript 86.55%
react interactjs drag resize touchscreen drag-and-drop

reactablejs's Introduction

Reactablejs = Reactjs + Interactjs

A react high-order component for interactjs.

Current supported features:

  • drag
  • resize
  • drop
  • multi-touch
  • restrict
  • snap
  • modifiers

Current supported props:

  • options: draggable resizable gesturable dropzone.
  • event handlers: onDragStart onDragMove onDragInertiaStart onDragEnd onResizeStart onResizeMove onResizeInertiaStart onResizeEnd onGestureStart onGestureMove onGestureEnd onDropActivate onDropdEactivate onDragEnter onDragLeave onDropMove onDrop onDown onMove onUp onCancel onTap onDoubleTap onHold.

api details, visit interactjs' docs

Installation

reactablejs use interactjs as peerDependencies, you should also install interactjs.

npm install reactablejs interactjs --save

Usage

import React from 'react'
import reactable from 'reactablejs'

const MyComponent = (props) => {
  return <div ref={props.getRef}>
    hello, world!
  </div>
}

// MyComponent will receive getRef in props, put getRef to the element you want interact, then you can use all options and event handlers on Reactable

const Reactable = reactable(MyComponent) 

Example

reactablejs's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

reactablejs's Issues

Make only background div draggable

I have a modal that pops up which has textboxes inside it. The problem is, when attempting to highlight text in that popup modal, it drags the window instead of highlighting. Can I make it so it ignores when dragging on objects inside the div, and only move when the div itself is dragged? Right now it seems to apply to an entire component only.

<BanModalReactable
                   loadBans={loadBans}
                   draggable={{
                       cursorChecker: () => "default",
                       modifiers: [
                           interact.modifiers.restrictRect({
                               restriction: 'parent',
                               endOnly: true
                           })
                       ]
                   }}
                   onDragMove={(event) => {
                       const { dx, dy } = event;
                       setBanModalCoord((prev) => ({
                           x: prev.x + dx,
                           y: prev.y + dy,
                       }));
                   }}
                   x={banModalCoord.x}
                   y={banModalCoord.y}
               />

How to change cursor on draggable component

When I have a draggable component, it puts a 4-way arrow cursor over that div, but I don't want that to happen. How can I disable this? I've checked the docs for reactablejs and interactjs, but cannot figure out how to do it. Could I get some help?

Newbie: Can't get reactable to work

I'm new to React and I can't manage to get reactablejs to work, here is my attempt at implementing the example code:
https://github.com/eliasericsson/reactable-example

This is the error I'm getting:
./node_modules/reactablejs/dist/index.mjs
Can't import the named export 'Component' from non EcmaScript module (only default export is available)

I apologize if I've missed something fundamental.

Stale react state

Hi,
I appreciate the work you have done with this project and I would like to ask if I could help you with the library.
One of the issues which I found is that the event handlers use a stale React state. I know that there is a workaround by using useRef(). However, this gets complicated when using Redux and leads to duplicate data.
I solved this for the events by refactoring the code to React hooks. Meanwhile I also updated the npm dependancies.
You can find my changes here: npm-updates-and-using-react-hooks
I could create a pull request.

Using interactjs modifiers with reactablejs

Hi,
I'm using reactablejs and really appreciate the easy handling! I've already a working app in place where I can move and rotate some elements on my screen. These elements live in a surrounding DIV. My next step would be to restrict the drag-area to this DIV. In the interact.js documentation I can see that the restrict modifier would do the job. But: I cannot see reactablejs exposing the modifiers feature yet.
Am I right - is reactablejs not capable of using modifiers at the moment? Do you have this on your roadmap? Would you appreciate to get a PR for this feature?

fix import location for DraggableOptions, DropzoneOptions, ResizableOptions

Hi! ๐Ÿ‘‹

Firstly, thanks for your work on this project! ๐Ÿ™‚

Today I used patch-package to patch [email protected] for the project I'm working on.

The imports for DraggableOptions, DropzoneOptions, ResizableOptions could not be resolved.

Here is the diff that solved my problem:

diff --git a/node_modules/reactablejs/dist/src/index.d.ts b/node_modules/reactablejs/dist/src/index.d.ts
index 4645aea..bd8f173 100644
--- a/node_modules/reactablejs/dist/src/index.d.ts
+++ b/node_modules/reactablejs/dist/src/index.d.ts
@@ -1,12 +1,15 @@
+import { DraggableOptions } from '@interactjs/actions/drag/plugin';
+import { DropzoneOptions } from '@interactjs/actions/drop/plugin';
+import { ResizableOptions } from '@interactjs/actions/resize/plugin';
 import * as React from 'react';
 export interface InjectedProps {
     getRef: React.Ref<string> | React.LegacyRef<string>;
 }
 export interface InteractProps {
-    draggable?: Interact.DraggableOptions | boolean;
-    resizable?: Interact.ResizableOptions | boolean;
-    gesturable?: Interact.ResizableOptions | boolean;
-    dropzone?: Interact.DropzoneOptions | boolean;
+    draggable?: DraggableOptions | boolean;
+    resizable?: ResizableOptions | boolean;
+    gesturable?: ResizableOptions | boolean;
+    dropzone?: DropzoneOptions | boolean;
     onDragStart?: Interact.ListenersArg;
     onDragMove?: Interact.ListenersArg;
     onDragEnd?: Interact.ListenersArg;

This issue body was partially generated by patch-package.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.