Skip to content

Commit ff77108

Browse files
author
dr-js
committed
Initial commit
0 parents  commit ff77108

File tree

15 files changed

+11408
-0
lines changed

15 files changed

+11408
-0
lines changed

.gitignore

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# Logs
2+
logs
3+
*.log
4+
5+
# Dependency directory
6+
node_modules
7+
8+
# WebStorm configuration
9+
.idea
10+
11+
# distribute file
12+
**/*-gitignore/**
13+
**/*-gitignore*
14+
/*.tgz
15+
16+
/lib
17+
/example/index.js

.npmignore

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# distribute file
2+
**/*-gitignore/**
3+
**/*-gitignore*
4+
/*.tgz
5+
6+
/*.lock
7+
/*lock.json
8+
/.*
9+
/src
10+
/example
11+
/*.config.js

LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2018 MockingBot
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

README.md

Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
# React-resizable-rotatable-draggable-rectangle
2+
3+
4+
A react widget that can be resized and rotated via a handler.
5+
6+
### Installation
7+
8+
`npm install --save react-resizable-rotatable-draggable`
9+
10+
### Usage
11+
12+
```javascript
13+
import React, { Component } from 'react'
14+
import ResizableRect from 'react-resizable-rotatable-draggable'
15+
16+
class App extends Component {
17+
constructor() {
18+
super()
19+
this.state = {
20+
width: 100,
21+
height: 100,
22+
top: 100,
23+
left: 100,
24+
rotateAngle: 0
25+
}
26+
}
27+
28+
handleResize = (style, isShiftKey, type) => {
29+
// type is a string and it shows which resize-handler you clicked
30+
// e.g. if you clicked top-right handler, then type is 'tr'
31+
let { top, left, width, height } = style
32+
top = Math.round(top)
33+
left = Math.round(left)
34+
width = Math.round(width)
35+
height = Math.round(height)
36+
this.setState({
37+
top,
38+
left,
39+
width,
40+
height
41+
})
42+
}
43+
44+
handleRotate = (rotateAngle) => {
45+
this.setState({
46+
rotateAngle
47+
})
48+
}
49+
50+
handleDrag = (deltaX, deltaY) => {
51+
this.setState({
52+
left: this.state.left + deltaX,
53+
top: this.state.top + deltaY
54+
})
55+
}
56+
57+
render() {
58+
const {width, top, left, height, rotateAngle} = this.state
59+
return (
60+
<div className="App">
61+
<ResizableRect
62+
left={left}
63+
top={top}
64+
width={width}
65+
height={height}
66+
rotateAngle={rotateAngle}
67+
// aspectRatio={false}
68+
// minWidth={10}
69+
// minHeight={10}
70+
zoomable='n, w, s, e, nw, ne, se, sw'
71+
// rotatable={true}
72+
// onRotateStart={this.handleRotateStart}
73+
onRotate={this.handleRotate}
74+
// onRotateEnd={this.handleRotateEnd}
75+
// onResizeStart={this.handleResizeStart}
76+
onResize={this.handleResize}
77+
// onResizeEnd={this.handleUp}
78+
// onDragStart={this.handleDragStart}
79+
onDrag={this.handleDrag}
80+
// onDragEnd={this.handleDragEnd}
81+
/>
82+
</div>
83+
)
84+
}
85+
}
86+
87+
export default App
88+
89+
```
90+
91+
### Props
92+
93+
| Props | Type | Default | Example |
94+
|:-----------:|:-----------------------:|:-------:|:-------------------------------------:|
95+
|left | number.isRequired | // | 10 |
96+
|top | number.isRequired | // | 10 |
97+
|width | number.isRequired | // | 100 |
98+
|height | number.isRequired | // | 100 |
99+
|rotateAngle | number | 0 | 0 |
100+
|rotatable | bool | true | true |
101+
|zoomable | string | '' | 'n, w, s, e, nw, ne, se, sw' |
102+
|minWidth | number | 10 | 0 |
103+
|minHeight | number | 10 | 0 |
104+
|aspectRatio | number (width / height) | // | 1(which makes the rectangle a square) |
105+
|onRotateStart| func | // | // |
106+
|onRotate | func | // | (rotateAngle) |
107+
|onRotateEnd | func | // | // |
108+
|onResizeStart| func | // | // |
109+
|onResize | func | // | (style, isShiftKey, type) |
110+
|onResizeEnd | func | // | // |
111+
|onDragStart | func | // | // |
112+
|onDrag | func | // | (deltaX, deltaY) |
113+
|onDragEnd | func | // | // |

babel.config.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
const BABEL_ENV = process.env.BABEL_ENV || ''
2+
const isDev = BABEL_ENV.includes('dev')
3+
4+
module.exports = {
5+
presets: [
6+
[ '@babel/env', { targets: isDev ? { node: '8.8' } : { browser: '>= 1%' } } ],
7+
[ '@babel/react' ]
8+
],
9+
plugins: [
10+
[ 'styled-components' ],
11+
[ '@babel/proposal-class-properties' ],
12+
[ 'minify-replace', { replacements: [ { identifierName: '__DEV__', replacement: { type: 'booleanLiteral', value: isDev } } ] } ]
13+
],
14+
comments: false
15+
}

example/index.html

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="utf-8">
5+
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
6+
<meta name="theme-color" content="#000000">
7+
<script src="index.js"></script>
8+
<title>React App</title>
9+
</head>
10+
<body>
11+
<noscript>
12+
You need to enable JavaScript to run this app.
13+
</noscript>
14+
<div id="root"></div>
15+
<script>
16+
const { init } = window.RRRD
17+
init(document.querySelector('#root'))
18+
</script>
19+
</body>
20+
</html>

0 commit comments

Comments
 (0)