-
Notifications
You must be signed in to change notification settings - Fork 0
/
Task.jsx
40 lines (35 loc) · 1 KB
/
Task.jsx
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
// Task component - represents a single todo item
Task = React.createClass({
propTypes: {
// This component gets the task to display throught a React prop.
// We can use propTypes to indicate it is required
task: React.PropTypes.object.isRequired
},
toggleChecked(){
// Set the checked property to the opposite of its current value
Tasks.update(this.props.task._id, {
$set: {checked: ! this.props.task.checked}
});
},
deleteThisTask(){
Tasks.remove(this.props.task._id);
},
render(){
// Give tasks a different className when they are checked off,
// so that we can style them nicely in CSS
const taskClassName = this.props.task.checked ? "checked" : "";
return (
<li className={taskClassName}>
<button className="delete" onClick={this.deleteThisTask}>
×
</button>
<input
type="checkbox"
readOnly={true}
checked={this.props.task.checked}
onClick={this.toggleChecked} />
<span className="text">{this.props.task.text}</span>
</li>
);
}
});