Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: transformScale support { w: number; h: number } #192

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions lib/Resizable.js
Original file line number Diff line number Diff line change
Expand Up @@ -126,8 +126,11 @@ export default class Resizable extends React.Component<Props, void> {
if (axisV === 'n') deltaY = -deltaY;

// Update w/h by the deltas. Also factor in transformScale.
let width = this.props.width + (canDragX ? deltaX / this.props.transformScale : 0);
let height = this.props.height + (canDragY ? deltaY / this.props.transformScale : 0);
const transformScale = this.props.transformScale;
const transformScaleW = typeof transformScale === 'number' ? transformScale : transformScale.w;
const transformScaleH = typeof transformScale === 'number' ? transformScale : transformScale.h;
let width = this.props.width + (canDragX ? deltaX / transformScaleW : 0);
let height = this.props.height + (canDragY ? deltaY / transformScaleH : 0);

// Run user-provided constraints.
[width, height] = this.runConstraints(width, height);
Expand Down
10 changes: 8 additions & 2 deletions lib/propTypes.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ export type DefaultProps = {
minConstraints: [number, number],
maxConstraints: [number, number],
resizeHandles: ResizeHandleAxis[],
transformScale: number,
transformScale: number | { w: number; h: number },
};

export type Props = {
Expand Down Expand Up @@ -137,7 +137,13 @@ export const resizableProps: Object = {
/*
* If `transform: scale(n)` is set on the parent, this should be set to `n`.
* */
transformScale: PropTypes.number,
transformScale: PropTypes.oneOfType([
PropTypes.number,
PropTypes.shape({
w: PropTypes.number,
h: PropTypes.number
})
]),
/*
* Initial width
*/
Expand Down