Files
old-csveditor/app/components/NameThrower.js

49 lines
1.0 KiB
JavaScript
Raw Normal View History

2014-08-20 19:50:48 +02:00
/** @jsx React.DOM */
2014-10-27 15:28:16 +01:00
var React = require('react');
2014-08-20 19:50:48 +02:00
var CheckboxStore = require('../stores/CheckboxStore.js');
var NameThrower = React.createClass({
getInitialState: function () {
return {
name: '',
colors: CheckboxStore.getColors()
};
},
2014-10-27 15:28:16 +01:00
componentWillMount: function () {
CheckboxStore.addChangeListener(this.update);
},
componentWillUnmount: function () {
CheckboxStore.removeChangeListener(this.update);
},
update: function () {
2014-08-20 19:50:48 +02:00
this.setState({
colors: CheckboxStore.getColors()
});
},
2014-10-27 15:28:16 +01:00
updateName: function (event) {
2014-08-20 19:50:48 +02:00
this.setState({
2014-10-27 15:28:16 +01:00
name: event.target.value
2014-08-20 19:50:48 +02:00
});
},
2014-10-27 15:28:16 +01:00
renderColors: function (color, index) {
2014-08-20 19:50:48 +02:00
var style = {color: color};
return <div key={index} style={style}>{this.state.name}</div>
2014-10-27 15:28:16 +01:00
},
render: function() {
var names = this.state.colors.map(this.renderColors);
2014-08-20 19:50:48 +02:00
return (
<div>
2014-10-27 15:28:16 +01:00
<div>
<input type="text" value={this.state.name} onChange={this.updateName}/>
</div>
<div>
{names}
</div>
2014-08-20 19:50:48 +02:00
</div>
);
}
});
module.exports = NameThrower;