From 920136b807b786b58b58aa46f3459d4895315953 Mon Sep 17 00:00:00 2001 From: Jack Fishwick Date: Mon, 26 Sep 2022 15:09:22 +0100 Subject: [PATCH] feat: add a Figma example. --- examples/vite-app/src/App/index.tsx | 6 ++ .../vite-app/src/examples/Figma/index.tsx | 97 +++++++++++++++++++ 2 files changed, 103 insertions(+) create mode 100644 examples/vite-app/src/examples/Figma/index.tsx diff --git a/examples/vite-app/src/App/index.tsx b/examples/vite-app/src/App/index.tsx index 5b596f48..8e46f457 100644 --- a/examples/vite-app/src/App/index.tsx +++ b/examples/vite-app/src/App/index.tsx @@ -13,6 +13,7 @@ import Edges from '../examples/Edges'; import EdgeRenderer from '../examples/EdgeRenderer'; import EdgeTypes from '../examples/EdgeTypes'; import Empty from '../examples/Empty'; +import Figma from '../examples/Figma'; import FloatingEdges from '../examples/FloatingEdges'; import Hidden from '../examples/Hidden'; import Interaction from '../examples/Interaction'; @@ -119,6 +120,11 @@ const routes: IRoute[] = [ path: '/empty', component: Empty, }, + { + name: 'Figma', + path: '/figma', + component: Figma, + }, { name: 'Floating Edges', path: '/floating-edges', diff --git a/examples/vite-app/src/examples/Figma/index.tsx b/examples/vite-app/src/examples/Figma/index.tsx new file mode 100644 index 00000000..3c19af29 --- /dev/null +++ b/examples/vite-app/src/examples/Figma/index.tsx @@ -0,0 +1,97 @@ +import ReactFlow, { + ReactFlowProvider, + Background, + BackgroundVariant, + Node, + Edge, + useReactFlow, + useKeyPress, +} from 'react-flow-renderer'; + +const MULTI_SELECT_KEY = ['Meta', 'Shift']; + +const initialNodes: Node[] = [ + { id: '1', type: 'input', data: { label: 'Node 1' }, position: { x: 250, y: 5 }, className: 'light' }, + { id: '2', data: { label: 'Node 2' }, position: { x: 100, y: 100 }, className: 'light' }, + { id: '3', data: { label: 'Node 3' }, position: { x: 400, y: 100 }, className: 'light' }, + { id: '4', data: { label: 'Node 4' }, position: { x: 400, y: 200 }, className: 'light' }, +]; + +const initialEdges: Edge[] = [ + { id: 'e1-2', source: '1', target: '2', animated: true }, + { id: 'e1-3', source: '1', target: '3' }, +]; + +const defaultEdgeOptions = { zIndex: 0 }; + +const BasicFlow = () => { + const instance = useReactFlow(); + const spaceBarPressed = useKeyPress('Space'); + + const updatePos = () => { + instance.setNodes((nodes) => + nodes.map((node) => { + node.position = { + x: Math.random() * 400, + y: Math.random() * 400, + }; + + return node; + }) + ); + }; + + const logToObject = () => console.log(instance.toObject()); + const resetTransform = () => instance.setViewport({ x: 0, y: 0, zoom: 1 }); + + const toggleClassnames = () => { + instance.setNodes((nodes) => + nodes.map((node) => { + node.className = node.className === 'light' ? 'dark' : 'light'; + + return node; + }) + ); + }; + + return ( + + + +
+ + + + +
+
+ ); +}; + +export default function App() { + return ( + + + + ); +}