Skip to content

Commit 0482f21

Browse files
committed
Dependency updates, including <Draggable> v1.
1 parent 6b44992 commit 0482f21

File tree

15 files changed

+118
-87
lines changed

15 files changed

+118
-87
lines changed

.babelrc

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"stage": 0
3+
}

.eslintrc

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
{
2+
"root": true,
3+
"parser": "babel-eslint",
4+
"plugins": [
5+
"react"
6+
],
7+
"extends": "eslint:recommended",
8+
"rules": {
9+
"strict": 0,
10+
"quotes": [0, "single"],
11+
"curly": [1, "multi-line"],
12+
"camelcase": 0,
13+
"comma-dangle": 0,
14+
"dot-notation": 0,
15+
"no-console": 0,
16+
"no-use-before-define": [1, "nofunc"],
17+
"no-underscore-dangle": 0,
18+
"no-unused-vars": 0,
19+
"new-cap": 0,
20+
"react/jsx-uses-vars": 1,
21+
"semi": [1, "always"]
22+
},
23+
env: {
24+
"browser": true,
25+
"node": true
26+
},
27+
"ecmaFeatures": {
28+
"jsx": true
29+
}
30+
}

.jshintignore

Lines changed: 0 additions & 1 deletion
This file was deleted.

.jshintrc

Lines changed: 0 additions & 18 deletions
This file was deleted.

README.md

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,11 @@ render: function() {
3030
</ResizableBox>
3131
);
3232
}
33+
```
3334

35+
### <Resizable> Options
3436

35-
### Options
37+
```js
3638
{
3739
// Functions
3840
onResizeStop: React.PropTypes.func,
@@ -47,3 +49,20 @@ handleSize: React.PropTypes.array,
4749
draggableOpts: React.PropTypes.object
4850
}
4951
```
52+
53+
### <ResizableBox> Options
54+
55+
```js
56+
{
57+
lockAspectRatio: React.PropTypes.bool, // Preserves aspect
58+
59+
// Constaints coords, pass [x,y]
60+
minConstraints: React.PropTypes.arrayOf(React.PropTypes.number),
61+
maxConstraints: React.PropTypes.arrayOf(React.PropTypes.number),
62+
63+
// Initial width/height - otherwise use CSS
64+
height: React.PropTypes.number,
65+
width: React.PropTypes.number
66+
}
67+
```
68+
```

TODO.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
Blocking issues to release with react-draggable v1
2+
3+
- [x] Basic Resizable functionality
4+
- [x] Basic ResizableBox functionality
5+
- [ ] Grid Snapping
6+
- [ ] Min/Max Constraints
7+
- [x] Aspect Ratios

build.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#!/bin/bash
22
rm -rf ./build
3-
./node_modules/.bin/babel --stage 0 --out-dir ./build ./lib
3+
./node_modules/.bin/babel --out-dir ./build ./lib
44
# More cross-platform compatible than `rename`
55
find ./build -type f -name '*.jsx' -exec sh -c 'mv -f $0 ${0%.jsx}.js' {} \;

css/styles.css

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
.react-resizable {
22
position: relative;
33
}
4-
.react-resizable-handle.react-draggable {
4+
.react-resizable-handle {
55
position: absolute;
66
width: 20px;
77
height: 20px;
@@ -14,11 +14,4 @@
1414
background-origin: content-box;
1515
box-sizing: border-box;
1616
cursor: se-resize;
17-
/* Since this handle is absolutely positioned, we don't want the
18-
draggable transforms to actually move it */
19-
transform: none !important;
20-
-webkit-transform: none !important;
21-
-ms-transform: none !important;
22-
-o-transform: none !important;
23-
-moz-transform: none !important;
2417
}

examples/1.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,12 +36,12 @@
3636
display: block;
3737
}
3838
</style>
39-
<script src="http://localhost:4002/bundle.js"></script>
39+
<script src="/bundle.js"></script>
4040
<title>React-Resizable</title>
4141
</head>
4242
<body>
4343
<h3>React-Resizable Demo</h3>
44-
<p>React-resizable is a simple component that you wrap your existing components inside. It
44+
<p>React-resizable is a simple component that you wrap your existing components inside. It
4545
gives those components resize handles.
4646
</p>
4747
<p><a href="https://github.com/STRML/react-resizable">View project on GitHub</a></p>

