Skip to Content

Tailwind

In this example we are using Tailwind  for styling the flow.

Import the React Flow stylesheet into the base layer so that Tailwind can override the default styles.

index.css
@import '@xyflow/react/dist/style.css' layer(base); @import 'tailwindcss';
import { useCallback } from 'react'; import { ReactFlow, useNodesState, useEdgesState, addEdge, MiniMap, Controls, } from '@xyflow/react'; import './index.css'; import CustomNode from './CustomNode'; const nodeTypes = { custom: CustomNode, }; const initNodes = [ { id: '1', type: 'custom', data: { name: 'Jane Doe', job: 'CEO', emoji: '😎' }, position: { x: 0, y: 50 }, }, { id: '2', type: 'custom', data: { name: 'Tyler Weary', job: 'Designer', emoji: '🤓' }, position: { x: -200, y: 200 }, }, { id: '3', type: 'custom', data: { name: 'Kristi Price', job: 'Developer', emoji: '🤩' }, position: { x: 200, y: 200 }, }, ]; const initEdges = [ { id: 'e1-2', source: '1', target: '2', }, { id: 'e1-3', source: '1', target: '3', }, ]; const Flow = () => { const [nodes, setNodes, onNodesChange] = useNodesState(initNodes); const [edges, setEdges, onEdgesChange] = useEdgesState(initEdges); const onConnect = useCallback((params) => setEdges((eds) => addEdge(params, eds)), []); return ( <ReactFlow nodes={nodes} edges={edges} onNodesChange={onNodesChange} onEdgesChange={onEdgesChange} onConnect={onConnect} nodeTypes={nodeTypes} fitView className="bg-teal-50 dark:bg-gray-900" colorMode="system" > <MiniMap /> <Controls /> </ReactFlow> ); }; export default Flow;
Last updated on