Skip to content

Commit 7f17239

Browse files
author
David Emory
committed
feat(form): Enhancements to ModeSelector for TriMet mobile UI
Allow custom label for ModeSelector. Translate OTP mode strings to user-friendly text.
1 parent ec006ea commit 7f17239

File tree

1 file changed

+22
-3
lines changed

1 file changed

+22
-3
lines changed

lib/components/form/mode-selector.js

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,25 +9,44 @@ class ModeSelector extends Component {
99
location: PropTypes.object,
1010
label: PropTypes.string,
1111
setLocation: PropTypes.func,
12+
showLabel: PropTypes.boolean,
1213
type: PropTypes.string // replace with locationType?
1314
}
15+
1416
_onChange = (evt) => {
1517
console.log(evt.target.value)
1618
this.props.setMode(evt.target.value)
1719
}
20+
21+
_getDisplayText (mode) {
22+
switch (mode) {
23+
case 'TRANSIT,WALK': return 'Walk to Transit'
24+
case 'TRANSIT,BICYCLE': return 'Bike to Transit'
25+
case 'WALK': return 'Walk Only'
26+
case 'BICYCLE': return 'Bike Only'
27+
}
28+
return mode
29+
}
30+
1831
render () {
1932
const { config, mode } = this.props
33+
const label = this.props.label || 'Mode:'
34+
const showLabel = this.props.showLabel === undefined ? true : this.props.showLabel
35+
2036
return (
2137
<form>
22-
<FormGroup>
23-
<ControlLabel>Mode:</ControlLabel>
38+
<FormGroup className='mode-selector'>
39+
{showLabel
40+
? <ControlLabel>{label}</ControlLabel>
41+
: null
42+
}
2443
<FormControl
2544
componentClass='select'
2645
value={mode}
2746
onChange={this._onChange}
2847
>
2948
{config.modes.map((m, i) => (
30-
<option key={i} value={m}>{m}</option>
49+
<option key={i} value={m}>{this._getDisplayText(m)}</option>
3150
))}
3251
</FormControl>
3352
</FormGroup>

0 commit comments

Comments
 (0)