lib/Resizable.jsx

Lines changed: 15 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,11 @@
11
'use strict';
22
var React = require('react');
3-
var Draggable = require('react-draggable');
4-
var PureRenderMixin = require('react/lib/ReactComponentWithPureRenderMixin');
3+
var DraggableCore = require('react-draggable').DraggableCore;
54
var assign = require('object-assign');
65
var cloneElement = require('./cloneElement');
76

87
var Resizable = module.exports = React.createClass({
98
displayName: 'Resizable',
10-
mixins: [PureRenderMixin],
119

1210
propTypes: {
1311
// Require that one and only one child be present.
@@ -31,22 +29,21 @@ var Resizable = module.exports = React.createClass({
3129
};
3230
},
3331

34-
getInitialState: function() {
32+
getInitialState() {
3533
return {
3634
bounds: this.constraintsToBounds(),
37-
initialWidth: this.props.width,
38-
initialHeight: this.props.height
35+
width: this.props.width,
36+
height: this.props.height
3937
};
4038
},
4139

42-
componentWillReceiveProps: function(props) {
40+
componentWillReceiveProps(props: Object) {
4341
if (!this.state.resizing) {
4442
this.setState({
45-
initialWidth: props.width,
46-
initialHeight: props.height,
43+
width: props.width,
44+
height: props.height,
4745
bounds: this.constraintsToBounds()
4846
});
49-
this.refs.draggable.resetState();
5047
}
5148
},
5249

@@ -62,22 +59,25 @@ var Resizable = module.exports = React.createClass({
6259
};
6360
},
6461

65-
6662
/**
6763
* Wrapper around drag events to provide more useful data.
6864
*
6965
* @param {String} handlerName Handler name to wrap.
7066
* @return {Function} Handler function.
7167
*/
72-
resizeHandler(handlerName) {
68+
resizeHandler(handlerName: string) {
7369
var me = this;
7470
return function(e, {node, position}) {
75-
me.props[handlerName] && me.props[handlerName](e, {node, size: calcWH(me.state, position)});
71+
let width = me.state.width + position.deltaX, height = me.state.height + position.deltaY;
72+
console.log(position);
73+
me.props[handlerName] && me.props[handlerName](e, {node, size: {width, height}});
7674

7775
if (handlerName === 'onResizeStart') {
7876
me.setState({resizing: true});
7977
} else if (handlerName === 'onResizeStop') {
8078
me.setState({resizing: false});
79+
} else {
80+
me.setState({width, height});
8181
}
8282
};
8383
},
@@ -92,7 +92,7 @@ var Resizable = module.exports = React.createClass({
9292
return cloneElement(p.children, assign({}, p, {
9393
children: [
9494
p.children.props.children,
95-
<Draggable
95+
<DraggableCore
9696
{...p.draggableOpts}
9797
ref="draggable"
9898
onStop={this.resizeHandler('onResizeStop')}
@@ -101,18 +101,8 @@ var Resizable = module.exports = React.createClass({
101101
bounds={this.state.bounds}
102102
>
103103
<span className="react-resizable-handle" />
104-
</Draggable>
104+
</DraggableCore>
105105
]
106106
}));
107107
}
108108
});
109-
110-
/**
111-
* Parse left and top coordinates.
112-
* @param {Number} options.left Left coordinate.
113-
* @param {Number} options.top Top coordinate.
114-
* @return {Object} Coordinates
115-
*/
116-
function calcWH({initialWidth, initialHeight}, {left, top}) {
117-
return {width: initialWidth + left, height: initialHeight + top};
118-
}

0 commit comments

Comments
 (0)