Skip to content

Commit 5abef80

Browse files
committed
Extract 'getFillColor' function to utils
1 parent d615c9f commit 5abef80

File tree

6 files changed

+31
-12
lines changed

6 files changed

+31
-12
lines changed

src/components/Pipe.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,14 @@ import React, { PropTypes, Component } from 'react'
22
import { Group, Path, Shape } from 'react-art'
33

44
import Constants from './constants'
5+
import { getFillColor } from '../utils'
56
import { PositionPropTypes } from '../propTypes'
67

78
class Pipe extends Component {
89
render() {
910
const {
1011
inputPosition,
12+
fillColor: maybeFillColor,
1113
strokeColor: maybeStrokeColor,
1214
outputPosition,
1315
type
@@ -22,7 +24,7 @@ class Pipe extends Component {
2224
x: outputPosition.x - inputPosition.x,
2325
y: outputPosition.y - (inputPosition.y + SlotConstants.height)
2426
}
25-
const fillColor = PipeConstants.fillColor[type]
27+
const fillColor = maybeFillColor || getFillColor(type)
2628
const strokeColor = maybeStrokeColor || PipeConstants.strokeColor
2729

2830
const path = Path()
@@ -44,6 +46,7 @@ class Pipe extends Component {
4446
}
4547

4648
Pipe.propTypes = {
49+
fillColor: PropTypes.string,
4750
inputPosition: PositionPropTypes.isRequired,
4851
outputPosition: PositionPropTypes.isRequired,
4952
strokeColor: PropTypes.string,

src/components/Primitive.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { Group, Text } from 'react-art'
33

44
import Constants from './constants'
55
import Ellipse from './Ellipse'
6-
import { innerInputSlotPosition } from '../utils'
6+
import { getFillColor, innerInputSlotPosition } from '../utils'
77
import { PositionPropTypes } from '../propTypes'
88
import Slot from './Slot'
99

@@ -33,7 +33,7 @@ class Primitive extends Component {
3333
} = this.props
3434
const { Primitive: PrimitiveConstants } = Primitive._constants
3535

36-
const fillColor = PrimitiveConstants.fillColor[type]
36+
const fillColor = getFillColor(type, value)
3737
const slotPosition = innerInputSlotPosition(size)
3838

3939
return (

src/components/TestInput.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { Group, Text } from 'react-art'
33

44
import Constants from './constants'
55
import Ellipse from './Ellipse'
6+
import { getFillColor } from '../utils'
67
import Pipe from './Pipe'
78
import { PositionPropTypes } from '../propTypes'
89

@@ -21,7 +22,8 @@ class TestInput extends Component {
2122
Slot: SlotConstants,
2223
TestInput: TestInputConstants
2324
} = TestInput._constants
24-
const fillColor = TestInputConstants.fillColor[type]
25+
26+
const fillColor = getFillColor(type, value)
2527
const position = {
2628
x: slotPosition.x - ((size.width - SlotConstants.width) / 2),
2729
y: slotPosition.y - TestInputConstants.yOffset
@@ -53,10 +55,11 @@ class TestInput extends Component {
5355
{ value === null ? "<NONE>" : value }
5456
</Text>
5557
<Pipe
58+
fillColor={ fillColor }
5659
inputPosition={ inputPipePosition }
57-
type={ type }
5860
outputPosition={ outputPipePosition }
5961
strokeColor={ fillColor }
62+
type={ type }
6063
/>
6164
</Group>
6265
)

src/components/constants.js

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
1-
const colorsForTypes = {
1+
const colors = {
22
boolean: "#A359E9",
3+
False: "#E44B37",
34
list: "#E9E759",
45
null: "#BFBFBF",
56
number: "#E96859",
6-
string: "#E9A559"
7-
// "#59E974"
7+
string: "#E9A559",
8+
True: "#358DE2"
89
}
910
const font = '15px monospace'
1011
const slotWidth = 15
@@ -43,7 +44,6 @@ const MainBrick = {
4344
MainBrick.slotAndOffset = slotWidth + MainBrick.slotOffset
4445

4546
const Pipe = {
46-
fillColor: colorsForTypes,
4747
font: font,
4848
strokeColor: 'black',
4949
textColor: 'black'
@@ -58,7 +58,6 @@ const Primitive = {
5858
height: 30,
5959
width: 60
6060
},
61-
fillColor: colorsForTypes,
6261
font: font,
6362
fontAlignment: 'middle',
6463
textColor: 'black'
@@ -80,7 +79,6 @@ const TestInput = {
8079
height: 30,
8180
width: 60
8281
},
83-
fillColor: colorsForTypes,
8482
font,
8583
textColor: 'black',
8684
yOffset: 60
@@ -90,6 +88,7 @@ const LEFT = 0
9088

9189
export default {
9290
Brick,
91+
colors,
9392
MainBrick,
9493
LEFT,
9594
Pipe,

src/utils/colors.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import { colors } from '../components/constants'
2+
3+
export const getFillColor = (type, value) => {
4+
const typeColor = colors[type]
5+
6+
switch (type) {
7+
case "boolean":
8+
const valueColor = colors[value]
9+
return value && valueColor ? valueColor : typeColor
10+
default:
11+
return typeColor
12+
}
13+
}

src/utils/index.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
import { selectElement } from '../actions'
22
import { LEFT } from '../components/constants'
33

4-
export * from './slotSelection'
4+
export * from './colors'
55
export * from './slotPosition'
6+
export * from './slotSelection'
67

78
export const isNotEmpty = (object) => {
89
return Object.keys(object).length > 0

0 commit comments

Comments
 (0)