1.0.14 • Published 4 years ago

react-managed-draggable v1.0.14

Weekly downloads
8
License
MIT
Repository
github
Last release
4 years ago

React Managed Draggable

Fully controlled React component with simple dragging interface

Allows you to drag elements rendered by React components. Mouse and touch dragging are both supported.

Installation

Node.JS

npm install --save react-managed-draggable

Browser

<script src="//unpkg.com/react-managed-draggable@latest/lib/browser/bundle.js"></script>
<!-- or: -->
<script src="//unpkg.com/react-managed-draggable@latest/lib/browser/bundle.min.js"></script>

Example usage

Example on CodePen.io

class App extends React.PureComponent {
  state = {
    deltaX: 0,
    deltaY: 0
  };

  render() {
    return (
      <ReactManagedDraggable.Draggable
        style={{ position: "relative", cursor: "pointer" }}
        onDragStart={this.handleDragStart}
        onDragMove={this.handleDragMove}
        onDragEnd={this.handleDragEnd}
      >
        <div
          style={{
            position: "absolute",
            top: this.state.deltaY,
            left: this.state.deltaX
          }}
        >
          Hello world
        </div>
      </ReactManagedDraggable.Draggable>
    );
  }

  handleDragStart = (event, dragInformation) => {
    // No-op.
  };

  handleDragMove = (event, dragInformation) => {
    this.setState({
      deltaX: dragInformation.current.x - dragInformation.start.x,
      deltaY: dragInformation.current.y - dragInformation.start.y
    });
  };

  handleDragEnd = (event, dragInformation) => {
    this.setState({ deltaX: 0, deltaY: 0 });
  };
}

ReactDOM.render(<App />, document.getElementById("container"));
1.0.14

4 years ago

1.0.13

4 years ago

1.0.12

4 years ago

1.0.11

4 years ago

1.0.10

5 years ago

1.0.9

5 years ago

1.0.8

5 years ago

1.0.7

5 years ago

1.0.6

5 years ago

1.0.5

5 years ago

1.0.4

5 years ago

1.0.3

5 years ago

1.0.2

5 years ago

1.0.1

5 years ago

1.0.0

5 years ago

0.2.0

5 years ago

0.1.8

6 years ago

0.1.7

6 years ago

0.1.6

6 years ago

0.1.5

6 years ago

0.1.4

6 years ago

0.1.3

6 years ago

0.1.2

6 years ago

0.1.1

6 years ago

0.1.0

6 years ago