Skip to content

Commit 8a45159

Browse files
committed
Add prop to toggle bound to parent
1 parent c4457d6 commit 8a45159

File tree

4 files changed

+64
-37
lines changed

4 files changed

+64
-37
lines changed

dist/index.es.js

Lines changed: 29 additions & 18 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/index.es.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/AlignmentGuides.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -478,6 +478,7 @@ class AlignmentGuides extends Component {
478478

479479
// Typechecking props for AlignmentGuides component
480480
AlignmentGuides.propTypes = {
481+
boundToParent: PropTypes.bool,
481482
boxes: PropTypes.array.isRequired,
482483
boxStyle: PropTypes.object,
483484
className: PropTypes.string,
@@ -504,6 +505,7 @@ AlignmentGuides.propTypes = {
504505

505506
// Default values for props
506507
AlignmentGuides.defaultProps = {
508+
boundToParent: true,
507509
boxes: [],
508510
drag: true,
509511
resize: true,

src/Box.js

Lines changed: 32 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,17 @@ class Box extends PureComponent {
7878
const left = e.clientX - deltaX;
7979
const top = e.clientY - deltaY;
8080

81-
const currentPosition = calculateBoundariesForDrag(left, top, boxWidth, boxHeight, boundingBoxDimensions);
81+
let currentPosition = this.props.boundToParent ?
82+
calculateBoundariesForDrag(left, top, boxWidth, boxHeight, boundingBoxDimensions) :
83+
{
84+
left,
85+
top,
86+
width: this.props.position.width,
87+
height: this.props.position.height,
88+
x: left,
89+
y: top,
90+
node: this.box.current
91+
};
8292
data = {
8393
x: currentPosition.left,
8494
y: currentPosition.top,
@@ -268,37 +278,40 @@ class Box extends PureComponent {
268278
const type = target.id.replace('resize-', '');
269279

270280
const { position: { cx, cy }, size: { width, height } } = getNewStyle(type, rect, deltaW, deltaH, 10, 10); // Use a better way to set minWidth and minHeight
271-
const currentPosition = centerToTopLeft({ cx, cy, width, height, rotateAngle });
281+
const tempPosition = centerToTopLeft({ cx, cy, width, height, rotateAngle });
272282

273283
data = {
274-
width: currentPosition.width,
275-
height: currentPosition.height,
276-
x: currentPosition.left,
277-
y: currentPosition.top,
278-
left: currentPosition.left,
279-
top: currentPosition.top,
284+
width: tempPosition.width,
285+
height: tempPosition.height,
286+
x: tempPosition.left,
287+
y: tempPosition.top,
288+
left: tempPosition.left,
289+
top: tempPosition.top,
280290
rotateAngle,
281291
node: this.box.current
282292
};
283293

284294
// if (rotateAngle !== 0) {
285295
// data = {
286-
// width: currentPosition.width,
287-
// height: currentPosition.height,
288-
// x: currentPosition.left,
289-
// y: currentPosition.top,
290-
// left: currentPosition.left,
291-
// top: currentPosition.top,
296+
// width: tempPosition.width,
297+
// height: tempPosition.height,
298+
// x: tempPosition.left,
299+
// y: tempPosition.top,
300+
// left: tempPosition.left,
301+
// top: tempPosition.top,
292302
// rotateAngle,
293303
// node: this.box.current
294304
// };
295305
// }
296306

297307
// Calculate the restrictions if resize goes out of bounds
298-
const restrictResizeWithinBoundaries = calculateBoundariesForResize(data.left, data.top, currentPosition.width, currentPosition.height, boundingBoxPosition);
299-
data = Object.assign({}, data, restrictResizeWithinBoundaries, {
300-
x: restrictResizeWithinBoundaries.left,
301-
y: restrictResizeWithinBoundaries.top
308+
const currentPosition = this.props.boundToParent ?
309+
calculateBoundariesForResize(data.left, data.top, tempPosition.width, tempPosition.height, boundingBoxPosition) :
310+
Object.assign({}, data);
311+
312+
data = Object.assign({}, data, currentPosition, {
313+
x: currentPosition.left,
314+
y: currentPosition.top
302315
});
303316

304317
this.props.onResize && this.props.onResize(e, data);
@@ -499,6 +512,7 @@ class Box extends PureComponent {
499512
}
500513

501514
Box.propTypes = {
515+
boundToParent: PropTypes.bool,
502516
drag: PropTypes.bool,
503517
getBoundingBoxElement: PropTypes.func,
504518
id: PropTypes.string,

0 commit comments

Comments
 (0)