Skip to content

Commit

Permalink
style(nodes): default styles
Browse files Browse the repository at this point in the history
  • Loading branch information
moklick committed Jul 25, 2019
1 parent 7de43f7 commit 97971de
Show file tree
Hide file tree
Showing 7 changed files with 37 additions and 20 deletions.
10 changes: 5 additions & 5 deletions example/SimpleGraph.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,17 +40,17 @@ class App extends PureComponent {

this.state = {
elements: [
{ id: '1', type: 'input', data: { label: 'Tests' }, position: { x: 50, y: 50 } },
{ id: '1', type: 'input', data: { label: 'Tests' }, position: { x: 250, y: 5 } },
{ id: '2', data: { label: 'This is a node This is a node This is a node This is a node' }, position: { x: 100, y: 100 } },
{ id: '3', data: { label: 'This is a node' }, position: { x: 100, y: 200 }, style: { background: '#222', color: '#fff' } },
{ id: '3', data: { label: 'I bring my own style' }, position: { x: 100, y: 200 }, style: { background: '#eee', color: '#222', border: '1px solid #bbb' } },
{ id: '4', type: 'output', data: { label: 'nody nodes' }, position: { x: 50, y: 300 } },
{ id: '5', type: 'default', data: { label: 'Another node'}, position: { x: 400, y: 300 } },
{ id: '6', type: 'special', onChange, data: { label: 'no option selected' }, position: { x: 400, y: 400 } },
{ source: '1', target: '2', type: 'bezier', animated: true, style: { stroke: 'orange' } },
{ id: '6', type: 'special', onChange, data: { label: 'no option selected' }, position: { x: 425, y: 400 } },
{ source: '1', target: '2', animated: true },
{ source: '2', target: '3' },
{ source: '3', target: '4' },
{ source: '3', target: '5' },
{ source: '5', target: '6' }
{ source: '5', target: '6', type: 'straight', animated: true, style: { stroke: '#FFCC00' } }
]
};
}
Expand Down
2 changes: 1 addition & 1 deletion example/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<link rel="stylesheet" type="text/css" href="../dist/ReactGraph.css">
<!--<link rel="stylesheet" type="text/css" href="../dist/ReactGraph.css">-->
<title>Document</title>
<style>
html, body {
Expand Down
14 changes: 13 additions & 1 deletion src/NodeRenderer/Handle/index.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,15 @@
import React from 'react';
import cx from 'classnames';

export default props => <div className="react-graph__handle" {...props} />;
export default (props) => {
const handleClasses = cx(
'react-graph__handle', {
input: props.input,
output: props.output
}
);

return (
<div className={handleClasses} {...props} />
);
};
4 changes: 2 additions & 2 deletions src/NodeRenderer/NodeTypes/DefaultNode.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ const nodeStyles = {

export default ({ data, style }) => (
<div style={{ ...nodeStyles, ...style }}>
<Handle style={{ top: 0 }} />
<Handle input />
{data.label}
<Handle style={{ bottom: 0, top: 'auto', transform: 'translate(-50%, 50%)' }} />
<Handle output />
</div>
);
2 changes: 1 addition & 1 deletion src/NodeRenderer/NodeTypes/InputNode.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,6 @@ export default ({ data, style }) => (
className="react-graph__node-inner"
>
{data.label}
<Handle style={{ bottom: 0, top: 'auto', transform: 'translate(-50%, 50%)' }} />
<Handle output />
</div>
);
4 changes: 2 additions & 2 deletions src/NodeRenderer/NodeTypes/OutputNode.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@ import React from 'react';
import Handle from '../Handle';

const nodeStyles = {
background: '#55ff99',
background: '#55dd99',
padding: 10,
borderRadius: 5,
width: 150
};

export default ({ data, style }) => (
<div style={{ ...nodeStyles, ...style }}>
<Handle style={{ top: 0 }} />
<Handle input />
{data.label}
</div>
);
21 changes: 13 additions & 8 deletions src/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,12 @@

.react-graph__edge {
fill: none;
stroke: #333;
stroke: #bbb;
stroke-width: 2;
pointer-events: all;

&.selected {
stroke: #ff5050;
stroke: #555;
}

&.animated {
Expand Down Expand Up @@ -90,18 +90,23 @@
}

&.selected > * {
box-shadow: 0 0 0 2px #000;
box-shadow: 0 0 0 2px #555;
}
}

.react-graph__handle {
position: absolute;
width: 12px;
height: 12px;
transform: translate(-50%, -50%);
background: #222;
width: 10px;
height: 5px;
transform: translate(-50%, 0);
background: rgba(255, 255, 255, 0.4);
left: 50%;
border-radius: 50%;
top: 0;

&.output {
top: auto;
bottom: 0;
}
}

.react-graph__nodesselection {
Expand Down

0 comments on commit 97971de

Please sign in to comment.