-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
63de46d
commit 2ee4574
Showing
8 changed files
with
202 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
import { useEffect, useState, useRef } from "react"; | ||
import { | ||
Handle, | ||
Position, | ||
useUpdateNodeInternals, | ||
NodeResizer, | ||
} from "reactflow"; | ||
import { drag } from "d3-drag"; | ||
import { select } from "d3-selection"; | ||
|
||
import styles from "./style.module.css"; | ||
|
||
export default function ResizeRotateNode({ | ||
id, | ||
sourcePosition = Position.Left, | ||
targetPosition = Position.Right, | ||
data, | ||
}) { | ||
const rotateControlRef = useRef(null); | ||
const updateNodeInternals = useUpdateNodeInternals(); | ||
const [rotation, setRotation] = useState(0); | ||
const [resizable, setResizable] = useState(!!data.resizable); | ||
const [rotatable, setRotatable] = useState(!!data.rotatable); | ||
|
||
useEffect(() => { | ||
if (!rotateControlRef.current) { | ||
return; | ||
} | ||
|
||
const selection = select(rotateControlRef.current); | ||
const dragHandler = drag().on("drag", (evt) => { | ||
const dx = evt.x - 100; | ||
const dy = evt.y - 100; | ||
const rad = Math.atan2(dx, dy); | ||
const deg = rad * (180 / Math.PI); | ||
setRotation(180 - deg); | ||
updateNodeInternals(id); | ||
}); | ||
|
||
selection.call(dragHandler); | ||
}, [id, updateNodeInternals]); | ||
|
||
return ( | ||
<> | ||
<div | ||
style={{ | ||
transform: `rotate(${rotation}deg)`, | ||
}} | ||
className={styles.node} | ||
> | ||
<NodeResizer isVisible={resizable} minWidth={180} minHeight={100} /> | ||
<div | ||
ref={rotateControlRef} | ||
style={{ | ||
display: rotatable ? "block" : "none", | ||
}} | ||
className={`nodrag ${styles.rotateHandle}`} | ||
/> | ||
<div> | ||
{data?.label} | ||
<div> | ||
<label> | ||
<input | ||
type="checkbox" | ||
checked={resizable} | ||
onChange={(evt) => setResizable(evt.target.checked)} | ||
/> | ||
resizable | ||
</label> | ||
</div> | ||
<div> | ||
<label> | ||
<input | ||
type="checkbox" | ||
checked={rotatable} | ||
onChange={(evt) => setRotatable(evt.target.checked)} | ||
/> | ||
rotatable | ||
</label> | ||
</div> | ||
</div> | ||
<Handle | ||
style={{ opacity: 0 }} | ||
position={sourcePosition} | ||
type="source" | ||
/> | ||
<Handle | ||
style={{ opacity: 0 }} | ||
position={targetPosition} | ||
type="target" | ||
/> | ||
</div> | ||
</> | ||
); | ||
} |
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,38 @@ | ||
.node { | ||
width: 100%; | ||
height: 100%; | ||
border-radius: 15px; | ||
border: 1px solid #000; | ||
background-color: #fff; | ||
padding: 20px; | ||
box-sizing: border-box; | ||
} | ||
|
||
.node :global .react-flow__resize-control.handle { | ||
width: 10px; | ||
height: 10px; | ||
border-radius: 100%; | ||
} | ||
|
||
.rotateHandle { | ||
position: absolute; | ||
width: 10px; | ||
height: 10px; | ||
background: #3367d9; | ||
left: 50%; | ||
top: -30px; | ||
border-radius: 100%; | ||
transform: translate(-50%, -50%); | ||
cursor: alias; | ||
} | ||
|
||
.rotateHandle:after { | ||
content: ""; | ||
display: block; | ||
position: absolute; | ||
width: 1px; | ||
height: 30px; | ||
background: #3367d9; | ||
left: 4px; | ||
top: 5px; | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
import ReactFlow, { Background, Position } from "reactflow"; | ||
|
||
import "reactflow/dist/style.css"; | ||
|
||
import ResizeRotateNode from "../components/flow/edit-flow/resize-and-rotate"; | ||
|
||
const nodeTypes = { | ||
resizeRotate: ResizeRotateNode, | ||
}; | ||
|
||
const nodes = [ | ||
{ | ||
id: "1", | ||
position: { x: 0, y: 0 }, | ||
data: { label: "Node 1", resizable: true }, | ||
type: "resizeRotate", | ||
targetPosition: Position.Left, | ||
sourcePosition: Position.Right, | ||
selected: true, | ||
style: { width: 180, height: 100 }, | ||
}, | ||
{ | ||
id: "2", | ||
position: { x: 300, y: 0 }, | ||
data: { label: "Node 2", rotatable: true }, | ||
type: "resizeRotate", | ||
targetPosition: Position.Left, | ||
sourcePosition: Position.Right, | ||
style: { width: 180, height: 100 }, | ||
}, | ||
]; | ||
|
||
const edges = [ | ||
{ | ||
id: "1->2", | ||
source: "1", | ||
target: "2", | ||
type: "smoothstep", | ||
}, | ||
]; | ||
|
||
export const MembersPage = () => { | ||
return ( | ||
<div> | ||
<p>Members Page</p> | ||
|
||
<ReactFlow | ||
nodeTypes={nodeTypes} | ||
defaultNodes={nodes} | ||
defaultEdges={edges} | ||
fitView | ||
> | ||
<Background /> | ||
</ReactFlow> | ||
</div> | ||
); | ||
}; |
This file was deleted.
Oops, something went wrong.
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