With updated deps
This commit is contained in:
51
app/components/Checkboxes.js
Normal file
51
app/components/Checkboxes.js
Normal file
@@ -0,0 +1,51 @@
|
||||
/** @jsx React.DOM */
|
||||
var React = require('flux-react');
|
||||
var Constants = require('../Constants.js');
|
||||
var ColoredCheckbox = require('./Checkboxes/ColoredCheckbox.js');
|
||||
var CheckboxActions = require('../actions/CheckboxActions.js');
|
||||
var CheckboxStore = require('../stores/CheckboxStore.js');
|
||||
|
||||
var Checkboxes = React.createClass({
|
||||
stores: [CheckboxStore],
|
||||
getInitialState: function () {
|
||||
return {
|
||||
checkboxes: CheckboxStore.getCheckboxes()
|
||||
};
|
||||
},
|
||||
storesDidUpdate: function () {
|
||||
this.setState({
|
||||
checkboxes: CheckboxStore.getCheckboxes()
|
||||
});
|
||||
},
|
||||
check: function (color) {
|
||||
React.dispatch({
|
||||
type: CheckboxActions.CHECK,
|
||||
color: color
|
||||
})
|
||||
},
|
||||
checkAll: function () {
|
||||
React.dispatch({
|
||||
type: CheckboxActions.CHECK_ALL
|
||||
});
|
||||
},
|
||||
uncheckAll: function () {
|
||||
React.dispatch({
|
||||
type: CheckboxActions.UNCHECK_ALL
|
||||
});
|
||||
},
|
||||
render: function() {
|
||||
var checkboxes = this.state.checkboxes.map(function (checkbox, index) {
|
||||
return <ColoredCheckbox key={index} color={checkbox.color} checked={checkbox.checked} onChange={this.check}/>
|
||||
}, this);
|
||||
return (
|
||||
<div>
|
||||
{checkboxes}
|
||||
<button onClick={this.checkAll}>Check all</button>
|
||||
<button onClick={this.uncheckAll}>Uncheck all</button>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
module.exports = Checkboxes;
|
||||
21
app/components/Checkboxes/ColoredCheckbox.js
Normal file
21
app/components/Checkboxes/ColoredCheckbox.js
Normal file
@@ -0,0 +1,21 @@
|
||||
/** @jsx React.DOM */
|
||||
var React = require('flux-react');
|
||||
|
||||
var ColoredCheckbox = React.createClass({
|
||||
render: function() {
|
||||
var style = {
|
||||
backgroundColor: this.props.color,
|
||||
padding: '5px'
|
||||
};
|
||||
return (
|
||||
<span key={this.props.key} style={style}>
|
||||
<input type="checkbox"
|
||||
onChange={this.props.onChange.bind(null, this.props.color)}
|
||||
checked={this.props.checked}/>
|
||||
</span>
|
||||
);
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
module.exports = ColoredCheckbox;
|
||||
39
app/components/NameThrower.js
Normal file
39
app/components/NameThrower.js
Normal file
@@ -0,0 +1,39 @@
|
||||
/** @jsx React.DOM */
|
||||
var React = require('flux-react');
|
||||
var Constants = require('../Constants.js');
|
||||
var CheckboxStore = require('../stores/CheckboxStore.js');
|
||||
|
||||
var NameThrower = React.createClass({
|
||||
stores: [CheckboxStore],
|
||||
getInitialState: function () {
|
||||
return {
|
||||
name: '',
|
||||
colors: CheckboxStore.getColors()
|
||||
};
|
||||
},
|
||||
storesDidUpdate: function () {
|
||||
this.setState({
|
||||
colors: CheckboxStore.getColors()
|
||||
});
|
||||
},
|
||||
updateName: function () {
|
||||
this.setState({
|
||||
name: this.refs.input.getDOMNode().value
|
||||
});
|
||||
},
|
||||
render: function() {
|
||||
var names = this.state.colors.map(function (color, index) {
|
||||
var style = {color: color};
|
||||
return <div key={index} style={style}>{this.state.name}</div>
|
||||
}, this);
|
||||
return (
|
||||
<div>
|
||||
<input ref="input" type="text" value={this.state.name} onChange={this.updateName}/>
|
||||
{names}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
module.exports = NameThrower;
|
||||
Reference in New Issue
Block a user