1.0.0 • Published 4 years ago

react-morphable v1.0.0

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

React-Morphable

View the Demo

A simple div that can be resized, rotated and / or dragged.

You can either use the <Morphable> element directly, without taking care about the position / size / rotation state of the div (while still getting access to it), or <MorphableCore> if you want the control of position / size / rotation state.

Installation

Using npm:

$ npm install --save react-morphable

Usage

import { Morphable, MorphableCore } from 'react-morphable';

render() {
  return (
    <Morphable>
      // children
    </Morphable>
  );

  // or

  return (
    <MorphableCore
      position={this.state.position}
      size={this.state.size}
      rotation={this.state.rotation}
    >
      // children
    </MorphableCore>
  );

}

Props

These props apply only to <MorphableCore>.

PropTypeDefault
position{ width: number, height: number }{ width: 150, height: 150 }
size{ x: number, y: number }{ x: 0, y: 0}
rotationnumber0

These props apply to both <MorphableCore> and <Morphable>. Note regarding CSS classes : react-morphable uses React-JSS, therefore it's not feasible to edit directly the class of a div as the class name is not fixed. That's why the prop classProps has been added (classes prop is already taken by react-JSS, we couldn't use it), thanks to which you can give any class name you want to any HTML element inside react-morphable, allowing to customize anything.

PropTypeDefault
childrenReact.Elementany
isMorphablebooltrue
lockAspectRatioboolfalse
disableDragboolfalse
disableResizeboolfalse
disableRotationboolfalse
disableGuidesbooltrue
disableBounds{forDrag: forResize: true}{forDrag: true, forResize: true (always, not yet set-up)}
bounds{top: left: bottom: right: }{ top: 0, left: 0, bottom: 0, right: 0 }
magnetismGrids{ drag: resize: rotation: }{ drag: 5, resize: 5, rotation: 5 }
debugboolfalse
onHandleMouseDownfunc({ e })void
onDragStartfunc({ e })void
onDragfunc({ e, x, y })void
onDragStopfunc({ e })void
onResizeStartfunc({ e })void
onResizefunc({ e, x, y, width, height })void
onResizeStopfunc({ e })void
onRotateStartfunc({ e })void
onRotatefunc({ e, rotation })void
onRotateEndfunc({ e })void
styles{ root: , rootTransformed: , corner: , topLeftCorner: , topRightCorner: , bottomLeftCorner: , bottomRightCorner: , middleTopCorner: , middleRightCorner: , middleBottomCorner: , middleLeftCorner: , middleTopAboveCorner: }void
classProps{ root: , rootTransformed: , corner: , topLeftCorner: , topRightCorner: , bottomLeftCorner: , bottomRightCorner: , middleTopCorner: , middleRightCorner: , middleBottomCorner: , middleLeftCorner: , middleTopAboveCorner: }void

To-do

  • styles
  • classes
  • bounds for drag
  • bounds for resize
  • minimum height, minimum width
  • accessibility
  • refactoring ?
1.0.0

4 years ago

0.3.2

6 years ago

0.3.1

6 years ago

0.3.0

6 years ago

0.2.1

6 years ago

0.1.1

6 years ago

0.1.0

6 years ago