-
-
Notifications
You must be signed in to change notification settings - Fork 629
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: fix dragTarget in control box #1054
- Loading branch information
Showing
5 changed files
with
120 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
76 changes: 76 additions & 0 deletions
76
packages/react-moveable/stories/6-CustomAble/ReactDragTargetAbleApp.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
import React from "react"; | ||
// import "./App.css"; | ||
import Moveable, { MoveableManagerInterface, Renderer } from "@/react-moveable"; | ||
|
||
const DimensionViewable = { | ||
name: "dimensionViewable", | ||
props: [], | ||
events: [], | ||
render(moveable: MoveableManagerInterface<any, any>, React: Renderer) { | ||
const rect = moveable.getRect(); | ||
|
||
// Add key (required) | ||
// Add class prefix moveable-(required) | ||
return ( | ||
<div | ||
key={"dimension-viewer"} | ||
className={"moveable-dimension"} | ||
style={{ | ||
position: "absolute", | ||
left: `${rect.width / 2}px`, | ||
top: `${rect.height + 20}px`, | ||
background: "#4af", | ||
borderRadius: "2px", | ||
padding: "2px 4px", | ||
color: "white", | ||
fontSize: "13px", | ||
whiteSpace: "nowrap", | ||
fontWeight: "bold", | ||
willChange: "transform", | ||
transform: `translate(-50%, 0px)`, | ||
}} | ||
> | ||
Target | ||
</div> | ||
); | ||
}, | ||
} as const; | ||
|
||
function App() { | ||
const [dragTarget, setDragTarget] = React.useState<HTMLElement>(); | ||
|
||
React.useEffect(() => { | ||
setDragTarget(document.querySelector<HTMLElement>(".moveable-dimension")!); | ||
}, []); | ||
return ( | ||
<div className="container"> | ||
<div className="target target1"></div> | ||
<div className="target target2"></div> | ||
<Moveable | ||
ables={[DimensionViewable]} | ||
dragTarget={dragTarget} | ||
resizable={true} | ||
props={{ | ||
dimensionViewable: true, | ||
}} | ||
target={[".target1"]} | ||
draggable={true} | ||
onDrag={(e) => { | ||
e.target.style.transform = e.transform; | ||
}} | ||
onResize={(e) => { | ||
e.target.style.width = `${e.width}px`; | ||
e.target.style.height = `${e.height}px`; | ||
e.target.style.transform = e.drag.transform; | ||
}} | ||
onRotate={(e) => { | ||
e.target.style.transform = e.drag.transform; | ||
}} | ||
elementGuidelines={[".target1", ".target2"]} | ||
snappable={true} | ||
/> | ||
</div> | ||
); | ||
} | ||
|
||
export default App; |