diff --git a/examples/react/src/examples/DevTools/ReactFlowDevTools/ChangeLogger.tsx b/examples/react/src/examples/DevTools/DevTools/ChangeLogger.tsx similarity index 77% rename from examples/react/src/examples/DevTools/ReactFlowDevTools/ChangeLogger.tsx rename to examples/react/src/examples/DevTools/DevTools/ChangeLogger.tsx index 4593ba28..d4fffcda 100644 --- a/examples/react/src/examples/DevTools/ReactFlowDevTools/ChangeLogger.tsx +++ b/examples/react/src/examples/DevTools/DevTools/ChangeLogger.tsx @@ -29,7 +29,7 @@ function ChangeInfo({ change }: ChangeInfoProps) { ); } -export default function ChangeLogger({ color = '#555', limit = 20 }: ChangeLoggerProps) { +export default function ChangeLogger({ limit = 20 }: ChangeLoggerProps) { const [changes, setChanges] = useState([]); const onNodesChangeIntercepted = useRef(false); const onNodesChange = useStore((s) => s.onNodesChange); @@ -62,19 +62,13 @@ export default function ChangeLogger({ color = '#555', limit = 20 }: ChangeLogge }, [onNodesChange]); return ( -
-
- Change Logger -
-
- {changes.length === 0 ? ( - <>no changes triggered - ) : ( - changes.map((change, index) => ) - )} -
+
+
Change Logger
+ {changes.length === 0 ? ( + <>no changes triggered + ) : ( + changes.map((change, index) => ) + )}
); } diff --git a/examples/react/src/examples/DevTools/ReactFlowDevTools/NodeInspector.tsx b/examples/react/src/examples/DevTools/DevTools/NodeInspector.tsx similarity index 82% rename from examples/react/src/examples/DevTools/ReactFlowDevTools/NodeInspector.tsx rename to examples/react/src/examples/DevTools/DevTools/NodeInspector.tsx index ae07029a..5d467514 100644 --- a/examples/react/src/examples/DevTools/ReactFlowDevTools/NodeInspector.tsx +++ b/examples/react/src/examples/DevTools/DevTools/NodeInspector.tsx @@ -12,17 +12,15 @@ type NodeInfoProps = { function NodeInfo({ id, type, x, y, width, height, data }: NodeInfoProps) { if (!width || !height) { - return
; + return null; } return (
@@ -39,16 +37,12 @@ function NodeInfo({ id, type, x, y, width, height, data }: NodeInfoProps) { ); } -type NodeInspectorProps = { - color: string; -}; - -export default function NodeInspector({ color = '#555' }: NodeInspectorProps) { +export default function NodeInspector() { const nodes = useNodes(); return ( -
+
{nodes.map((node) => { const x = node.computed?.positionAbsolute?.x || 0; const y = node.computed?.positionAbsolute?.y || 0; diff --git a/examples/react/src/examples/DevTools/DevTools/index.tsx b/examples/react/src/examples/DevTools/DevTools/index.tsx new file mode 100644 index 00000000..107d0078 --- /dev/null +++ b/examples/react/src/examples/DevTools/DevTools/index.tsx @@ -0,0 +1,42 @@ +import { useState, type Dispatch, type SetStateAction, type ReactNode, HTMLAttributes } from 'react'; +import { Panel } from '@xyflow/react'; + +import NodeInspector from './NodeInspector'; +import ChangeLogger from './ChangeLogger'; + +export default function ReactFlowDevTools() { + const [nodeInspectorActive, setNodeInspectorActive] = useState(false); + const [changeLoggerActive, setChangeLoggerActive] = useState(false); + + return ( +
+ + + Node Inspector + + + Change Logger + + + {changeLoggerActive && } + {nodeInspectorActive && } +
+ ); +} + +function DevToolButton({ + active, + setActive, + children, + ...rest +}: { + active: boolean; + setActive: Dispatch>; + children: ReactNode; +} & HTMLAttributes) { + return ( + + ); +} diff --git a/examples/react/src/examples/DevTools/DevTools/style.css b/examples/react/src/examples/DevTools/DevTools/style.css new file mode 100644 index 00000000..39c65969 --- /dev/null +++ b/examples/react/src/examples/DevTools/DevTools/style.css @@ -0,0 +1,63 @@ +.react-flow__devtools { + --border-radius: 4px; + --highlight-color: rgba(238, 58, 115, 1); + --font: monospace, sans-serif; + + border-radius: var(--border-radius); + font-size: 11px; + font-family: var(--font); +} + +.react-flow__devtools button { + background: white; + border: none; + padding: 5px 15px; + color: #222; + font-weight: bold; + font-size: 12px; + cursor: pointer; + font-family: var(--font); + background-color: #f4f4f4; +} + +.react-flow__devtools button:hover { + background: var(--highlight-color); + color: white; +} + +.react-flow__devtools button.active { + background: var(--highlight-color); + color: white; +} + +.react-flow__devtools button:first-child { + border-radius: var(--border-radius) 0 0 var(--border-radius); + border-right: 1px solid #ddd; +} + +.react-flow__devtools button:last-child { + border-radius: 0 var(--border-radius) var(--border-radius) 0; +} + +.react-flow__devtools-changelogger { + pointer-events: none; + position: relative; + top: 50px; + left: 20px; + font-family: var(--font); +} + +.react-flow__devtools-title { + font-weight: bold; + margin-bottom: 5px; +} + +.react-flow__devtools-nodeinspector { + pointer-events: none; + font-family: monospace, sans-serif; + font-size: 10px; +} + +.react-flow__devtools-nodeinfo { + top: 5px; +} diff --git a/examples/react/src/examples/DevTools/ReactFlowDevTools/index.tsx b/examples/react/src/examples/DevTools/ReactFlowDevTools/index.tsx deleted file mode 100644 index 2b488b7c..00000000 --- a/examples/react/src/examples/DevTools/ReactFlowDevTools/index.tsx +++ /dev/null @@ -1,26 +0,0 @@ -import { useState } from 'react'; -import { Panel, PanelPosition } from '@xyflow/react'; - -import NodeInspector from './NodeInspector'; -import ChangeLogger from './ChangeLogger'; - -type ReactFlowDevToolsProps = { - position?: PanelPosition; - color?: string; -}; - -export default function ReactFlowDevTools({ color = '#aaa', position = 'top-left' }: ReactFlowDevToolsProps) { - const [isNodeInspectorActive, setIsNodeInspectorActive] = useState(false); - const [isChangeLoggerActive, setIsChangeLoggerActive] = useState(false); - - return ( - <> - - - - - {isNodeInspectorActive && } - {isChangeLoggerActive && } - - ); -} diff --git a/examples/react/src/examples/DevTools/index.tsx b/examples/react/src/examples/DevTools/index.tsx index 153b0897..5303dea6 100644 --- a/examples/react/src/examples/DevTools/index.tsx +++ b/examples/react/src/examples/DevTools/index.tsx @@ -1,6 +1,8 @@ import { useCallback } from 'react'; import { ReactFlow, addEdge, Node, Connection, Edge, useNodesState, useEdgesState } from '@xyflow/react'; -import ReactFlowDevTools from './ReactFlowDevTools'; + +import DevTools from './DevTools'; +import './Devtools/style.css'; const initNodes: Node[] = [ { @@ -8,32 +10,26 @@ const initNodes: Node[] = [ type: 'input', data: { label: 'Node 1' }, position: { x: 250, y: 5 }, - className: 'light', - ariaLabel: 'Input Node 1', }, { id: '2a', data: { label: 'Node 2' }, position: { x: 100, y: 100 }, - className: 'light', - ariaLabel: 'Default Node 2', }, { id: '3a', data: { label: 'Node 3' }, position: { x: 400, y: 100 }, - className: 'light', }, { id: '4a', data: { label: 'Node 4' }, position: { x: 400, y: 200 }, - className: 'light', }, ]; const initEdges: Edge[] = [ - { id: 'e1-2', source: '1a', target: '2a', ariaLabel: undefined }, + { id: 'e1-2', source: '1a', target: '2a' }, { id: 'e1-3', source: '1a', target: '3a' }, ]; @@ -50,8 +46,9 @@ const BasicFlow = () => { onNodesChange={onNodesChange} onEdgesChange={onEdgesChange} onConnect={onConnect} + fitView > - + ); };