react-resizable 1.7.4 → 1.10.1

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.
@@ -2,14 +2,13 @@
2
2
  import React from 'react';
3
3
  import PropTypes from 'prop-types';
4
4
  import {DraggableCore} from 'react-draggable';
5
- import cloneElement from './cloneElement';
5
+ import {cloneElement} from './utils';
6
6
  import type {Element as ReactElement, Node as ReactNode} from 'react';
7
7
 
8
8
  type Axis = 'both' | 'x' | 'y' | 'none';
9
+ type ResizeHandle = 's' | 'w' | 'e' | 'n' | 'sw' | 'nw' | 'se' | 'ne';
9
10
  type State = {
10
- resizing: boolean,
11
- width: number, height: number,
12
- slackW: number, slackH: number
11
+ slackW: number, slackH: number,
13
12
  };
14
13
  type DragCallbackData = {
15
14
  node: HTMLElement,
@@ -19,13 +18,15 @@ type DragCallbackData = {
19
18
  };
20
19
  export type ResizeCallbackData = {
21
20
  node: HTMLElement,
22
- size: {width: number, height: number}
21
+ size: {width: number, height: number},
22
+ handle: ResizeHandle
23
23
  };
24
24
  export type Props = {
25
25
  children: ReactElement<any>,
26
26
  className?: ?string,
27
27
  width: number,
28
28
  height: number,
29
+ handle: ReactElement<any> | (resizeHandle: ResizeHandle) => ReactElement<any>,
29
30
  handleSize: [number, number],
30
31
  lockAspectRatio: boolean,
31
32
  axis: Axis,
@@ -34,7 +35,9 @@ export type Props = {
34
35
  onResizeStop?: ?(e: SyntheticEvent<>, data: ResizeCallbackData) => any,
35
36
  onResizeStart?: ?(e: SyntheticEvent<>, data: ResizeCallbackData) => any,
36
37
  onResize?: ?(e: SyntheticEvent<>, data: ResizeCallbackData) => any,
37
- draggableOpts?: ?Object
38
+ draggableOpts?: ?Object,
39
+ resizeHandles: ResizeHandle[],
40
+ transformScale: number,
38
41
  };
39
42
 
40
43
  export default class Resizable extends React.Component<Props, State> {
@@ -54,9 +57,25 @@ export default class Resizable extends React.Component<Props, State> {
54
57
  // Optional props
55
58
  //
56
59
 
60
+ // Custom resize handle
61
+ handle: PropTypes.element,
62
+
57
63
  // If you change this, be sure to update your css
58
64
  handleSize: PropTypes.array,
59
65
 
66
+ // Defines which resize handles should be rendered (default: 'se')
67
+ // Allows for any combination of:
68
+ // 's' - South handle (bottom-center)
69
+ // 'w' - West handle (left-center)
70
+ // 'e' - East handle (right-center)
71
+ // 'n' - North handle (top-center)
72
+ // 'sw' - Southwest handle (bottom-left)
73
+ // 'nw' - Northwest handle (top-left)
74
+ // 'se' - Southeast handle (bottom-right)
75
+ // 'ne' - Northeast handle (top-center)
76
+ resizeHandles: PropTypes.arrayOf(PropTypes.oneOf(['s', 'w', 'e', 'n', 'sw', 'nw', 'se', 'ne'])),
77
+ transformScale: PropTypes.number,
78
+
60
79
  // If true, will only allow width/height to move in lockstep
61
80
  lockAspectRatio: PropTypes.bool,
62
81
 
@@ -85,26 +104,15 @@ export default class Resizable extends React.Component<Props, State> {
85
104
  lockAspectRatio: false,
86
105
  axis: 'both',
87
106
  minConstraints: [20, 20],
88
- maxConstraints: [Infinity, Infinity]
107
+ maxConstraints: [Infinity, Infinity],
108
+ resizeHandles: ['se'],
109
+ transformScale: 1
89
110
  };
90
111
 
91
112
  state: State = {
92
- resizing: false,
93
- width: this.props.width, height: this.props.height,
94
113
  slackW: 0, slackH: 0
95
114
  };
96
115
 
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
- }
106
- }
107
-
108
116
  lockAspectRatio(width: number, height: number, aspectRatio: number): [number, number] {
109
117
  height = width / aspectRatio;
110
118
  width = height * aspectRatio;
@@ -114,15 +122,23 @@ export default class Resizable extends React.Component<Props, State> {
114
122
  // If you do this, be careful of constraints
115
123
  runConstraints(width: number, height: number): [number, number] {
116
124
  const [min, max] = [this.props.minConstraints, this.props.maxConstraints];
125
+ if (!min && !max) return [width, height];
117
126
 
127
+ // Fit width & height to aspect ratio
118
128
  if (this.props.lockAspectRatio) {
119
- const ratio = this.state.width / this.state.height;
120
- height = width / ratio;
121
- width = height * ratio;
129
+ if (height === this.props.height) {
130
+ const ratio = this.props.width / this.props.height;
131
+ height = width / ratio;
132
+ width = height * ratio;
133
+ } else {
134
+ // Take into account vertical resize with N/S handles on locked aspect
135
+ // ratio. Calculate the change height-first, instead of width-first
136
+ const ratio = this.props.height / this.props.width;
137
+ width = height / ratio;
138
+ height = width * ratio;
139
+ }
122
140
  }
123
141
 
124
- if (!min && !max) return [width, height];
125
-
126
142
  const [oldW, oldH] = [width, height];
127
143
 
128
144
  // Add slack to the values used to calculate bound position. This will ensure that if
@@ -157,19 +173,29 @@ export default class Resizable extends React.Component<Props, State> {
157
173
  * @param {String} handlerName Handler name to wrap.
158
174
  * @return {Function} Handler function.
159
175
  */
160
- resizeHandler(handlerName: string): Function {
176
+ resizeHandler(handlerName: string, axis: ResizeHandle): Function {
161
177
  return (e: SyntheticEvent<> | MouseEvent, {node, deltaX, deltaY}: DragCallbackData) => {
178
+ deltaX /= this.props.transformScale;
179
+ deltaY /= this.props.transformScale;
162
180
 
163
181
  // Axis restrictions
164
- const canDragX = this.props.axis === 'both' || this.props.axis === 'x';
165
- const canDragY = this.props.axis === 'both' || this.props.axis === 'y';
182
+ const canDragX = (this.props.axis === 'both' || this.props.axis === 'x') && ['n', 's'].indexOf(axis) === -1;
183
+ const canDragY = (this.props.axis === 'both' || this.props.axis === 'y') && ['e', 'w'].indexOf(axis) === -1;
184
+
185
+ // reverse delta if using top or left drag handles
186
+ if (canDragX && axis[axis.length - 1] === 'w') {
187
+ deltaX = -deltaX;
188
+ }
189
+ if (canDragY && axis[0] === 'n') {
190
+ deltaY = -deltaY;
191
+ }
166
192
 
167
193
  // Update w/h
168
- let width = this.state.width + (canDragX ? deltaX : 0);
169
- let height = this.state.height + (canDragY ? deltaY : 0);
194
+ let width = this.props.width + (canDragX ? deltaX : 0);
195
+ let height = this.props.height + (canDragY ? deltaY : 0);
170
196
 
171
197
  // Early return if no change
172
- const widthChanged = width !== this.state.width, heightChanged = height !== this.state.height;
198
+ const widthChanged = width !== this.props.width, heightChanged = height !== this.props.height;
173
199
  if (handlerName === 'onResize' && !widthChanged && !heightChanged) return;
174
200
 
175
201
  [width, height] = this.runConstraints(width, height);
@@ -177,32 +203,41 @@ export default class Resizable extends React.Component<Props, State> {
177
203
  // Set the appropriate state for this handler.
178
204
  const newState = {};
179
205
  if (handlerName === 'onResizeStart') {
180
- newState.resizing = true;
206
+ // nothing
181
207
  } else if (handlerName === 'onResizeStop') {
182
- newState.resizing = false;
183
208
  newState.slackW = newState.slackH = 0;
184
209
  } else {
185
210
  // 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;
211
+ if (width === this.props.width && height === this.props.height) return;
189
212
  }
190
213
 
191
214
  const hasCb = typeof this.props[handlerName] === 'function';
192
215
  if (hasCb) {
216
+ // $FlowIgnore isn't refining this correctly to SyntheticEvent
193
217
  if (typeof e.persist === 'function') e.persist();
194
- this.setState(newState, () => this.props[handlerName](e, {node, size: {width, height}}));
218
+ this.setState(newState, () => this.props[handlerName](e, {node, size: {width, height}, handle: axis}));
195
219
  } else {
196
220
  this.setState(newState);
197
221
  }
198
222
  };
199
223
  }
200
224
 
225
+ renderResizeHandle(resizeHandle: ResizeHandle): ReactNode {
226
+ const {handle} = this.props;
227
+ if (handle) {
228
+ if (typeof handle === 'function') {
229
+ return handle(resizeHandle);
230
+ }
231
+ return handle;
232
+ }
233
+ return <span className={`react-resizable-handle react-resizable-handle-${resizeHandle}`} />;
234
+ }
235
+
201
236
  render(): ReactNode {
202
237
  // eslint-disable-next-line no-unused-vars
203
238
  const {children, draggableOpts, width, height, handleSize,
204
239
  lockAspectRatio, axis, minConstraints, maxConstraints, onResize,
205
- onResizeStop, onResizeStart, ...p} = this.props;
240
+ onResizeStop, onResizeStart, resizeHandles, transformScale, ...p} = this.props;
206
241
 
207
242
  const className = p.className ?
208
243
  `${p.className} react-resizable`:
@@ -211,21 +246,23 @@ export default class Resizable extends React.Component<Props, State> {
211
246
  // What we're doing here is getting the child of this element, and cloning it with this element's props.
212
247
  // We are then defining its children as:
213
248
  // Its original children (resizable's child's children), and
214
- // A draggable handle.
249
+ // One or more draggable handles.
215
250
  return cloneElement(children, {
216
251
  ...p,
217
252
  className,
218
253
  children: [
219
254
  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')}
255
+ resizeHandles.map(h => (
256
+ <DraggableCore
257
+ {...draggableOpts}
258
+ key={`resizableHandle-${h}`}
259
+ onStop={this.resizeHandler('onResizeStop', h)}
260
+ onStart={this.resizeHandler('onResizeStart', h)}
261
+ onDrag={this.resizeHandler('onResize', h)}
226
262
  >
227
- <span className="react-resizable-handle" />
228
- </DraggableCore>
263
+ {this.renderResizeHandle(h)}
264
+ </DraggableCore>
265
+ ))
229
266
  ]
230
267
  });
231
268
  }
@@ -1,118 +1,135 @@
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 = _interopRequireDefault(require("react"));
6
7
 
7
- var _react = require('react');
8
+ var _propTypes = _interopRequireDefault(require("prop-types"));
8
9
 
9
- var _react2 = _interopRequireDefault(_react);
10
-
11
- var _propTypes = require('prop-types');
12
-
13
- var _propTypes2 = _interopRequireDefault(_propTypes);
14
-
15
- var _Resizable = require('./Resizable');
16
-
17
- var _Resizable2 = _interopRequireDefault(_Resizable);
10
+ var _Resizable = _interopRequireDefault(require("./Resizable"));
18
11
 
19
12
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
20
13
 
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; }
14
+ 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); }
22
15
 
23
- function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
16
+ 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; }
24
17
 
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; }
18
+ function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
26
19
 
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; }
20
+ function _inheritsLoose(subClass, superClass) { subClass.prototype = Object.create(superClass.prototype); subClass.prototype.constructor = subClass; subClass.__proto__ = superClass; }
21
+
22
+ 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; }
28
23
 
29
24
  // An example use of Resizable.
30
- var ResizableBox = function (_React$Component) {
31
- _inherits(ResizableBox, _React$Component);
25
+ var ResizableBox =
26
+ /*#__PURE__*/
27
+ function (_React$Component) {
28
+ _inheritsLoose(ResizableBox, _React$Component);
32
29
 
33
30
  function ResizableBox() {
34
- var _temp, _this, _ret;
35
-
36
- _classCallCheck(this, ResizableBox);
31
+ var _this;
37
32
 
38
- for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) {
33
+ for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
39
34
  args[_key] = arguments[_key];
40
35
  }
41
36
 
42
- return _ret = (_temp = (_this = _possibleConstructorReturn(this, _React$Component.call.apply(_React$Component, [this].concat(args))), _this), _this.state = {
37
+ _this = _React$Component.call.apply(_React$Component, [this].concat(args)) || this;
38
+
39
+ _defineProperty(_assertThisInitialized(_this), "state", {
43
40
  width: _this.props.width,
44
- height: _this.props.height
45
- }, _this.onResize = function (e, data) {
41
+ height: _this.props.height,
42
+ propsWidth: _this.props.width,
43
+ propsHeight: _this.props.height
44
+ });
45
+
46
+ _defineProperty(_assertThisInitialized(_this), "onResize", function (e, data) {
46
47
  var size = data.size;
47
48
  var width = size.width,
48
49
  height = size.height;
49
50
 
50
-
51
51
  if (_this.props.onResize) {
52
52
  e.persist && e.persist();
53
+
53
54
  _this.setState(size, function () {
54
55
  return _this.props.onResize && _this.props.onResize(e, data);
55
56
  });
56
57
  } else {
57
58
  _this.setState(size);
58
59
  }
59
- }, _temp), _possibleConstructorReturn(_this, _ret);
60
+ });
61
+
62
+ return _this;
60
63
  }
61
64
 
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
- });
65
+ ResizableBox.getDerivedStateFromProps = function getDerivedStateFromProps(props, state) {
66
+ // If parent changes height/width, set that in our state.
67
+ if (state.propsWidth !== props.width || state.propsHeight !== props.height) {
68
+ return {
69
+ width: props.width,
70
+ height: props.height,
71
+ propsWidth: props.width,
72
+ propsHeight: props.height
73
+ };
68
74
  }
75
+
76
+ return null;
69
77
  };
