react-resizable 1.7.5 → 1.11.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (50) hide show
  1. package/.babelrc +10 -4
  2. package/.browserslistrc +3 -0
  3. package/.eslintrc +10 -6
  4. package/.flowconfig +9 -11
  5. package/CHANGELOG.md +59 -29
  6. package/LICENSE +21 -0
  7. package/README.md +18 -5
  8. package/__tests__/Resizable.test.js +245 -0
  9. package/__tests__/ResizableBox.test.js +99 -0
  10. package/__tests__/__snapshots__/Resizable.test.js.snap +29 -0
  11. package/__tests__/__snapshots__/ResizableBox.test.js.snap +23 -0
  12. package/build/Resizable.js +183 -177
  13. package/build/Resizable.js.flow +115 -152
  14. package/build/ResizableBox.js +95 -75
  15. package/build/ResizableBox.js.flow +61 -34
  16. package/build/propTypes.js +112 -0
  17. package/build/propTypes.js.flow +135 -0
  18. package/build/utils.js +27 -0
  19. package/build/{cloneElement.js.flow → utils.js.flow} +2 -2
  20. package/coverage/clover.xml +107 -0
  21. package/coverage/coverage-final.json +5 -0
  22. package/coverage/lcov-report/Resizable.js.html +665 -0
  23. package/coverage/lcov-report/ResizableBox.js.html +374 -0
  24. package/coverage/lcov-report/base.css +224 -0
  25. package/coverage/lcov-report/block-navigation.js +79 -0
  26. package/coverage/lcov-report/favicon.png +0 -0
  27. package/coverage/lcov-report/flow-typed/npm/index.html +111 -0
  28. package/coverage/lcov-report/flow-typed/npm/jest_v26.x.x.js.html +3734 -0
  29. package/coverage/lcov-report/index.html +156 -0
  30. package/coverage/lcov-report/prettify.css +1 -0
  31. package/coverage/lcov-report/prettify.js +2 -0
  32. package/coverage/lcov-report/propTypes.js.html +485 -0
  33. package/coverage/lcov-report/react-resizable/dist/bundle.js.html +95 -0
  34. package/coverage/lcov-report/react-resizable/dist/index.html +111 -0
  35. package/coverage/lcov-report/react-resizable/flow-typed/npm/index.html +111 -0
  36. package/coverage/lcov-report/react-resizable/flow-typed/npm/jest_v26.x.x.js.html +3734 -0
  37. package/coverage/lcov-report/react-resizable/index.html +111 -0
  38. package/coverage/lcov-report/react-resizable/index.js.html +101 -0
  39. package/coverage/lcov-report/sort-arrow-sprite.png +0 -0
  40. package/coverage/lcov-report/sorter.js +170 -0
  41. package/coverage/lcov-report/utils.js.html +122 -0
  42. package/coverage/lcov.info +233 -0
  43. package/css/styles.css +53 -5
  44. package/dist/bundle.js +6 -0
  45. package/flow-typed/npm/jest_v26.x.x.js +1218 -0
  46. package/package.json +33 -25
  47. package/setupTests/enzyme.js +4 -0
  48. package/.github/ISSUE_TEMPLATE.md +0 -23
  49. package/.github/PULL_REQUEST_TEMPLATE.md +0 -6
  50. package/build/cloneElement.js +0 -20
@@ -1,108 +1,31 @@
1
1
  // @flow
2
2
  import React from 'react';
3
- import PropTypes from 'prop-types';
3
+ import type {Node as ReactNode} from 'react';
4
4
  import {DraggableCore} from 'react-draggable';
