From a5aa78f02a5056dfa1e57170ec632a6f33f80451 Mon Sep 17 00:00:00 2001 From: moklick Date: Wed, 17 Jul 2019 10:25:38 +0200 Subject: [PATCH] docs(example): add select to node --- example/SimpleGraph.js | 29 ++++++++++++++++++++--------- 1 file changed, 20 insertions(+), 9 deletions(-) diff --git a/example/SimpleGraph.js b/example/SimpleGraph.js index 1bdf9fdd..16635420 100644 --- a/example/SimpleGraph.js +++ b/example/SimpleGraph.js @@ -7,14 +7,11 @@ const SpecialNode = ({ data, styles }) => (
- I am special!
{data.label} - - data.onChange(e.target.value, data)}> + + +
); @@ -23,6 +20,19 @@ class App extends PureComponent { constructor() { super(); + const onChange = (id, d) => { + this.setState(prevState => ( + { elements: prevState.elements.map(e => ({ + ...e, + data: { + ...e.data, + label: '6' === e.data.id ? `option ${id} selected` : e.data.label + } + })) + } + )); + } + this.state = { elements: [ { data: { id: '1', label: 'Tests', type: 'input' }, position: { x: 50, y: 50 } }, @@ -30,7 +40,7 @@ class App extends PureComponent { { data: { id: '3', label: 'This is a node' }, position: { x: 100, y: 200 }, style: { background: '#222', color: '#fff' } }, { data: { id: '4', label: 'nody nodes', type: 'output' }, position: { x: 50, y: 300 } }, { data: { id: '5', label: 'Another node', type: 'default' }, position: { x: 400, y: 300 } }, - { data: { id: '6', label: 'I have inputs', type: 'special' }, position: { x: 400, y: 400 } }, + { data: { id: '6', label: 'no option selected', type: 'special', onChange }, position: { x: 400, y: 400 } }, { data: { source: '1', target: '2' } }, { data: { source: '2', target: '3' } }, { data: { source: '3', target: '4' } }, @@ -72,6 +82,7 @@ class App extends PureComponent { } render() { + console.log(this.state.elements); return (