70
78
 
71
- ResizableBox.prototype.render = function render() {
79
+ var _proto = ResizableBox.prototype;
80
+
81
+ _proto.render = function render() {
72
82
  // Basic wrapper around a Resizable instance.
73
83
  // If you use Resizable directly, you are responsible for updating the child component
74
84
  // 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
- );
85
+ var _this$props = this.props,
86
+ handle = _this$props.handle,
87
+ handleSize = _this$props.handleSize,
88
+ onResize = _this$props.onResize,
89
+ onResizeStart = _this$props.onResizeStart,
90
+ onResizeStop = _this$props.onResizeStop,
91
+ draggableOpts = _this$props.draggableOpts,
92
+ minConstraints = _this$props.minConstraints,
93
+ maxConstraints = _this$props.maxConstraints,
94
+ lockAspectRatio = _this$props.lockAspectRatio,
95
+ axis = _this$props.axis,
96
+ width = _this$props.width,
97
+ height = _this$props.height,
98
+ resizeHandles = _this$props.resizeHandles,
99
+ props = _objectWithoutPropertiesLoose(_this$props, ["handle", "handleSize", "onResize", "onResizeStart", "onResizeStop", "draggableOpts", "minConstraints", "maxConstraints", "lockAspectRatio", "axis", "width", "height", "resizeHandles"]);
100
+
101
+ return _react.default.createElement(_Resizable.default, {
102
+ handle: handle,
103
+ handleSize: handleSize,
104
+ width: this.state.width,
105
+ height: this.state.height,
106
+ onResizeStart: onResizeStart,
107
+ onResize: this.onResize,
108
+ onResizeStop: onResizeStop,
109
+ draggableOpts: draggableOpts,
110
+ minConstraints: minConstraints,
111
+ maxConstraints: maxConstraints,
112
+ lockAspectRatio: lockAspectRatio,
113
+ axis: axis,
114
+ resizeHandles: resizeHandles
115
+ }, _react.default.createElement("div", _extends({
116
+ style: {
117
+ width: this.state.width + 'px',
118
+ height: this.state.height + 'px'
119
+ }
120
+ }, props)));
106
121
  };
107
122
 
108
123
  return ResizableBox;
109
- }(_react2.default.Component);
124
+ }(_react.default.Component);
125
+
126
+ exports.default = ResizableBox;
127
+
128
+ _defineProperty(ResizableBox, "propTypes", {
129
+ height: _propTypes.default.number,
130
+ width: _propTypes.default.number
131
+ });
110
132
 
111
- ResizableBox.propTypes = {
112
- height: _propTypes2.default.number,
113
- width: _propTypes2.default.number
114
- };
115
- ResizableBox.defaultProps = {
133
+ _defineProperty(ResizableBox, "defaultProps", {
116
134
  handleSize: [20, 20]
117
- };
118
- exports.default = ResizableBox;
135
+ });
@@ -5,7 +5,10 @@ import Resizable from './Resizable';
5
5
  import type {Props as ResizableProps, ResizeCallbackData} from './Resizable';
6
6
  import type {Node as ReactNode} from 'react';
7
7
 
8
- type State = {width: number, height: number};
8
+ type State = {
9
+ width: number, height: number,
10
+ propsWidth: number, propsHeight: number,
11
+ };
9
12
 
10
13
  // An example use of Resizable.
11
14
  export default class ResizableBox extends React.Component<ResizableProps, State> {
@@ -21,8 +24,23 @@ export default class ResizableBox extends React.Component<ResizableProps, State>
21
24
  state: State = {
22
25
  width: this.props.width,
23
26
  height: this.props.height,
27
+ propsWidth: this.props.width,
28
+ propsHeight: this.props.height,
24
29
  };
25
30
 
31
+ static getDerivedStateFromProps(props: ResizableProps, state: State) {
32
+ // If parent changes height/width, set that in our state.
33
+ if (state.propsWidth !== props.width || state.propsHeight !== props.height) {
34
+ return {
35
+ width: props.width,
36
+ height: props.height,
37
+ propsWidth: props.width,
38
+ propsHeight: props.height,
39
+ };
40
+ }
41
+ return null;
42
+ }
43
+
26
44
  onResize = (e: SyntheticEvent<>, data: ResizeCallbackData) => {
27
45
  const {size} = data;
28
46
  const {width, height} = size;
@@ -35,23 +53,15 @@ export default class ResizableBox extends React.Component<ResizableProps, State>
35
53
  }
36
54
  };
