react-resizable 3.0.0 → 3.0.4

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.
package/.eslintrc CHANGED
@@ -5,7 +5,8 @@
5
5
  "react"
6
6
  ],
7
7
  "extends": [
8
- "eslint:recommended"
8
+ "eslint:recommended",
9
+ "plugin:jest/recommended"
9
10
  ],
10
11
  "rules": {
11
12
  "strict": 0,
package/.flowconfig CHANGED
@@ -1,5 +1,5 @@
1
1
  [version]
2
- ^0.150.1
2
+ ^0.153.0
3
3
 
4
4
  [ignore]
5
5
  .*/node_modules/@babel.*
package/CHANGELOG.md CHANGED
@@ -1,16 +1,36 @@
1
1
  # Changelog
2
2
 
3
+ ### 3.0.4 (Jun 15, 2021)
4
+
5
+ - 🐛 Bugfix: Fix incorrect fix for `handleAxis` on DOM elements. [#175](https://github.com/react-grid-layout/react-resizable/issues/175)
6
+ - ✏ Chore:Upgrade dependencies.
7
+
8
+ ### 3.0.3 (Jun 14, 2021)
9
+
10
+ - 🐛 Bugfix: Remove unknown prop `handleAxis` making it to DOM elements, causing a warning in dev.
11
+ - ✏ Chore:Rewrote `lockAspectRatio` logic to be more accurate and shorter.
12
+
13
+ ### 3.0.2 (Jun 8, 2021)
14
+
15
+ - ✏ Chore:Add documentation for resize handles and fix a mistake where the `handleAxis` prop was not being passed to custom components.
16
+ - See [Resize Handles](README.md#resize-handle)
17
+
18
+ ### 3.0.1 (May 10, 2021)
19
+
20
+ - ✏ Chore:Reduce package size through `.npmignore`.
21
+
3
22
  ### 3.0.0 (May 10, 2021)
4
23
 
5
24
  #### Breaking
6
- - Fixed handling of the `nodeRef` that needs to be passed to `<DraggableCore>` to avoid use of ReactDOM. This means that vanilla usage of `react-resizable` no longer requires ReactDOM. No code changes are needed in the usual case, except:
25
+
26
+ - 🐛 Bugfix: Fixed handling of the `nodeRef` that needs to be passed to `<DraggableCore>` to avoid use of ReactDOM. This means that vanilla usage of `react-resizable` no longer requires ReactDOM. No code changes are needed in the usual case, except:
7
27
  * React `>= 16.3` is required due to use of `React.createRef()`, and
8
28
  * The `handle` prop now sends a `ReactRef<HTMLElement>` as its second argument and expects it to be used on your returned component.
9
29
  * If you do not attach the `ref`, you will receive the following error: `"<DraggableCore> not mounted on DragStart!"` This is due to the ref being present but not attached to any node.
10
30
 
11
31
  ### 1.11.1 (Mar 5, 2021)
12
32
 
13
- - Added React 17 to peerDependencies.
33
+ - ✏ Chore: Added React 17 to peerDependencies.
14
34
 
15
35
  ### 1.11.0 (Sep 3, 2020)
16
36
 
package/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  ### React-Resizable
2
2
 
3
- [View the Demo](https://react-grid-layout.github.io/react-resizable/examples/1.html)
3
+ [View the Demo](https://react-grid-layout.github.io/react-resizable/index.html)
4
4
 
5
5
  A simple widget that can be resized via one or more handles.
6
6
 
@@ -115,7 +115,7 @@ type ResizableProps =
115
115
  onResizeStart?: ?(e: SyntheticEvent, data: ResizeCallbackData) => any,
116
116
  onResize?: ?(e: SyntheticEvent, data: ResizeCallbackData) => any,
117
117
  draggableOpts?: ?Object,
118
- resizeHandles?: ?Array<'s' | 'w' | 'e' | 'n' | 'sw' | 'nw' | 'se' | 'ne'> = ['se']
118
+ resizeHandles?: ?Array<ResizeHandleAxis> = ['se']
119
119
  };
120
120
  ```
121
121
 
@@ -127,4 +127,61 @@ The following props can also be used on `<ResizableBox>`:
127
127
  }
128
128
  ```
129
129
 
130
- If a `width` or `height` is passed to `<ResizableBox>`'s `style` prop, it will be ignored as it is required for internal function.
130
+ If a `width` or `height` is passed to `<ResizableBox>`'s `style` prop, it will be ignored as it is required for internal function.
131
+
132
+ #### Resize Handle
133
+
134
+ If you override the resize handle, we expect that any `ref` passed to your new handle with represent the underlying DOM element.
135
+
136
+ This is required, as `react-resizable` must be able to access the underlying DOM node to attach handlers and measure position deltas.
137
+
138
+ There are a few ways to do this:
139
+
140
+ ##### Native DOM Element
141
+
142
+ This requires no special treatment.
143
+
144
+ ```js
145
+ <Resizable handle={<div className="foo" />} />
146
+ ```
147
+
148
+ ##### Custom React Component
149
+
150
+ You must [forward the ref](https://reactjs.org/docs/forwarding-refs.html) and props to the underlying DOM element.
151
+
152
+ ###### Class Components
153
+
154
+ ```js
155
+ class MyHandleComponent extends React.Component {
156
+ render() {
157
+ const {handleAxis, innerRef, ...props} = this.props;
158
+ return <div ref={innerRef} className={`foo handle-${handleAxis}`} {...props} />
159
+ }
160
+ }
161
+ const MyHandle = React.forwardRef((props, ref) => <MyHandleComponent innerRef={ref} {...props} />);
162
+
163
+ <Resizable handle={<MyHandle />} />
164
+ ```
165
+
166
+ ###### Functional Components
167
+
168
+ ```js
169
+ const MyHandle = React.forwardRef((props, ref) => {
170
+ const {handleAxis, ...restProps} = props;
171
+ return <div ref={ref} className={`foo handle-${handleAxis}`} {...restProps} />;
172
+ });
173
+
174
+ <Resizable handle={<MyHandle />} />
175
+ ```
176
+
177
+ ##### Custom Function
178
+
179
+ You can define a function as a handle, which will simply receive an axis (see above `ResizeHandleAxis` type) and ref. This may be more clear to read, depending on your coding style.
180
+
181
+ ```js
182
+ const MyHandle = (props) => {
183
+ return <div ref={props.innerRef} className="foo" {...props} />;
184
+ };
185
+
186
+ <Resizable handle={(handleAxis, ref) => <MyHandle innerRef={ref} className={`foo handle-${handleAxis}`} {...props} />} />
187
+ ```
@@ -11,20 +11,22 @@ var _utils = require("./utils");
11
11
 
12
12
  var _propTypes = require("./propTypes");
13
13
 
14
+ var _excluded = ["children", "className", "draggableOpts", "width", "height", "handle", "handleSize", "lockAspectRatio", "axis", "minConstraints", "maxConstraints", "onResize", "onResizeStop", "onResizeStart", "resizeHandles", "transformScale"];
15
+
14
16
  function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
15
17
 
16
18
  function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && 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; }
17
19
 
18
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); }
19
21
 
22
+ 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; }
23
+
20
24
  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; }
