Giter Site home page Giter Site logo

charygao / react-resizable-rotatable-draggable Goto Github PK

View Code? Open in Web Editor NEW

This project forked from mockingbot/react-resizable-rotatable-draggable

0.0 0.0 0.0 1002 KB

A rectangle react component which can be resized and rotated

Home Page: https://mockingbot.github.io/react-resizable-rotatable-draggable/

License: MIT License

JavaScript 100.00%

react-resizable-rotatable-draggable's Introduction

React-resizable-rotatable-draggable-rectangle

NPM JavaScript Style Guide

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

Installation

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

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'

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

  handleResize = (style, isShiftKey, type) => {
    // type is a string and it shows which resize-handler you clicked
    // e.g. if you clicked top-right handler, then type is 'tr'
    let { top, left, width, height } = style
    top = Math.round(top)
    left = Math.round(left)
    width = Math.round(width)
    height = Math.round(height)
    this.setState({
      top,
      left,
      width,
      height
    })
  }

  handleRotate = (rotateAngle) => {
    this.setState({
      rotateAngle
    })
  }

  handleDrag = (deltaX, deltaY) => {
    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}
        />
      </div>
    )
  }
}

export default App

Props

Props Type Default Example
left number.isRequired 10
top number.isRequired 10
width number.isRequired 100
height number.isRequired 100
rotateAngle number 0 0
rotatable bool true true
zoomable string '' 'n, w, s, e, nw, ne, se, sw'
minWidth number 10 0
minHeight number 10 0
aspectRatio number (width / height) 1(which makes the rectangle a square)
onRotateStart func
onRotate func (rotateAngle)
onRotateEnd func
onResizeStart func
onResize func (style, isShiftKey, type)
onResizeEnd func
onDragStart func
onDrag func (deltaX, deltaY)
onDragEnd func

License

MIT © MockingBot

react-resizable-rotatable-draggable's People

Contributors

dr-js avatar iny7 avatar pugson avatar weiwang120 avatar

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.