5
- import cloneElement from './cloneElement';
6
- import type {Element as ReactElement, Node as ReactNode} from 'react';
7
-
8
- type Axis = 'both' | 'x' | 'y' | 'none';
9
- type State = {
10
- resizing: boolean,
11
- width: number, height: number,
12
- slackW: number, slackH: number
13
- };
14
- type DragCallbackData = {
15
- node: HTMLElement,
16
- x: number, y: number,
17
- deltaX: number, deltaY: number,
18
- lastX: number, lastY: number
19
- };
20
- export type ResizeCallbackData = {
21
- node: HTMLElement,
22
- size: {width: number, height: number}
23
- };
24
- export type Props = {
25
- children: ReactElement<any>,
26
- className?: ?string,
27
- width: number,
28
- height: number,
29
- handleSize: [number, number],
30
- lockAspectRatio: boolean,
31
- axis: Axis,
32
- minConstraints: [number, number],
33
- maxConstraints: [number, number],
34
- onResizeStop?: ?(e: SyntheticEvent<>, data: ResizeCallbackData) => any,
35
- onResizeStart?: ?(e: SyntheticEvent<>, data: ResizeCallbackData) => any,
36
- onResize?: ?(e: SyntheticEvent<>, data: ResizeCallbackData) => any,
37
- draggableOpts?: ?Object
38
- };
39
-
40
- export default class Resizable extends React.Component<Props, State> {
41
- static propTypes = {
42
- //
43
- // Required Props
44
- //
45
-
46
- // Require that one and only one child be present.
47
- children: PropTypes.element.isRequired,
48
-
49
- // Initial w/h
50
- width: PropTypes.number.isRequired,
51
- height: PropTypes.number.isRequired,
52
-
53
- //
54
- // Optional props
55
- //
56
-
57
- // If you change this, be sure to update your css
58
- handleSize: PropTypes.array,
59
-
60
- // If true, will only allow width/height to move in lockstep
61
- lockAspectRatio: PropTypes.bool,
62
-
63
- // Restricts resizing to a particular axis (default: 'both')
64
- // 'both' - allows resizing by width or height
65
- // 'x' - only allows the width to be changed
66
- // 'y' - only allows the height to be changed
67
- // 'none' - disables resizing altogether
68
- axis: PropTypes.oneOf(['both', 'x', 'y', 'none']),
69
-
70
- // Min/max size
71
- minConstraints: PropTypes.arrayOf(PropTypes.number),
72
- maxConstraints: PropTypes.arrayOf(PropTypes.number),
73
-
74
- // Callbacks
75
- onResizeStop: PropTypes.func,
76
- onResizeStart: PropTypes.func,
77
- onResize: PropTypes.func,
78
-
79
- // These will be passed wholesale to react-draggable's DraggableCore
80
- draggableOpts: PropTypes.object
81
- };
5
+ import {cloneElement} from './utils';
6
+ import {resizableProps} from "./propTypes";
7
+ import type {ResizeHandleAxis, Props, ResizableState, DragCallbackData} from './propTypes';
8
+
9
+ export default class Resizable extends React.Component<Props, ResizableState> {
10
+ static propTypes = resizableProps;
82
11
 
83
12
  static defaultProps = {
84
13
  handleSize: [20, 20],
85
14
  lockAspectRatio: false,
86
15
  axis: 'both',
87
16
  minConstraints: [20, 20],
88
- maxConstraints: [Infinity, Infinity]
17
+ maxConstraints: [Infinity, Infinity],
18
+ resizeHandles: ['se'],
19
+ transformScale: 1
89
20
  };
90
21
 
91
- state: State = {
92
- resizing: false,
93
- width: this.props.width, height: this.props.height,
94
- slackW: 0, slackH: 0
95
- };
22
+ state: ResizableState = undefined;
96
23
 
97
- componentWillReceiveProps(nextProps: Object) {
98
- // If parent changes height/width, set that in our state.
99
- if (!this.state.resizing &&
100
- (nextProps.width !== this.props.width || nextProps.height !== this.props.height)) {
101
- this.setState({
102
- width: nextProps.width,
103
- height: nextProps.height
104
- });
105
- }
24
+ lastHandleRect: ?ClientRect = null;
25
+ slack: ?[number, number] = null;
26
+
27
+ componentWillUnmount() {
28
+ this.resetData();
106
29
  }
107
30
 
108
31
  lockAspectRatio(width: number, height: number, aspectRatio: number): [number, number] {
@@ -111,24 +34,37 @@ export default class Resizable extends React.Component<Props, State> {
111
34
  return [width, height];
112
35
  }
113
36
 
114
- // If you do this, be careful of constraints
37
+ resetData() {
38
+ this.lastHandleRect = this.slack = null;
39
+ }
40
+
41
+ // Clamp width and height within provided constraints
115
42
  runConstraints(width: number, height: number): [number, number] {
116
43
  const [min, max] = [this.props.minConstraints, this.props.maxConstraints];
44
+ if (!min && !max) return [width, height];
117
45
 
46
+ // If constraining to min and max, we need to also fit width and height to aspect ratio.
118
47
  if (this.props.lockAspectRatio) {
119
- const ratio = this.state.width / this.state.height;
120
- height = width / ratio;
121
- width = height * ratio;
48
+ const resizingHorizontally = height === this.props.height;
49
+ if (resizingHorizontally) {
50
+ const ratio = this.props.width / this.props.height;
51
+ height = width / ratio;
52
+ width = height * ratio;
53
+ } else {
54
+ // Take into account vertical resize with N/S handles on locked aspect
55
+ // ratio. Calculate the change height-first, instead of width-first
56
+ const ratio = this.props.height / this.props.width;
57
+ width = height / ratio;
58
+ height = width * ratio;
59
+ }
122
60
  }
123
61
 
124
- if (!min && !max) return [width, height];
125
-
126
62
  const [oldW, oldH] = [width, height];
127
63
 
128
64
  // Add slack to the values used to calculate bound position. This will ensure that if
129
65
  // we start removing slack, the element won't react to it right away until it's been
130
66
  // completely removed.
131
- let {slackW, slackH} = this.state;
67
+ let [slackW, slackH] = this.slack || [0, 0];
132
68
  width += slackW;
133
69
  height += slackH;
134
70
 
@@ -141,12 +77,8 @@ export default class Resizable extends React.Component<Props, State> {
141
77
  height = Math.min(max[1], height);
142
78
  }
143
79
 
144
- // If the numbers changed, we must have introduced some slack. Record it for the next iteration.
145
- slackW += (oldW - width);
146
- slackH += (oldH - height);
147
- if (slackW !== this.state.slackW || slackH !== this.state.slackH) {
148
- this.setState({slackW, slackH});
149
- }
80
+ // If the width or height changed, we must have introduced some slack. Record it for the next iteration.
81
+ this.slack = [slackW + (oldW - width), slackH + (oldH - height)];
150
82
 
151
83
  return [width, height];
152
84
  }
@@ -157,75 +89,106 @@ export default class Resizable extends React.Component<Props, State> {
157
89
  * @param {String} handlerName Handler name to wrap.
158
90
  * @return {Function} Handler function.
159
91
  */
160
- resizeHandler(handlerName: string): Function {
161
- return (e: SyntheticEvent<> | MouseEvent, {node, deltaX, deltaY}: DragCallbackData) => {
92
+ resizeHandler(handlerName: 'onResize' | 'onResizeStart' | 'onResizeStop', axis: ResizeHandleAxis): Function {
93
+ return (e: SyntheticEvent<>, {node, deltaX, deltaY}: DragCallbackData) => {
94
+ // Reset data in case it was left over somehow (should not be possible)
95
+ if (handlerName === 'onResizeStart') this.resetData();
162
96
 
163
97
  // Axis restrictions
164
- const canDragX = this.props.axis === 'both' || this.props.axis === 'x';
165
- const canDragY = this.props.axis === 'both' || this.props.axis === 'y';
98
+ const canDragX = (this.props.axis === 'both' || this.props.axis === 'x') && axis !== 'n' && axis !== 's';
99
+ const canDragY = (this.props.axis === 'both' || this.props.axis === 'y') && axis !== 'e' && axis !== 'w';
100
+ // No dragging possible.
101
+ if (!canDragX && !canDragY) return;
102
+
103
+ // Decompose axis for later use
104
+ const axisV = axis[0];
105
+ const axisH = axis[axis.length - 1]; // intentionally not axis[1], so that this catches axis === 'w' for example
106
+
107
+ // Track the element being dragged to account for changes in position.
108
+ // If a handle's position is changed between callbacks, we need to factor this in to the next callback.
109
+ // Failure to do so will cause the element to "skip" when resized upwards or leftwards.
110
+ const handleRect = node.getBoundingClientRect();
111
+ if (this.lastHandleRect != null) {
112
+ // If the handle has repositioned on either axis since last render,
113
+ // we need to increase our callback values by this much.
114
+ // Only checking 'n', 'w' since resizing by 's', 'w' won't affect the overall position on page,
115
+ if (axisH === 'w') {
116
+ const deltaLeftSinceLast = handleRect.left - this.lastHandleRect.left;
117
+ deltaX += deltaLeftSinceLast;
118
+ }
119
+ if (axisV === 'n') {
120
+ const deltaTopSinceLast = handleRect.top - this.lastHandleRect.top;
121
+ deltaY += deltaTopSinceLast;
122
+ }
123
+ }
124
+ // Storage of last rect so we know how much it has really moved.
125
+ this.lastHandleRect = handleRect;
166
126
 
167
- // Update w/h
168
- let width = this.state.width + (canDragX ? deltaX : 0);
169
- let height = this.state.height + (canDragY ? deltaY : 0);
127
+ // Reverse delta if using top or left drag handles.
128
+ if (axisH === 'w') deltaX = -deltaX;
129
+ if (axisV === 'n') deltaY = -deltaY;
170
130
 
171
- // Early return if no change
172
- const widthChanged = width !== this.state.width, heightChanged = height !== this.state.height;
173
- if (handlerName === 'onResize' && !widthChanged && !heightChanged) return;
131
+ // Update w/h by the deltas. Also factor in transformScale.
132
+ let width = this.props.width + (canDragX ? deltaX / this.props.transformScale : 0);
133
+ let height = this.props.height + (canDragY ? deltaY / this.props.transformScale : 0);
174
134
 
135
+ // Run user-provided constraints.
175
136
  [width, height] = this.runConstraints(width, height);
176
137
 
177
- // Set the appropriate state for this handler.
178
- const newState = {};
179
- if (handlerName === 'onResizeStart') {
180
- newState.resizing = true;
181
- } else if (handlerName === 'onResizeStop') {
182
- newState.resizing = false;
183
- newState.slackW = newState.slackH = 0;
184
- } else {
185
- // Early return if no change after constraints
186
- if (width === this.state.width && height === this.state.height) return;
187
- newState.width = width;
188
- newState.height = height;
189
- }
138
+ const dimensionsChanged = width !== this.props.width || height !== this.props.height;
190
139
 
191
- const hasCb = typeof this.props[handlerName] === 'function';
192
- if (hasCb) {
140
+ // Call user-supplied callback if present.
141
+ const cb = typeof this.props[handlerName] === 'function' ? this.props[handlerName] : null;
142
+ // Don't call 'onResize' if dimensions haven't changed.
143
+ const shouldSkipCb = handlerName === 'onResize' && !dimensionsChanged;
144
+ if (cb && !shouldSkipCb) {
193
145
  if (typeof e.persist === 'function') e.persist();
194
- this.setState(newState, () => this.props[handlerName](e, {node, size: {width, height}}));
195
- } else {
196
- this.setState(newState);
146
+ cb(e, {node, size: {width, height}, handle: axis});
197
147
  }
148
+
149
+ // Reset internal data
150
+ if (handlerName === 'onResizeStop') this.resetData();
198
151
  };
199
152
  }
200
153
 
154
+ renderResizeHandle(resizeHandleAxis: ResizeHandleAxis): ReactNode {
155
+ const {handle} = this.props;
156
+ if (handle) {
157
+ if (typeof handle === 'function') {
158
+ return handle(resizeHandleAxis);
159
+ }
160
+ return handle;
161
+ }
162
+ return <span className={`react-resizable-handle react-resizable-handle-${resizeHandleAxis}`} />;
163
+ }
164
+
201
165
  render(): ReactNode {
166
+ // Pass along only props not meant for the `<Resizable>`.`
202
167
  // eslint-disable-next-line no-unused-vars
203
- const {children, draggableOpts, width, height, handleSize,
204
- lockAspectRatio, axis, minConstraints, maxConstraints, onResize,
205
- onResizeStop, onResizeStart, ...p} = this.props;
206
-
207
- const className = p.className ?
208
- `${p.className} react-resizable`:
209
- 'react-resizable';
168
+ const {children, className, draggableOpts, width, height, handle, handleSize,
169
+ lockAspectRatio, axis, minConstraints, maxConstraints, onResize,
170
+ onResizeStop, onResizeStart, resizeHandles, transformScale, ...p} = this.props;
210
171
 
211
172
  // What we're doing here is getting the child of this element, and cloning it with this element's props.
212
173
  // We are then defining its children as:
213
174
  // Its original children (resizable's child's children), and
214
- // A draggable handle.
175
+ // One or more draggable handles.
215
176
  return cloneElement(children, {
216
177
  ...p,
217
- className,
178
+ className: `${className ? `${className} ` : ''}react-resizable`,
218
179
  children: [
219
- children.props.children,
220
- <DraggableCore
221
- {...draggableOpts}
222
- key="resizableHandle"
223
- onStop={this.resizeHandler('onResizeStop')}
224
- onStart={this.resizeHandler('onResizeStart')}
225
- onDrag={this.resizeHandler('onResize')}
180
+ ...children.props.children,
181
+ ...resizeHandles.map((handleAxis) => (
182
+ <DraggableCore
183
+ {...draggableOpts}
184
+ key={`resizableHandle-${handleAxis}`}
185
+ onStop={this.resizeHandler('onResizeStop', handleAxis)}
186
+ onStart={this.resizeHandler('onResizeStart', handleAxis)}
187
+ onDrag={this.resizeHandler('onResize', handleAxis)}
226
188
  >
227
- <span className="react-resizable-handle" />
228
- </DraggableCore>
189
+ {this.renderResizeHandle(handleAxis)}
190
+ </DraggableCore>
191
+ ))
229
192
  ]
230
193
  });
231
194
  }
@@ -1,118 +1,138 @@
1
- 'use strict';
1
+ "use strict";
2
2
 
3
3
  exports.__esModule = true;
4
+ exports.default = void 0;
4
5
 
5
- var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; };
6
+ var React = _interopRequireWildcard(require("react"));
6
7
 
7
- var _react = require('react');
8
+ var _propTypes = _interopRequireDefault(require("prop-types"));
8
9
 
9
- var _react2 = _interopRequireDefault(_react);
10
+ var _Resizable = _interopRequireDefault(require("./Resizable"));
10
11
 
11
- var _propTypes = require('prop-types');
12
+ var _propTypes2 = require("./propTypes");
12
13
 
13
- var _propTypes2 = _interopRequireDefault(_propTypes);
14
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
14
15
 
15
- var _Resizable = require('./Resizable');
16
+ function _getRequireWildcardCache() { if (typeof WeakMap !== "function") return null; var cache = new WeakMap(); _getRequireWildcardCache = function _getRequireWildcardCache() { return cache; }; return cache; }
16
17
 
17
- var _Resizable2 = _interopRequireDefault(_Resizable);
18
+ function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
18
19
 
19
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
20
+ function _extends() { _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
20
21
 
21
- function _objectWithoutProperties(obj, keys) { var target = {}; for (var i in obj) { if (keys.indexOf(i) >= 0) continue; if (!Object.prototype.hasOwnProperty.call(obj, i)) continue; target[i] = obj[i]; } return target; }
22
+ function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; }
22
23
 
23
- function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
24
+ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
24
25
 
25
- function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
26
+ function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }
26
27
 
27
- function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
28
+ function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
28
29
 
29
- // An example use of Resizable.
30
- var ResizableBox = function (_React$Component) {
31
- _inherits(ResizableBox, _React$Component);
30
+ function _inheritsLoose(subClass, superClass) { subClass.prototype = Object.create(superClass.prototype); subClass.prototype.constructor = subClass; subClass.__proto__ = superClass; }
32
31
 
33
- function ResizableBox() {
34
- var _temp, _this, _ret;
32
+ function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
35
33
 
36
- _classCallCheck(this, ResizableBox);
34
+ var ResizableBox = /*#__PURE__*/function (_React$Component) {
35
+ _inheritsLoose(ResizableBox, _React$Component);
37
36
 
38
- for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) {
37
+ function ResizableBox() {
38
+ var _this;
39
+
40
+ for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
39
41
  args[_key] = arguments[_key];
40
42
  }
41
43
 
42
- return _ret = (_temp = (_this = _possibleConstructorReturn(this, _React$Component.call.apply(_React$Component, [this].concat(args))), _this), _this.state = {
44
+ _this = _React$Component.call.apply(_React$Component, [this].concat(args)) || this;
45
+
46
+ _defineProperty(_assertThisInitialized(_this), "state", {
43
47
  width: _this.props.width,
44
- height: _this.props.height
45
- }, _this.onResize = function (e, data) {
46
- var size = data.size;
47
- var width = size.width,
48
- height = size.height;
48
+ height: _this.props.height,
49
+ propsWidth: _this.props.width,
50
+ propsHeight: _this.props.height
51
+ });
49
52
 
53
+ _defineProperty(_assertThisInitialized(_this), "onResize", function (e, data) {
54
+ var size = data.size;
50
55
 
51
56
  if (_this.props.onResize) {
52
57
  e.persist && e.persist();
58
+
53
59
  _this.setState(size, function () {
54
60
  return _this.props.onResize && _this.props.onResize(e, data);
55
61
  });
56
62
  } else {
57
63
  _this.setState(size);
58
64
  }
59
- }, _temp), _possibleConstructorReturn(_this, _ret);
65
+ });
66
+
67
+ return _this;
60
68
  }
61
69
 
62
- ResizableBox.prototype.componentWillReceiveProps = function componentWillReceiveProps(nextProps) {
63
- if (nextProps.width !== this.props.width || nextProps.height !== this.props.height) {
64
- this.setState({
65
- width: nextProps.width,
66
- height: nextProps.height
67
- });
70
+ ResizableBox.getDerivedStateFromProps = function getDerivedStateFromProps(props, state) {
71
+ // If parent changes height/width, set that in our state.
72
+ if (state.propsWidth !== props.width || state.propsHeight !== props.height) {
73
+ return {
74
+ width: props.width,
75
+ height: props.height,
76
+ propsWidth: props.width,
77
+ propsHeight: props.height
78
+ };
68
79
  }
80
+
81
+ return null;
69
82
  };
70
83
 
71
- ResizableBox.prototype.render = function render() {
84
+ var _proto = ResizableBox.prototype;
85
+
86
+ _proto.render = function render() {
72
87
  // Basic wrapper around a Resizable instance.
73
88
  // If you use Resizable directly, you are responsible for updating the child component
74
89
  // with a new width and height.
75
- var _props = this.props,
76
- handleSize = _props.handleSize,
77
- onResize = _props.onResize,
78
- onResizeStart = _props.onResizeStart,
79
- onResizeStop = _props.onResizeStop,
80
- draggableOpts = _props.draggableOpts,
81
- minConstraints = _props.minConstraints,
82
- maxConstraints = _props.maxConstraints,
83
- lockAspectRatio = _props.lockAspectRatio,
84
- axis = _props.axis,
85
- width = _props.width,
86
- height = _props.height,
87
- props = _objectWithoutProperties(_props, ['handleSize', 'onResize', 'onResizeStart', 'onResizeStop', 'draggableOpts', 'minConstraints', 'maxConstraints', 'lockAspectRatio', 'axis', 'width', 'height']);
88
-
89
- return _react2.default.createElement(
90
- _Resizable2.default,
91
- {
92
- handleSize: handleSize,
93
- width: this.state.width,
94
- height: this.state.height,
95
- onResizeStart: onResizeStart,
96
- onResize: this.onResize,
97
- onResizeStop: onResizeStop,
98
- draggableOpts: draggableOpts,
99
- minConstraints: minConstraints,
100
- maxConstraints: maxConstraints,
101
- lockAspectRatio: lockAspectRatio,
102
- axis: axis
103
- },
104
- _react2.default.createElement('div', _extends({ style: { width: this.state.width + 'px', height: this.state.height + 'px' } }, props))
105
- );
90
+ var _this$props = this.props,
91
+ handle = _this$props.handle,
92
+ handleSize = _this$props.handleSize,
93
+ onResize = _this$props.onResize,
94
+ onResizeStart = _this$props.onResizeStart,
95
+ onResizeStop = _this$props.onResizeStop,
96
+ draggableOpts = _this$props.draggableOpts,
97
+ minConstraints = _this$props.minConstraints,
98
+ maxConstraints = _this$props.maxConstraints,
99
+ lockAspectRatio = _this$props.lockAspectRatio,
100
+ axis = _this$props.axis,
101
+ width = _this$props.width,
102
+ height = _this$props.height,
103
+ resizeHandles = _this$props.resizeHandles,
104
+ style = _this$props.style,
105
+ transformScale = _this$props.transformScale,
106
+ props = _objectWithoutPropertiesLoose(_this$props, ["handle", "handleSize", "onResize", "onResizeStart", "onResizeStop", "draggableOpts", "minConstraints", "maxConstraints", "lockAspectRatio", "axis", "width", "height", "resizeHandles", "style", "transformScale"]);
107
+
108
+ return /*#__PURE__*/React.createElement(_Resizable.default, {
109
+ axis: axis,
110
+ draggableOpts: draggableOpts,
111
+ handle: handle,
112
+ handleSize: handleSize,
113
+ height: this.state.height,
114
+ lockAspectRatio: lockAspectRatio,
115
+ maxConstraints: maxConstraints,
116
+ minConstraints: minConstraints,
117
+ onResizeStart: onResizeStart,
118
+ onResize: this.onResize,
119
+ onResizeStop: onResizeStop,
120
+ resizeHandles: resizeHandles,
121
+ transformScale: transformScale,
122
+ width: this.state.width
123
+ }, /*#__PURE__*/React.createElement("div", _extends({}, props, {
124
+ style: _objectSpread(_objectSpread({}, style), {}, {
125
+ width: this.state.width + 'px',
126
+ height: this.state.height + 'px'
127
+ })
128
+ })));
106
129
  };
107
130
 
108
131
  return ResizableBox;
109
- }(_react2.default.Component);
110
-
111
- ResizableBox.propTypes = {
112
- height: _propTypes2.default.number,
113
- width: _propTypes2.default.number
114
- };
115
- ResizableBox.defaultProps = {
116
- handleSize: [20, 20]
117
- };
118
- exports.default = ResizableBox;
132
+ }(React.Component);
133
+
134
+ exports.default = ResizableBox;
135
+
136
+ _defineProperty(ResizableBox, "propTypes", _objectSpread(_objectSpread({}, _propTypes2.resizableProps), {}, {
137
+ children: _propTypes.default.element
138
+ }));