Skip to content

Commit

Permalink
docs(example): add select to node
Browse files Browse the repository at this point in the history
  • Loading branch information
moklick committed Jul 17, 2019
1 parent 0e179ff commit a5aa78f
Showing 1 changed file with 20 additions and 9 deletions.
29 changes: 20 additions & 9 deletions example/SimpleGraph.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,11 @@ const SpecialNode = ({ data, styles }) => (
<div
style={{ background: '#FFCC00', padding: 10, borderRadius: 30, ...styles }}
>
I am <strong>special</strong>!<br />{data.label}
<input
style={{ margin: '10px 0' }}
/>
<select>
<option>1</option>
<option>2</option>
<option>3</option>
<div>I am <strong>special</strong>!<br />{data.label}</div>
<select onChange={(e) => data.onChange(e.target.value, data)}>
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
</select>
</div>
);
Expand All @@ -23,14 +20,27 @@ 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 } },
{ data: { id: '2', label: 'This is a node This is a node This is a node This is a node' }, position: { x: 100, y: 100 } },
{ 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' } },
Expand Down Expand Up @@ -72,6 +82,7 @@ class App extends PureComponent {
}

render() {
console.log(this.state.elements);
return (
<Graph
elements={this.state.elements}
Expand Down

0 comments on commit a5aa78f

Please sign in to comment.