We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
npm install react-flow-renderer react-beautiful-dnd
import React from 'react'; import ReactFlow, { Handle } from 'react-flow-renderer'; import { DragDropContext, Droppable, Draggable } from 'react-beautiful-dnd'; const onDragEnd = (result, items, setItems) => { if (!result.destination) return; const reorderedItems = Array.from(items); const [removed] = reorderedItems.splice(result.source.index, 1); reorderedItems.splice(result.destination.index, 0, removed); setItems(reorderedItems); }; const CustomNode = ({ data }) => { const [items, setItems] = React.useState(data.items); return ( <div className="custom-node"> <Handle type="target" position="top" /> <DragDropContext onDragEnd={(result) => onDragEnd(result, items, setItems)}> <Droppable droppableId="droppable"> {(provided) => ( <div {...provided.droppableProps} ref={provided.innerRef}> {items.map((item, index) => ( <Draggable key={item.id} draggableId={item.id} index={index}> {(provided) => ( <div ref={provided.innerRef} {...provided.draggableProps} {...provided.dragHandleProps} className="draggable-item" > {item.content} </div> )} </Draggable> ))} {provided.placeholder} </div> )} </Droppable> </DragDropContext> <Handle type="source" position="bottom" /> </div> ); }; const initialElements = [ { id: '1', type: 'customNode', position: { x: 100, y: 100 }, data: { items: [ { id: 'item-1', content: 'Item 1' }, { id: 'item-2', content: 'Item 2' }, { id: 'item-3', content: 'Item 3' }, ], }, }, ]; const App = () => { return ( <ReactFlow elements={initialElements} nodeTypes={{ customNode: CustomNode }} style={{ width: '100%', height: '100vh' }} /> ); }; export default App;
The text was updated successfully, but these errors were encountered:
No branches or pull requests
The text was updated successfully, but these errors were encountered: