1
- import React , { PropTypes , Component } from 'react'
1
+ import React , { PropTypes , Component , PureComponent } from 'react'
2
2
3
- import { getModeIcon , isTransit } from '../../util/itinerary'
3
+ import { getIcon , isTransit } from '../../util/itinerary'
4
4
5
5
export default class ModeButton extends Component {
6
6
static propTypes = {
@@ -11,13 +11,12 @@ export default class ModeButton extends Component {
11
11
onClick : PropTypes . func
12
12
}
13
13
14
- render ( ) {
15
- const { active, enabled, icons, label, mode, onClick, inlineLabel, showPlusTransit} = this . props
16
- const height = this . props . height || 48
17
- const iconSize = height - 20
18
-
19
- const iconColor = enabled ? '#000' : '#ccc'
20
- const modeStr = mode . mode || mode
14
+ _getButtonStyle ( {
15
+ active,
16
+ enabled,
17
+ height,
18
+ modeStr
19
+ } ) {
21
20
const buttonStyle = { height }
22
21
23
22
if ( modeStr !== 'TRANSIT' && isTransit ( modeStr ) ) {
@@ -30,42 +29,124 @@ export default class ModeButton extends Component {
30
29
if ( active ) buttonStyle . backgroundColor = '#add8e6'
31
30
}
32
31
32
+ return buttonStyle
33
+ }
34
+
35
+ render ( ) {
36
+ const {
37
+ active,
38
+ enabled,
39
+ icons,
40
+ label,
41
+ mode,
42
+ onClick,
43
+ inlineLabel,
44
+ showPlusTransit
45
+ } = this . props
46
+ const height = this . props . height || 48
47
+ const iconSize = height - 20
48
+ const iconColor = enabled ? '#000' : '#ccc'
49
+ const modeStr = mode . company || mode . mode || mode
50
+ const buttonStyle = this . _getButtonStyle ( { active, enabled, height, modeStr } )
51
+
33
52
return (
34
- < div className = { `mode-button-container ${ enabled ? 'enabled' : 'disabled' } ` } style = { { height : height + ( inlineLabel ? 8 : 24 ) , textAlign : 'center' } } >
53
+ < div
54
+ className = { `mode-button-container ${ enabled ? 'enabled' : 'disabled' } ` }
55
+ style = { { height : height + ( inlineLabel ? 8 : 24 ) , textAlign : 'center' } }
56
+ >
35
57
< button
36
58
className = 'mode-button'
37
59
onClick = { onClick }
38
60
title = { label }
39
61
style = { buttonStyle }
40
62
disabled = { ! enabled }
41
63
>
42
- { /* Show the 'plus' and general transit icons, if enabled */ }
43
64
{ showPlusTransit && (
44
- < span >
45
- < div style = { { display : 'inline-block' , width : iconSize , height : iconSize , verticalAlign : 'middle' } } >
46
- { enabled
47
- ? getModeIcon ( 'TRANSIT' , icons )
48
- : < div style = { { width : iconSize , height : iconSize , backgroundColor : iconColor , borderRadius : iconSize / 2 } } />
49
- }
50
- </ div >
51
- < i className = 'fa fa-plus' style = { { verticalAlign : 'middle' , color : iconColor , margin : '0px 5px' , fontSize : 14 } } />
52
- </ span >
65
+ < PlusTransit
66
+ enabled = { enabled }
67
+ iconColor = { iconColor }
68
+ icons = { icons }
69
+ iconSize = { iconSize }
70
+ />
53
71
) }
54
72
55
73
{ /* Show the primary mode icon */ }
56
74
< div
57
75
className = 'mode-icon'
58
- style = { { display : 'inline-block' , fill : iconColor , width : iconSize , height : iconSize , verticalAlign : 'middle' } } >
59
- { getModeIcon ( mode , icons ) }
76
+ style = { {
77
+ display : 'inline-block' ,
78
+ fill : iconColor ,
79
+ width : iconSize ,
80
+ height : iconSize ,
81
+ verticalAlign : 'middle'
82
+ } }
83
+ >
84
+ { getIcon ( modeStr , icons ) }
60
85
</ div >
61
86
62
87
{ /* Show the inline label, if enabled */ }
63
- { inlineLabel && < span style = { { fontSize : iconSize * 0.8 , marginLeft : 10 , verticalAlign : 'middle' , fontWeight : active ? 600 : 300 } } > { label } </ span > }
88
+ { inlineLabel && (
89
+ < span style = { {
90
+ fontSize : iconSize * 0.8 ,
91
+ marginLeft : 10 ,
92
+ verticalAlign : 'middle' ,
93
+ fontWeight : active ? 600 : 300
94
+ } }
95
+ >
96
+ { label }
97
+ </ span >
98
+ ) }
64
99
</ button >
65
100
66
101
{ /* If not in inline-label mode, label directly below the button */ }
67
- { ! inlineLabel && < div className = 'mode-label' style = { { color : iconColor , fontWeight : active ? 600 : 300 } } > { label } </ div > }
102
+ { ! inlineLabel && (
103
+ < div
104
+ className = 'mode-label'
105
+ style = { { color : iconColor , fontWeight : active ? 600 : 300 } }
106
+ >
107
+ { label }
108
+ </ div >
109
+ ) }
68
110
</ div >
69
111
)
70
112
}
71
113
}
114
+
115
+ class PlusTransit extends PureComponent {
116
+ render ( ) {
117
+ const { enabled, iconColor, icons, iconSize} = this . props
118
+ return (
119
+ < span >
120
+ < div
121
+ style = { {
122
+ display : 'inline-block' ,
123
+ width : iconSize ,
124
+ height : iconSize ,
125
+ verticalAlign : 'middle'
126
+ } }
127
+ >
128
+ { enabled
129
+ ? getIcon ( 'TRANSIT' , icons )
130
+ : (
131
+ < div style = { {
132
+ width : iconSize ,
133
+ height : iconSize ,
134
+ backgroundColor : iconColor ,
135
+ borderRadius : iconSize / 2
136
+ } } />
137
+ )
138
+ }
139
+ </ div >
140
+ < i
141
+ className = 'fa fa-plus'
142
+ style = { {
143
+ verticalAlign : 'middle' ,
144
+ color : iconColor ,
145
+ margin : '0px 5px' ,
146
+ fontSize : 14
147
+ } }
148
+ />
149
+ </ span >
150
+ )
151
+ }
152
+ }
0 commit comments