-
Notifications
You must be signed in to change notification settings - Fork 358
Expand file tree
/
Copy pathconfig_form.js
More file actions
78 lines (67 loc) · 2.19 KB
/
config_form.js
File metadata and controls
78 lines (67 loc) · 2.19 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
/** @jsx React.DOM */
var ConfigForm = React.createClass({
propTypes: {
onConfigChange: React.PropTypes.func.isRequired
},
/**
@method getInitialState
@return {Object}
**/
getInitialState: function () {
return this.props.config;
},
/**
@method render
@return {ReactComponent}
**/
render: function () {
var change = function (propName) {
return this.handleChange.bind(this, propName);
}.bind(this);
var isPositionChecked = function (pos) {
return this.state.position === pos;
}.bind(this);
return (
<form className='config'>
<ol>
<li>
<input type='radio' value='top' name='position' onChange={change('position')} checked={isPositionChecked('top')}/>
</li>
<li>
<input type='radio' value='right' name='position' onChange={change('position')} checked={isPositionChecked('right')} />
</li>
<li>
<input type='radio' value='bottom' name='position' onChange={change('position')} checked={isPositionChecked('bottom')} />
</li>
<li>
<input type='radio' value='left' name='position' onChange={change('position')} checked={isPositionChecked('left')} />
</li>
<li className='with-input'>
<input type='text' onChange={change('size')} value={this.state.size} />
</li>
<li className='with-input'>
<input type='text' onChange={change('color')} value={this.state.color} />
</li>
<li className='with-input'>
<input type='text' onChange={change('borderSize')} value={this.state.borderSize} />
</li>
<li className='with-input'>
<input type='text' onChange={change('borderColor')} value={this.state.borderColor} />
</li>
</ol>
</form>
);
},
handleChange: function (propName, ev) {
var nextState = {},
val = ev.target.value;
if (val && propName.indexOf('ize') !== -1) {
val = parseInt(val, 10);
}
nextState[propName] = val;
this.setState(nextState, function () {
this.props.onConfigChange(this.state);
}.bind(this));
}
});
module.exports = ConfigForm;