37
55
 
38
- componentWillReceiveProps(nextProps: ResizableProps) {
39
- if (nextProps.width !== this.props.width || nextProps.height !== this.props.height) {
40
- this.setState({
41
- width: nextProps.width,
42
- height: nextProps.height
43
- });
44
- }
45
- }
46
-
47
56
  render(): ReactNode {
48
57
  // Basic wrapper around a Resizable instance.
49
58
  // If you use Resizable directly, you are responsible for updating the child component
50
59
  // with a new width and height.
51
- const {handleSize, onResize, onResizeStart, onResizeStop, draggableOpts,
52
- minConstraints, maxConstraints, lockAspectRatio, axis, width, height, ...props} = this.props;
60
+ const {handle, handleSize, onResize, onResizeStart, onResizeStop, draggableOpts, minConstraints,
61
+ maxConstraints, lockAspectRatio, axis, width, height, resizeHandles, ...props} = this.props;
53
62
  return (
54
63
  <Resizable
64
+ handle={handle}
55
65
  handleSize={handleSize}
56
66
  width={this.state.width}
57
67
  height={this.state.height}
@@ -63,7 +73,8 @@ export default class ResizableBox extends React.Component<ResizableProps, State>
63
73
  maxConstraints={maxConstraints}
64
74
  lockAspectRatio={lockAspectRatio}
65
75
  axis={axis}
66
- >
76
+ resizeHandles={resizeHandles}
77
+ >
67
78
  <div style={{width: this.state.width + 'px', height: this.state.height + 'px'}} {...props} />
68
79
  </Resizable>
69
80
  );
package/build/utils.js ADDED
@@ -0,0 +1,27 @@
1
+ "use strict";
2
+
3
+ exports.__esModule = true;
4
+ exports.cloneElement = cloneElement;
5
+
6
+ var _react = _interopRequireDefault(require("react"));
7
+
8
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
9
+
10
+ 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; }
11
+
12
+ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(source, true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(source).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
13
+
14
+ 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; }
15
+
16
+ // React.addons.cloneWithProps look-alike that merges style & className.
17
+ function cloneElement(element, props) {
18
+ if (props.style && element.props.style) {
19
+ props.style = _objectSpread({}, element.props.style, {}, props.style);
20
+ }
21
+
22
+ if (props.className && element.props.className) {
23
+ props.className = element.props.className + " " + props.className;
24
+ }
25
+
26
+ return _react.default.cloneElement(element, props);
27
+ }
@@ -3,7 +3,7 @@ import React from 'react';
3
3
  import type {Element as ReactElement} from 'react';
