Updated with latest version of react boilerplate
This commit is contained in:
@@ -1,59 +0,0 @@
|
||||
/** @jsx React.DOM */
|
||||
var React = require('react');
|
||||
var flux = require('flux-react');
|
||||
var actions = require('./../actions.js');
|
||||
var ColoredCheckbox = require('./Checkboxes/ColoredCheckbox.js');
|
||||
var CheckboxStore = require('../stores/CheckboxStore.js');
|
||||
|
||||
var Checkboxes = React.createClass({
|
||||
stores: [CheckboxStore],
|
||||
getInitialState: function () {
|
||||
return {
|
||||
checkboxes: CheckboxStore.getCheckboxes()
|
||||
};
|
||||
},
|
||||
componentWillMount: function () {
|
||||
CheckboxStore.addChangeListener(this.update);
|
||||
},
|
||||
componentWillUnmount: function () {
|
||||
CheckboxStore.removeChangeListener(this.update);
|
||||
},
|
||||
update: function () {
|
||||
this.setState({
|
||||
checkboxes: CheckboxStore.getCheckboxes()
|
||||
});
|
||||
},
|
||||
check: function (color) {
|
||||
actions.check(color);
|
||||
},
|
||||
checkAll: function () {
|
||||
actions.checkAll();
|
||||
},
|
||||
uncheckAll: function () {
|
||||
actions.uncheckAll();
|
||||
},
|
||||
renderCheckbox: function (checkbox, index) {
|
||||
return <ColoredCheckbox
|
||||
key={index}
|
||||
color={checkbox.color}
|
||||
checked={checkbox.checked}
|
||||
onChange={this.check}/>
|
||||
},
|
||||
render: function() {
|
||||
var checkboxes = this.state.checkboxes.map(this.renderCheckbox);
|
||||
return (
|
||||
<div>
|
||||
<div>
|
||||
{checkboxes}
|
||||
</div>
|
||||
<div>
|
||||
<button onClick={this.checkAll}>Check all</button>
|
||||
<button onClick={this.uncheckAll}>Uncheck all</button>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
module.exports = Checkboxes;
|
||||
@@ -1,24 +0,0 @@
|
||||
/** @jsx React.DOM */
|
||||
var React = require('react');
|
||||
|
||||
var ColoredCheckbox = React.createClass({
|
||||
changeColor: function () {
|
||||
this.props.onChange(this.props.color);
|
||||
},
|
||||
render: function() {
|
||||
var style = {
|
||||
backgroundColor: this.props.color,
|
||||
padding: '5px'
|
||||
};
|
||||
return (
|
||||
<span key={this.props.key} style={style}>
|
||||
<input type="checkbox"
|
||||
onChange={this.changeColor}
|
||||
checked={this.props.checked}/>
|
||||
</span>
|
||||
);
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
module.exports = ColoredCheckbox;
|
||||
@@ -1,48 +0,0 @@
|
||||
/** @jsx React.DOM */
|
||||
var React = require('react');
|
||||
var CheckboxStore = require('../stores/CheckboxStore.js');
|
||||
|
||||
var NameThrower = React.createClass({
|
||||
getInitialState: function () {
|
||||
return {
|
||||
name: '',
|
||||
colors: CheckboxStore.getColors()
|
||||
};
|
||||
},
|
||||
componentWillMount: function () {
|
||||
CheckboxStore.addChangeListener(this.update);
|
||||
},
|
||||
componentWillUnmount: function () {
|
||||
CheckboxStore.removeChangeListener(this.update);
|
||||
},
|
||||
update: function () {
|
||||
this.setState({
|
||||
colors: CheckboxStore.getColors()
|
||||
});
|
||||
},
|
||||
updateName: function (event) {
|
||||
this.setState({
|
||||
name: event.target.value
|
||||
});
|
||||
},
|
||||
renderColors: function (color, index) {
|
||||
var style = {color: color};
|
||||
return <div key={index} style={style}>{this.state.name}</div>
|
||||
},
|
||||
render: function() {
|
||||
var names = this.state.colors.map(this.renderColors);
|
||||
return (
|
||||
<div>
|
||||
<div>
|
||||
<input type="text" value={this.state.name} onChange={this.updateName}/>
|
||||
</div>
|
||||
<div>
|
||||
{names}
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
module.exports = NameThrower;
|
||||
Reference in New Issue
Block a user