21
25
 
22
26
  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; }
23
27
 
24
28
  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; }
25
29
 
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; }
27
-
28
30
  function _inheritsLoose(subClass, superClass) { subClass.prototype = Object.create(superClass.prototype); subClass.prototype.constructor = subClass; _setPrototypeOf(subClass, superClass); }
29
31
 
30
32
  function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
@@ -54,37 +56,31 @@ var Resizable = /*#__PURE__*/function (_React$Component) {
54
56
  this.resetData();
55
57
  };
56
58
 
57
- _proto.lockAspectRatio = function lockAspectRatio(width, height, aspectRatio) {
58
- height = width / aspectRatio;
59
- width = height * aspectRatio;
60
- return [width, height];
61
- };
62
-
63
59
  _proto.resetData = function resetData() {
64
60
  this.lastHandleRect = this.slack = null;
65
61
  } // Clamp width and height within provided constraints
66
62
  ;
67
63
 
68
64
  _proto.runConstraints = function runConstraints(width, height) {
69
- var _ref = [this.props.minConstraints, this.props.maxConstraints],
70
- min = _ref[0],
71
- max = _ref[1];
72
- if (!min && !max) return [width, height]; // If constraining to min and max, we need to also fit width and height to aspect ratio.
65
+ var _this$props = this.props,
66
+ minConstraints = _this$props.minConstraints,
67
+ maxConstraints = _this$props.maxConstraints,
68
+ lockAspectRatio = _this$props.lockAspectRatio; // short circuit
69
+
70
+ if (!minConstraints && !maxConstraints && !lockAspectRatio) return [width, height]; // If constraining to min and max, we need to also fit width and height to aspect ratio.
73
71
 
74
- if (this.props.lockAspectRatio) {
75
- var resizingHorizontally = height === this.props.height;
72
+ if (lockAspectRatio) {
73
+ var ratio = this.props.width / this.props.height;
74
+ var deltaW = width - this.props.width;
75
+ var deltaH = height - this.props.height; // Find which coordinate was greater and should push the other toward it.
76
+ // E.g.:
77
+ // ratio = 1, deltaW = 10, deltaH = 5, deltaH should become 10.
78
+ // ratio = 2, deltaW = 10, deltaH = 6, deltaW should become 12.
76
79
 
77
- if (resizingHorizontally) {
78
- var ratio = this.props.width / this.props.height;
80
+ if (Math.abs(deltaW) > Math.abs(deltaH * ratio)) {
79
81
  height = width / ratio;
80
- width = height * ratio;
81
82
  } else {
82
- // Take into account vertical resize with N/S handles on locked aspect
83
- // ratio. Calculate the change height-first, instead of width-first
84
- var _ratio = this.props.height / this.props.width;
85
-
86
- width = height / _ratio;
87
- height = width * _ratio;
83
+ width = height * ratio;
88
84
  }
89
85
  }
90
86
 
@@ -93,21 +89,21 @@ var Resizable = /*#__PURE__*/function (_React$Component) {
93
89
  // we start removing slack, the element won't react to it right away until it's been
94
90
  // completely removed.
95
91
 
96
- var _ref2 = this.slack || [0, 0],
97
- slackW = _ref2[0],
98
- slackH = _ref2[1];
92
+ var _ref = this.slack || [0, 0],
93
+ slackW = _ref[0],
94
+ slackH = _ref[1];
99
95
 
100
96
  width += slackW;
101
97
  height += slackH;
102
98
 
103
- if (min) {
104
- width = Math.max(min[0], width);
105
- height = Math.max(min[1], height);
99
+ if (minConstraints) {
100
+ width = Math.max(minConstraints[0], width);
101
+ height = Math.max(minConstraints[1], height);
106
102
  }
107
103
 
108
- if (max) {
109
- width = Math.min(max[0], width);
110
- height = Math.min(max[1], height);
104
+ if (maxConstraints) {
105
+ width = Math.min(maxConstraints[0], width);
106
+ height = Math.min(maxConstraints[1], height);
111
107
  } // If the width or height changed, we must have introduced some slack. Record it for the next iteration.
112
108
 
113
109
 
@@ -125,10 +121,10 @@ var Resizable = /*#__PURE__*/function (_React$Component) {
125
121
  _proto.resizeHandler = function resizeHandler(handlerName, axis) {
126
122
  var _this2 = this;
127
123
 
128
- return function (e, _ref3) {
129
- var node = _ref3.node,
130
- deltaX = _ref3.deltaX,
131
- deltaY = _ref3.deltaY;
124
+ return function (e, _ref2) {
125
+ var node = _ref2.node,
126
+ deltaX = _ref2.deltaX,
127
+ deltaY = _ref2.deltaY;
132
128
  // Reset data in case it was left over somehow (should not be possible)
133
129
  if (handlerName === 'onResizeStart') _this2.resetData(); // Axis restrictions
134
130
 
@@ -180,7 +176,7 @@ var Resizable = /*#__PURE__*/function (_React$Component) {
180
176
  var shouldSkipCb = handlerName === 'onResize' && !dimensionsChanged;
181
177
 
182
178
  if (cb && !shouldSkipCb) {
183
- if (typeof e.persist === 'function') e.persist();
179
+ e.persist == null ? void 0 : e.persist();
184
180
  cb(e, {
185
181
  node: node,
186
182
  size: {
@@ -194,26 +190,36 @@ var Resizable = /*#__PURE__*/function (_React$Component) {
194
190
 
195
191
  if (handlerName === 'onResizeStop') _this2.resetData();
196
192
  };
197
- } // Render a resize handle given an axis & DOM ref.
193
+ } // Render a resize handle given an axis & DOM ref. Ref *must* be attached for
194
+ // the underlying draggable library to work properly.
198
195
  ;
199
196
 
200
197
  _proto.renderResizeHandle = function renderResizeHandle(handleAxis, ref) {
201
- var handle = this.props.handle;
202
-
203
- if (handle) {
204
- if (typeof handle === 'function') {
205
- return handle(handleAxis, ref);
206
- }
198
+ var handle = this.props.handle; // No handle provided, make the default
207
199
 
208
- return /*#__PURE__*/React.cloneElement(handle, {
200
+ if (!handle) {
201
+ return /*#__PURE__*/React.createElement("span", {
202
+ className: "react-resizable-handle react-resizable-handle-" + handleAxis,
209
203
  ref: ref
210
204
  });
211
- }
205
+ } // Handle is a function, such as:
206
+ // `handle={(handleAxis) => <span className={...} />}`
207
+
208
+
209
+ if (typeof handle === 'function') {
210
+ return handle(handleAxis, ref);
211
+ } // Handle is a React component (composite or DOM).
212
212
 
213
- return /*#__PURE__*/React.createElement("span", {
214
- className: "react-resizable-handle react-resizable-handle-" + handleAxis,
213
+
214
+ var isDOMElement = typeof handle.type === 'string';
215
+
216
+ var props = _objectSpread({
215
217
  ref: ref
218
+ }, isDOMElement ? {} : {
219
+ handleAxis: handleAxis
216
220
  });
221
+
222
+ return /*#__PURE__*/React.cloneElement(handle, props);
217
223
  };
218
224
 
219
225
  _proto.render = function render() {
@@ -221,27 +227,27 @@ var Resizable = /*#__PURE__*/function (_React$Component) {
221
227
 
222
228
  // Pass along only props not meant for the `<Resizable>`.`
223
229
  // eslint-disable-next-line no-unused-vars
224
- var _this$props = this.props,
225
- children = _this$props.children,
226
- className = _this$props.className,
227
- draggableOpts = _this$props.draggableOpts,
228
- width = _this$props.width,
229
- height = _this$props.height,
230
- handle = _this$props.handle,
231
- handleSize = _this$props.handleSize,
232
- lockAspectRatio = _this$props.lockAspectRatio,
233
- axis = _this$props.axis,
234
- minConstraints = _this$props.minConstraints,
235
- maxConstraints = _this$props.maxConstraints,
236
- onResize = _this$props.onResize,
237
- onResizeStop = _this$props.onResizeStop,
238
- onResizeStart = _this$props.onResizeStart,
239
- resizeHandles = _this$props.resizeHandles,
240
- transformScale = _this$props.transformScale,
241
- p = _objectWithoutPropertiesLoose(_this$props, ["children", "className", "draggableOpts", "width", "height", "handle", "handleSize", "lockAspectRatio", "axis", "minConstraints", "maxConstraints", "onResize", "onResizeStop", "onResizeStart", "resizeHandles", "transformScale"]); // What we're doing here is getting the child of this element, and cloning it with this element's props.
230
+ var _this$props2 = this.props,
231
+ children = _this$props2.children,
232
+ className = _this$props2.className,
233
+ draggableOpts = _this$props2.draggableOpts,
234
+ width = _this$props2.width,
235
+ height = _this$props2.height,
236
+ handle = _this$props2.handle,
237
+ handleSize = _this$props2.handleSize,
238
+ lockAspectRatio = _this$props2.lockAspectRatio,
239
+ axis = _this$props2.axis,
240
+ minConstraints = _this$props2.minConstraints,
241
+ maxConstraints = _this$props2.maxConstraints,
242
+ onResize = _this$props2.onResize,
243
+ onResizeStop = _this$props2.onResizeStop,
244
+ onResizeStart = _this$props2.onResizeStart,
245
+ resizeHandles = _this$props2.resizeHandles,
246
+ transformScale = _this$props2.transformScale,
247
+ p = _objectWithoutPropertiesLoose(_this$props2, _excluded); // What we're doing here is getting the child of this element, and cloning it with this element's props.
242
248
  // We are then defining its children as:
243
- // Its original children (resizable's child's children), and
244
- // One or more draggable handles.
249
+ // 1. Its original children (resizable's child's children), and
250
+ // 2. One or more draggable handles.
245
251
 
246
252
 
247
253
  return (0, _utils.cloneElement)(children, _objectSpread(_objectSpread({}, p), {}, {
@@ -29,34 +29,30 @@ export default class Resizable extends React.Component<Props, void> {
29
29
  this.resetData();
30
30
  }
31
31
 
32
- lockAspectRatio(width: number, height: number, aspectRatio: number): [number, number] {
33
- height = width / aspectRatio;
34
- width = height * aspectRatio;
35
- return [width, height];
36
- }
37
-
38
32
  resetData() {
39
33
  this.lastHandleRect = this.slack = null;
40
34
  }
41
35
 
42
36
  // Clamp width and height within provided constraints
43
37
  runConstraints(width: number, height: number): [number, number] {
44
- const [min, max] = [this.props.minConstraints, this.props.maxConstraints];
45
- if (!min && !max) return [width, height];
38
+ const {minConstraints, maxConstraints, lockAspectRatio} = this.props;
39
+ // short circuit
40
+ if (!minConstraints && !maxConstraints && !lockAspectRatio) return [width, height];
46
41
 
47
42
  // If constraining to min and max, we need to also fit width and height to aspect ratio.
48
- if (this.props.lockAspectRatio) {
49
- const resizingHorizontally = height === this.props.height;
50
- if (resizingHorizontally) {
51
- const ratio = this.props.width / this.props.height;
43
+ if (lockAspectRatio) {
44
+ const ratio = this.props.width / this.props.height;
45
+ const deltaW = width - this.props.width;
46
+ const deltaH = height - this.props.height;
47
+
48
+ // Find which coordinate was greater and should push the other toward it.
49
+ // E.g.:
50
+ // ratio = 1, deltaW = 10, deltaH = 5, deltaH should become 10.
51
+ // ratio = 2, deltaW = 10, deltaH = 6, deltaW should become 12.
52
+ if (Math.abs(deltaW) > Math.abs(deltaH * ratio)) {
52
53
  height = width / ratio;
53
- width = height * ratio;
54
54
  } else {
55
- // Take into account vertical resize with N/S handles on locked aspect
56
- // ratio. Calculate the change height-first, instead of width-first
57
- const ratio = this.props.height / this.props.width;
58
- width = height / ratio;
59
- height = width * ratio;
55
+ width = height * ratio;
60
56
  }
61
57
  }
62
58
 
@@ -69,13 +65,13 @@ export default class Resizable extends React.Component<Props, void> {
69
65
  width += slackW;
70
66
  height += slackH;
71
67
 
72
- if (min) {
73
- width = Math.max(min[0], width);
74
- height = Math.max(min[1], height);
68
+ if (minConstraints) {
69
+ width = Math.max(minConstraints[0], width);
70
+ height = Math.max(minConstraints[1], height);
75
71
  }
76
- if (max) {
77
- width = Math.min(max[0], width);
78
- height = Math.min(max[1], height);
72
+ if (maxConstraints) {
73
+ width = Math.min(maxConstraints[0], width);
74
+ height = Math.min(maxConstraints[1], height);
79
75
  }
80
76
 
81
77
  // If the width or height changed, we must have introduced some slack. Record it for the next iteration.
@@ -143,7 +139,7 @@ export default class Resizable extends React.Component<Props, void> {
143
139
  // Don't call 'onResize' if dimensions haven't changed.
144
140
  const shouldSkipCb = handlerName === 'onResize' && !dimensionsChanged;
145
141
  if (cb && !shouldSkipCb) {
146
- if (typeof e.persist === 'function') e.persist();
142
+ e.persist?.();
147
143
  cb(e, {node, size: {width, height}, handle: axis});
148
144
  }
149
145
 
@@ -152,16 +148,29 @@ export default class Resizable extends React.Component<Props, void> {
152
148
  };
153
149
  }
154
150
 
155
- // Render a resize handle given an axis & DOM ref.
151
+ // Render a resize handle given an axis & DOM ref. Ref *must* be attached for
152
+ // the underlying draggable library to work properly.
156
153
  renderResizeHandle(handleAxis: ResizeHandleAxis, ref: ReactRef<HTMLElement>): ReactNode {
157
154
  const {handle} = this.props;
158
- if (handle) {
159
- if (typeof handle === 'function') {
160
- return handle(handleAxis, ref);
161
- }
162
- return React.cloneElement(handle, {ref});
155
+ // No handle provided, make the default
156
+ if (!handle) {
157
+ return <span className={`react-resizable-handle react-resizable-handle-${handleAxis}`} ref={ref} />;
158
+ }
159
+ // Handle is a function, such as:
160
+ // `handle={(handleAxis) => <span className={...} />}`
161
+ if (typeof handle === 'function') {
162
+ return handle(handleAxis, ref);
163
163
  }
164
- return <span className={`react-resizable-handle react-resizable-handle-${handleAxis}`} ref={ref} />;
164
+ // Handle is a React component (composite or DOM).
165
+ const isDOMElement = typeof handle.type === 'string';
166
+ const props = {
167
+ ref,
168
+ // Add `handleAxis` prop iff this is not a DOM element,
169
+ // otherwise we'll get an unknown property warning
170
+ ...(isDOMElement ? {} : {handleAxis})
171
+ };
172
+ return React.cloneElement(handle, props);
173
+
165
174
  }
166
175
 
167
176
  render(): ReactNode {
@@ -173,8 +182,8 @@ export default class Resizable extends React.Component<Props, void> {
173
182
 
174
183
  // What we're doing here is getting the child of this element, and cloning it with this element's props.
175
184
  // We are then defining its children as:
176
- // Its original children (resizable's child's children), and
177
- // One or more draggable handles.
185
+ // 1. Its original children (resizable's child's children), and
186
+ // 2. One or more draggable handles.
178
187
  return cloneElement(children, {
179
188
  ...p,
180
189
  className: `${className ? `${className} ` : ''}react-resizable`,
@@ -11,6 +11,8 @@ var _Resizable = _interopRequireDefault(require("./Resizable"));
11
11
 
12
12
  var _propTypes2 = require("./propTypes");
13
13
 
14
+ var _excluded = ["handle", "handleSize", "onResize", "onResizeStart", "onResizeStop", "draggableOpts", "minConstraints", "maxConstraints", "lockAspectRatio", "axis", "width", "height", "resizeHandles", "style", "transformScale"];
15
+
14
16
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
15
17
 
16
18
  function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
@@ -53,7 +55,7 @@ var ResizableBox = /*#__PURE__*/function (_React$Component) {
53
55
  var size = data.size;
54
56
 
55
57
  if (_this.props.onResize) {
56
- e.persist && e.persist();
58
+ e.persist == null ? void 0 : e.persist();
57
59
 
58
60
  _this.setState(size, function () {
59
61
  return _this.props.onResize && _this.props.onResize(e, data);
@@ -102,7 +104,7 @@ var ResizableBox = /*#__PURE__*/function (_React$Component) {
102
104
  resizeHandles = _this$props.resizeHandles,
103
105
  style = _this$props.style,
104
106
  transformScale = _this$props.transformScale,
105
- props = _objectWithoutPropertiesLoose(_this$props, ["handle", "handleSize", "onResize", "onResizeStart", "onResizeStop", "draggableOpts", "minConstraints", "maxConstraints", "lockAspectRatio", "axis", "width", "height", "resizeHandles", "style", "transformScale"]);
107
+ props = _objectWithoutPropertiesLoose(_this$props, _excluded);
106
108
 
107
109
  return /*#__PURE__*/React.createElement(_Resizable.default, {
108
110
  axis: axis,
@@ -44,7 +44,7 @@ export default class ResizableBox extends React.Component<ResizableBoxProps, Res
44
44
  onResize: (e: SyntheticEvent<>, data: ResizeCallbackData) => void = (e, data) => {
45
45
  const {size} = data;
46
46
  if (this.props.onResize) {
47
- e.persist && e.persist();
47
+ e.persist?.();
48
48
  this.setState(size, () => this.props.onResize && this.props.onResize(e, data));
49
49
  } else {
50
50
  this.setState(size);