Skip to content

Commit 6cffdc3

Browse files
committed
demo: add fixed position resize #964
1 parent 1b58541 commit 6cffdc3

File tree

2 files changed

+51
-0
lines changed

2 files changed

+51
-0
lines changed

packages/react-moveable/stories/3-Group/0-Group.stories.tsx

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,3 +162,9 @@ export const GroupRoundableGroup = add("Roundable Group", {
162162
});
163163
},
164164
});
165+
166+
167+
export const GroupFixedResizeGroup = add("Fixed Position Resize Group", {
168+
app: require("./ReactFixedResizeGroupApp").default,
169+
path: require.resolve("./ReactFixedResizeGroupApp"),
170+
});
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
import * as React from "react";
2+
import Moveable from "@/react-moveable";
3+
4+
export default function App(props: Record<string, any>) {
5+
return (
6+
<div className="root">
7+
<div className="container">
8+
<div className="target target1" style={{
9+
transform: "translate(0px, 0px) rotate(0deg) scale(1, 1)",
10+
}}>Target1</div>
11+
<div className="target target2" style={{
12+
transform: "translate(0px, 0px) rotate(0deg) scale(1, 1)",
13+
}}>Target2</div>
14+
<div className="target target3" style={{
15+
transform: "translate(0px, 0px) rotate(0deg) scale(1, 1)",
16+
}}>Target3</div>
17+
<Moveable
18+
target={".target"}
19+
draggable={true}
20+
resizable={true}
21+
keepRatio={false}
22+
onDragGroup={e => {
23+
e.events.forEach(ev => {
24+
ev.target.style.cssText += ev.cssText;
25+
});
26+
}}
27+
onResizeGroup={(e) => {
28+
if (e.direction[0] === -1) {
29+
// left edge
30+
e.events.forEach((ev) => {
31+
ev.target.style.width = `${ev.width - ev.dist[0] + e.dist[0]}px`;
32+
ev.target.style.cssText += `margin-left: ${-e.dist[0]}px`; // the first resize moves the element , not desireable
33+
});
34+
} else if (e.direction[0] === 1) {
35+
//right edge
36+
e.events.forEach((ev) => {
37+
ev.target.style.width = `${ev.width - ev.dist[0] + e.dist[0]}px`;
38+
});
39+
}
40+
}}
41+
/>
42+
</div>
43+
</div>
44+
);
45+
}

0 commit comments

Comments
 (0)