2.0.2 • Published 4 years ago

react-resizable-rotatable-draggable-touch-v2 v2.0.2

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

react-resizable-rotatable-draggable-touch-v2

NPM JavaScript Style Guide

A react widget that can be dragged, resized and rotated via a handler.

This is a fork of react-resizable-rotatable-draggable-touch which is a fork of react-resizable-rotatable-draggable, with a few improvements and extra props.

Installation

npm install --save react-resizable-rotatable-draggable-touch-v2`

Then you will need to install peer dependency

npm install --save styled-components

Usage

import React, { Component } from 'react'
import ResizableRect from 'react-resizable-rotatable-draggable-touch-v2'

class App extends Component {
  constructor() {
    super()
    this.state = {
      width: 100,
      height: 100,
      top: 100,
      left: 100,
      rotateAngle: 0
    }
  }

  handleResize = ({ style: { top, left, width, height }, isShiftKey, type, event }) => {
    console.log('resize', top, left, width, height, event)
    this.setState({
      top: Math.round(top),
      left: Math.round(left),
      width: Math.round(width),
      height: Math.round(height)
    })
  }

  handleRotate = ({ rotateAngle, event }) => {
    console.log('rotate', rotateAngle, event)
    this.setState({ rotateAngle })
  }

  handleDrag = ({ deltaX, deltaY, event }) => {
    console.log('drag', deltaX, deltaY, event)
    this.setState({
      left: this.state.left + deltaX,
      top: this.state.top + deltaY
    })
  }

  render() {
    const {width, top, left, height, rotateAngle} = this.state
    return (
      <div className="App">
        <ResizableRect
          left={left}
          top={top}
          width={width}
          height={height}
          rotateAngle={rotateAngle}
          // aspectRatio={false}
          // minWidth={10}
          // minHeight={10}
          zoomable='n, w, s, e, nw, ne, se, sw'
          // rotatable={true}
          // onRotateStart={this.handleRotateStart}
          onRotate={this.handleRotate}
          // onRotateEnd={this.handleRotateEnd}
          // onResizeStart={this.handleResizeStart}
          onResize={this.handleResize}
          // onResizeEnd={this.handleUp}
          // onDragStart={this.handleDragStart}
          onDrag={this.handleDrag}
          // onDragEnd={this.handleDragEnd}
          color="#6963da"
        >Hello world</ResizableRect>
      </div>
    )
  }
}

export default App

Props

PropsTypeDefaultExample
leftnumber.isRequired10
topnumber.isRequired10
widthnumber.isRequired100
heightnumber.isRequired100
rotateAnglenumber00
rotatablebooltruetrue
zoomablestring'''n, w, s, e, nw, ne, se, sw'
minWidthnumber100
minHeightnumber100
aspectRationumber (width / height)1(which makes the rectangle a square)
onRotateStartfunc
onRotatefunc(rotateAngle)
onRotateEndfunc
onResizeStartfunc
onResizefunc(style, isShiftKey, type)
onResizeEndfunc
onDragStartfunc
onDragfunc(deltaX, deltaY)
onDragEndfunc
onClickfunc
onDoubleClickfunc
classNamestring''
colorstring#333

License

MIT © MockingBot rinose Vlad-x

2.0.2

4 years ago

2.0.1

4 years ago

2.0.0

4 years ago