Skip to content

Commit 902d907

Browse files
authored
Support scale (#485)
* fix: window boundary * fix: tsc error * fix: parent scale * fix: body boundary * fix: selector boundary * fix: fix errors and add grid stories * fix: README
1 parent 80bdfba commit 902d907

File tree

4 files changed

+69
-0
lines changed

4 files changed

+69
-0
lines changed

README.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,13 @@ The `lockAspectRatioExtraWidth` property enables a resizable component to mainta
197197
For instance, a video could be displayed 16:9 with a 50px side bar.
198198
If omitted, set `0`.
199199

200+
#### `scale?: number;`
201+
202+
Specifies the scale of the canvas your are dragging or resizing this element on. This allows
203+
you to, for example, get the correct drag / resize deltas while you are zoomed in or out via
204+
a transform or matrix in the parent of this element.
205+
If omitted, set `1`.
206+
200207
#### `lockAspectRatioExtraHeight?: number;`
201208

202209
The `lockAspectRatioExtraHeight` property enables a resizable component to maintain an aspect ratio plus extra height.

src/index.js.flow

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,7 @@ export type Props = {
133133
disableDragging?: boolean,
134134
cancel?: boolean,
135135
enableUserSelectHack?: boolean,
136+
scale?: number,
136137
};
137138

138139
export class Rnd extends React.Component<Props, State> {
@@ -145,6 +146,7 @@ export class Rnd extends React.Component<Props, State> {
145146
onDragStart: () => {},
146147
onDrag: () => {},
147148
onDragStop: () => {},
149+
scale: 1,
148150
};
149151

150152
updateSize(size: { width: number | string, height: number | string }) {

stories/index.tsx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import ScaleWindowUnControlled from "./scale/window-uncontrolled";
1212
import ScaleBodyX05UnControlled from "./scale/body-uncontrolled-x0-5";
1313
import ScaleBodyX15UnControlled from "./scale/body-uncontrolled-x1-5";
1414
import ScaleSelectorUnControlled from "./scale/selector-uncontrolled";
15+
import ScaleSelectorControlled from "./scale/selector-controlled";
1516

1617
import BasicMultiUncontrolled from "./basic/multi-uncontrolled";
1718
import BasicMultiControlled from "./basic/multi-controlled";
@@ -60,8 +61,11 @@ storiesOf("scale", module)
6061
.add("x0.5 with body boundary", () => <ScaleBodyX05UnControlled />)
6162
.add("x1.5 with body boundary", () => <ScaleBodyX15UnControlled />)
6263
.add("with window boundary", () => <ScaleWindowUnControlled />)
64+
.add("with selector boundary uncontrolled", () => <ScaleSelectorUnControlled />)
65+
.add("with selector boundary controlled", () => <ScaleSelectorControlled />)
6366
.add("with selector boundary", () => <ScaleSelectorUnControlled />);
6467

68+
6569
storiesOf("size", module)
6670
.add("percent uncontrolled", () => <SizePercentUncontrolled />)
6771
.add("percent controlled", () => <SizePercentControlled />);
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
import React from "react";
2+
import { Rnd } from "../../src";
3+
import { style, parentBoundary, selectorBoundary } from "../styles";
4+
5+
type State = {
6+
x: number;
7+
y: number;
8+
width: number;
9+
height: number;
10+
};
11+
12+
export default class Example extends React.Component<{}, State> {
13+
constructor(props) {
14+
super(props);
15+
this.state = {
16+
width: 200,
17+
height: 200,
18+
x: 0,
19+
y: 0,
20+
};
21+
}
22+
23+
render() {
24+
return (
25+
<div className="boundary" style={{ ...selectorBoundary, transform: "scale(0.6)" }}>
26+
<div style={parentBoundary}>
27+
<Rnd
28+
scale={0.6}
29+
style={style}
30+
bounds=".boundary"
31+
size={{
32+
width: this.state.width,
33+
height: this.state.height,
34+
}}
35+
position={{
36+
x: this.state.x,
37+
y: this.state.y,
38+
}}
39+
onDragStop={(e, d) => {
40+
this.setState({ x: d.x, y: d.y });
41+
}}
42+
onResize={(e, direction, ref, delta, position) => {
43+
this.setState({
44+
width: ref.offsetWidth,
45+
height: ref.offsetHeight,
46+
...position,
47+
});
48+
}}
49+
>
50+
001
51+
</Rnd>
52+
</div>
53+
</div>
54+
);
55+
}
56+
}

0 commit comments

Comments
 (0)