4
4
 
5
5
  // React.addons.cloneWithProps look-alike that merges style & className.
6
- module.exports = function cloneElement(element: ReactElement<any>, props: Object): ReactElement<any> {
6
+ export function cloneElement(element: ReactElement<any>, props: Object): ReactElement<any> {
7
7
  if (props.style && element.props.style) {
8
8
  props.style = {...element.props.style, ...props.style};
9
9
  }
@@ -11,4 +11,4 @@ module.exports = function cloneElement(element: ReactElement<any>, props: Object
11
11
  props.className = `${element.props.className} ${props.className}`;
12
12
  }
13
13
  return React.cloneElement(element, props);
14
- };
14
+ }
package/css/styles.css CHANGED
@@ -5,13 +5,61 @@
5
5
  position: absolute;
6
6
  width: 20px;
7
7
  height: 20px;
8
- bottom: 0;
9
- right: 0;
10
- background: url('data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHZpZXdCb3g9IjAgMCA2IDYiIHN0eWxlPSJiYWNrZ3JvdW5kLWNvbG9yOiNmZmZmZmYwMCIgeD0iMHB4IiB5PSIwcHgiIHdpZHRoPSI2cHgiIGhlaWdodD0iNnB4Ij48ZyBvcGFjaXR5PSIwLjMwMiI+PHBhdGggZD0iTSA2IDYgTCAwIDYgTCAwIDQuMiBMIDQgNC4yIEwgNC4yIDQuMiBMIDQuMiAwIEwgNiAwIEwgNiA2IEwgNiA2IFoiIGZpbGw9IiMwMDAwMDAiLz48L2c+PC9zdmc+');
11
- background-position: bottom right;
12
- padding: 0 3px 3px 0;
13
8
  background-repeat: no-repeat;
