Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(nodes): connect on touch device
- Loading branch information
Showing
8 changed files
with
136 additions
and
7 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,49 @@ | ||
import { useCallback } from 'react'; | ||
import ReactFlow, { | ||
Node, | ||
Edge, | ||
useNodesState, | ||
useEdgesState, | ||
Position, | ||
Connection, | ||
addEdge, | ||
} from 'react-flow-renderer'; | ||
|
||
import './touch-device.css'; | ||
|
||
const initialNodes: Node[] = [ | ||
{ | ||
id: '1', | ||
data: { label: 'Node 1' }, | ||
position: { x: 100, y: 100 }, | ||
sourcePosition: Position.Right, | ||
targetPosition: Position.Left, | ||
}, | ||
{ | ||
id: '2', | ||
data: { label: 'Node 2' }, | ||
position: { x: 300, y: 100 }, | ||
sourcePosition: Position.Right, | ||
targetPosition: Position.Left, | ||
}, | ||
]; | ||
|
||
const initialEdges: Edge[] = []; | ||
|
||
const TouchDeviceFlow = () => { | ||
const [nodes, setNodes, onNodesChange] = useNodesState(initialNodes); | ||
const [edges, setEdges, onEdgesChange] = useEdgesState(initialEdges); | ||
const onConnect = useCallback((connection: Connection) => setEdges((eds) => addEdge(connection, eds)), []); | ||
|
||
return ( | ||
<ReactFlow | ||
nodes={nodes} | ||
edges={edges} | ||
onConnect={onConnect} | ||
onNodesChange={onNodesChange} | ||
onEdgesChange={onEdgesChange} | ||
/> | ||
); | ||
}; | ||
|
||
export default TouchDeviceFlow; |
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,19 @@ | ||
.react-flow .react-flow__handle { | ||
width: 20px; | ||
height: 20px; | ||
border-radius: 3px; | ||
background-color: #9f7aea; | ||
} | ||
|
||
.react-flow__handle.connecting { | ||
animation: bounce 1600ms infinite ease-out; | ||
} | ||
|
||
@keyframes bounce { | ||
0% { | ||
transform: translate(0, -50%) scale(1); | ||
} | ||
50% { | ||
transform: translate(0, -50%) scale(1.1); | ||
} | ||
} |
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
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