style(nodes): default styles

This commit is contained in:
moklick
2019-07-25 17:11:34 +02:00
parent 7de43f7843
commit 97971de1a5
7 changed files with 37 additions and 20 deletions
+5 -5
View File
@@ -40,17 +40,17 @@ class App extends PureComponent {
this.state = { this.state = {
elements: [ 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: '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: '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: '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 } }, { id: '6', type: 'special', onChange, data: { label: 'no option selected' }, position: { x: 425, y: 400 } },
{ source: '1', target: '2', type: 'bezier', animated: true, style: { stroke: 'orange' } }, { source: '1', target: '2', animated: true },
{ source: '2', target: '3' }, { source: '2', target: '3' },
{ source: '3', target: '4' }, { source: '3', target: '4' },
{ source: '3', target: '5' }, { source: '3', target: '5' },
{ source: '5', target: '6' } { source: '5', target: '6', type: 'straight', animated: true, style: { stroke: '#FFCC00' } }
] ]
}; };
} }
+1 -1
View File
@@ -4,7 +4,7 @@
<meta charset="UTF-8"> <meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0"> <meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge"> <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> <title>Document</title>
<style> <style>
html, body { html, body {
+13 -1
View File
@@ -1,3 +1,15 @@
import React from 'react'; 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} />
);
};
+2 -2
View File
@@ -11,8 +11,8 @@ const nodeStyles = {
export default ({ data, style }) => ( export default ({ data, style }) => (
<div style={{ ...nodeStyles, ...style }}> <div style={{ ...nodeStyles, ...style }}>
<Handle style={{ top: 0 }} /> <Handle input />
{data.label} {data.label}
<Handle style={{ bottom: 0, top: 'auto', transform: 'translate(-50%, 50%)' }} /> <Handle output />
</div> </div>
); );
+1 -1
View File
@@ -15,6 +15,6 @@ export default ({ data, style }) => (
className="react-graph__node-inner" className="react-graph__node-inner"
> >
{data.label} {data.label}
<Handle style={{ bottom: 0, top: 'auto', transform: 'translate(-50%, 50%)' }} /> <Handle output />
</div> </div>
); );
+2 -2
View File
@@ -3,7 +3,7 @@ import React from 'react';
import Handle from '../Handle'; import Handle from '../Handle';
const nodeStyles = { const nodeStyles = {
background: '#55ff99', background: '#55dd99',
padding: 10, padding: 10,
borderRadius: 5, borderRadius: 5,
width: 150 width: 150
@@ -11,7 +11,7 @@ const nodeStyles = {
export default ({ data, style }) => ( export default ({ data, style }) => (
<div style={{ ...nodeStyles, ...style }}> <div style={{ ...nodeStyles, ...style }}>
<Handle style={{ top: 0 }} /> <Handle input />
{data.label} {data.label}
</div> </div>
); );
+13 -8
View File
@@ -47,12 +47,12 @@
.react-graph__edge { .react-graph__edge {
fill: none; fill: none;
stroke: #333; stroke: #bbb;
stroke-width: 2; stroke-width: 2;
pointer-events: all; pointer-events: all;
&.selected { &.selected {
stroke: #ff5050; stroke: #555;
} }
&.animated { &.animated {
@@ -90,18 +90,23 @@
} }
&.selected > * { &.selected > * {
box-shadow: 0 0 0 2px #000; box-shadow: 0 0 0 2px #555;
} }
} }
.react-graph__handle { .react-graph__handle {
position: absolute; position: absolute;
width: 12px; width: 10px;
height: 12px; height: 5px;
transform: translate(-50%, -50%); transform: translate(-50%, 0);
background: #222; background: rgba(255, 255, 255, 0.4);
left: 50%; left: 50%;
border-radius: 50%; top: 0;
&.output {
top: auto;
bottom: 0;
}
} }
.react-graph__nodesselection { .react-graph__nodesselection {