14
9
  background-origin: content-box;
15
10
  box-sizing: border-box;
11
+ background-image: url('data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHZpZXdCb3g9IjAgMCA2IDYiIHN0eWxlPSJiYWNrZ3JvdW5kLWNvbG9yOiNmZmZmZmYwMCIgeD0iMHB4IiB5PSIwcHgiIHdpZHRoPSI2cHgiIGhlaWdodD0iNnB4Ij48ZyBvcGFjaXR5PSIwLjMwMiI+PHBhdGggZD0iTSA2IDYgTCAwIDYgTCAwIDQuMiBMIDQgNC4yIEwgNC4yIDQuMiBMIDQuMiAwIEwgNiAwIEwgNiA2IEwgNiA2IFoiIGZpbGw9IiMwMDAwMDAiLz48L2c+PC9zdmc+');
12
+ background-position: bottom right;
13
+ padding: 0 3px 3px 0;
14
+ }
15
+ .react-resizable-handle-sw {
16
+ bottom: 0;
17
+ left: 0;
18
+ cursor: sw-resize;
19
+ transform: rotate(90deg);
20
+ }
21
+ .react-resizable-handle-se {
22
+ bottom: 0;
23
+ right: 0;
16
24
  cursor: se-resize;
17
25
  }
26
+ .react-resizable-handle-nw {
27
+ top: 0;
28
+ left: 0;
29
+ cursor: nw-resize;
30
+ transform: rotate(180deg);
31
+ }
32
+ .react-resizable-handle-ne {
33
+ top: 0;
34
+ right: 0;
35
+ cursor: ne-resize;
36
+ transform: rotate(270deg);
37
+ }
38
+ .react-resizable-handle-w,
39
+ .react-resizable-handle-e {
40
+ top: 50%;
41
+ margin-top: -10px;
42
+ cursor: ew-resize;
43
+ }
44
+ .react-resizable-handle-w {
45
+ left: 0;
46
+ transform: rotate(135deg);
47
+ }
48
+ .react-resizable-handle-e {
49
+ right: 0;
50
+ transform: rotate(315deg);
51
+ }
52
+ .react-resizable-handle-n,
53
+ .react-resizable-handle-s {
54
+ left: 50%;
55
+ margin-left: -10px;
56
+ cursor: ns-resize;
57
+ }
58
+ .react-resizable-handle-n {
59
+ top: 0;
60
+ transform: rotate(225deg);
61
+ }
62
+ .react-resizable-handle-s {
63
+ bottom: 0;
64
+ transform: rotate(45deg);
65
+ }
package/index.html ADDED
@@ -0,0 +1,15 @@
1
+ <html>
2
+ <head>
3
+ <style>
4
+ body {
5
+ background: darkblue;
6
+ color: white;
7
+ font-size: 32px;
8
+ }
9
+ </style>
10
+ </head>
11
+ <body>
12
+ Hello! This is a website wow
13
+ <div style="background-color: black; width: 200px; height: 200px">BOX</div>
14
+ </body>
15
+ </html>