0.3.0-dev.0 • Published 3 years ago

@posturize/react-resizable-rotatable-draggable v0.3.0-dev.0

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

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

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

License

MIT © MockingBot

ansi-regexacornajvacorn-jsxansi-stylesargparseansi-escapesarray-includesarray-unionarray-uniqarray.prototype.flatarray.prototype.flatmapasyncastral-regexbabel-plugin-dynamic-import-nodebabel-plugin-syntax-jsxbrowserslistbalanced-matchbrace-expansionbuiltin-modulescall-bindcallsitescamelizecaniuse-litechardetcli-cursorcolor-convertcolor-namecli-widthchalkcommandercolorettecontains-pathconvert-source-mapconcat-mapcore-js-compatcross-spawncss-color-keywordscss-box-modeldebugcss-to-react-nativedeep-isdoctrinedefine-propertieselectron-to-chromiumemail-addresseserror-exescaladeemoji-regexes-abstractes-to-primitiveescape-string-regexpeslint-config-standard-jsxeslint-import-resolver-nodeeslint-module-utilseslint-plugin-eseslint-utilseslint-scopeeslint-visitor-keysespreeesqueryesprimaesrecurseestraverseestree-walkeresutilsexternal-editorfiguresfast-deep-equalfast-json-stable-stringifyfast-levenshteinfile-entry-cachefilenamifyfilename-reserved-regexfilenamify-urlfind-upflat-cacheflattedfs.realpathfs-extrafunctional-red-black-treefunction-bindget-intrinsicgensyncglobbyglobalsgraceful-fsglobhashas-flaghas-symbolshosted-git-infohoist-non-react-staticsiconv-litehumanize-urlignoreimport-freshimurmurhashinflightinquirerinheritsinternal-slotis-arrayishis-callableis-fullwidth-code-pointis-date-objectis-core-moduleis-moduleis-plain-objis-negative-zerois-symbolis-regexis-whatis-stringisexejs-yamlisarrayjsescjs-tokensjson-stable-stringify-without-jsonifyjson-schema-traversejson5jsonfilejsx-ast-utilslevnload-json-filelocate-pathmemoize-onelodashloose-envifymerge-anythingmagic-stringmimic-fnminimatchmute-streammkdirpmsminimistnatural-comparenice-trynormalize-package-datanormalize-urlnode-releasesobject-assignobject-inspectobject-keysobject.assignobject.fromentriesobject.entriesobject.valuesonceoptionatoronetimeos-tmpdirp-limitp-tryp-locateparent-moduleparse-jsonpath-existspath-is-absolutepath-parsepath-is-insidepath-keypath-typepinkiepinkie-promisepkg-dirpostcss-value-parserprelude-lsprepend-httpprogresspifyraf-schdpunycodequery-stringreact-beautiful-dndreact-reduxread-pkgread-pkg-upreduxregenerateregenerator-runtimeregenerate-unicode-propertiesreact-isregenerator-transformregexpu-coreregexp.prototype.flagsregexppregjsgenregjsparserresolverestore-cursorresolve-fromrollup-pluginutilsrimrafrun-asyncsafe-buffersemverschedulerrxjsshebang-commandsafer-buffershebang-regexsort-keysslice-ansiside-channelsignal-exitspdx-correctspdx-exceptionssource-mapspdx-expression-parsesourcemap-codecspdx-license-idsstrict-uri-encodesprintf-jsstring.prototype.matchallstring-widthstring.prototype.trimstartstrip-ansistring.prototype.trimendstrip-bomstrip-outerstrip-json-commentsstrip-url-authstylis-rule-sheetsymbol-observablesupports-colorstylisthroughtmptext-tabletableto-fast-propertiestrim-repeatedtiny-invarianttsconfig-pathstype-checkunicode-canonical-property-names-ecmascriptunicode-match-property-ecmascripttslibunicode-match-property-value-ecmascriptunicode-property-aliases-ecmascriptuniversalifyuri-jsuse-memo-onevalidate-npm-package-licenseword-wrapwrappywhichwrite
0.3.0-dev.0

3 years ago