Skip to content

Commit 6a214e8

Browse files
committed
Flow fixes, dep rearranging
1 parent eb95dc5 commit 6a214e8

File tree

4 files changed

+35
-20
lines changed

4 files changed

+35
-20
lines changed

lib/Resizable.jsx

+20-8
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,20 @@
11
import {default as React, PropTypes} from 'react';
22
import {DraggableCore} from 'react-draggable';
3-
import assign from 'object-assign';
43
import cloneElement from './cloneElement';
54

5+
type Position = {
6+
deltaX: number,
7+
deltaY: number
8+
};
9+
type State = {
10+
aspectRatio: number,
11+
resizing: boolean,
12+
height: number,
13+
width: number,
14+
};
15+
616
export default class Resizable extends React.Component {
17+
718
static propTypes = {
819
//
920
// Required Props
@@ -40,8 +51,8 @@ export default class Resizable extends React.Component {
4051
handleSize: [20, 20]
4152
};
4253

43-
state = {
4454
bounds: this.constraintsToBounds(),
55+
state: State = {
4556
width: this.props.width,
4657
height: this.props.height
4758
};
@@ -74,8 +85,8 @@ export default class Resizable extends React.Component {
7485
* @param {String} handlerName Handler name to wrap.
7586
* @return {Function} Handler function.
7687
*/
77-
resizeHandler(handlerName: string) {
78-
return (e, {node, position}) => {
88+
resizeHandler(handlerName: string): Function {
89+
return (e, {node, position}: {node: HTMLElement, position: Position}) => {
7990
let width = this.state.width + position.deltaX, height = this.state.height + position.deltaY;
8091
this.props[handlerName] && this.props[handlerName](e, {node, size: {width, height}});
8192

@@ -89,17 +100,18 @@ export default class Resizable extends React.Component {
89100
};
90101
}
91102

92-
render() {
103+
render(): ReactElement {
93104
let p = this.props;
94105
let className = p.className ?
95106
`${p.className} react-resizable`:
96-
'react-resizable'
107+
'react-resizable';
97108

98109
// What we're doing here is getting the child of this element, and cloning it with this element's props.
99110
// We are then defining its children as:
100111
// Its original children (resizable's child's children), and
101112
// A draggable handle.
102-
return cloneElement(p.children, assign({}, p, {
113+
return cloneElement(p.children, {
114+
...p,
103115
className,
104116
children: [
105117
p.children.props.children,
@@ -114,6 +126,6 @@ export default class Resizable extends React.Component {
114126
<span className="react-resizable-handle" />
115127
</DraggableCore>
116128
]
117-
}));
129+
});
118130
}
119131
}

lib/ResizableBox.jsx

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import {default as React, PropTypes} from 'react';
22
import Resizable from './Resizable';
33

4+
type State = {width: number, height: number, aspectRatio: number};
45
type Size = {width: number, height: number};
56
type ResizeData = {element: Element, size: Size};
67

@@ -19,15 +20,13 @@ export default class ResizableBox extends React.Component {
1920
handleSize: [20,20]
2021
};
2122

22-
state = {
23+
state: State = {
2324
width: this.props.width,
2425
height: this.props.height,
2526
aspectRatio: this.props.width / this.props.height
2627
};
2728

28-
// TODO data is ResizeData type, but that doesn't work in babel-typecheck pre-babel6
29-
onResize = (event: Event, data: Object) => {
30-
let {element, size} = data;
29+
onResize = (event, {element, size}) => {
3130
let {width, height} = size;
3231
let widthChanged = width !== this.state.width, heightChanged = height !== this.state.height;
3332
if (!widthChanged && !heightChanged) return;
@@ -60,8 +59,9 @@ export default class ResizableBox extends React.Component {
6059
}
6160
return [width, height];
6261
};
62+
onResize: (event: Event, data: ResizeData) => void;
6363

64-
render() {
64+
render(): ReactElement {
6565
// Basic wrapper around a Resizable instance.
6666
// If you use Resizable directly, you are responsible for updating the component
6767
// with a new width and height.

lib/cloneElement.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
1-
import assign from 'object-assign';
1+
// @flow
22
import React from 'react';
33

44
// React.addons.cloneWithProps look-alike that merges style & className.
5-
module.exports = function cloneElement(element: React.Component, props: Object) {
5+
module.exports = function cloneElement(element: ReactElement, props: Object): ReactElement {
66
if (props.style && element.props.style) {
7-
props.style = assign({}, element.props.style, props.style);
7+
props.style = {...element.props.style, ...props.style};
88
}
99
if (props.className && element.props.className) {
10-
props.className = element.props.className + ' ' + props.className;
10+
props.className = `${element.props.className} ${props.className}`;
1111
}
1212
return React.cloneElement(element, props);
1313
};

package.json

+6-3
Original file line numberDiff line numberDiff line change
@@ -41,16 +41,19 @@
4141
"eslint-plugin-react": "^3.16.1",
4242
"lodash": "^4.3.0",
4343
"pre-commit": "^1.1.2",
44-
"react": "^0.14.7",
4544
"style-loader": "^0.13.0",
45+
"react": "^0.14.7",
46+
"react-dom": "^0.14.7",
4647
"webpack": "^1.12.13",
4748
"webpack-dev-server": "^1.14.1"
4849
},
4950
"dependencies": {
50-
"react-dom": "^0.14.7",
51-
"object-assign": "^4.0.1",
5251
"react-draggable": "^1.2.0"
5352
},
53+
"peerDependencies": {
54+
"react": "^0.14.7",
55+
"react-dom": "^0.14.7"
56+
},
5457
"publishConfig": {
5558
"registry": "https://registry.npmjs.org"
5659
},

0 commit comments

Comments
 (0)