Task.jsx 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. // Task component: represents a single todo item.
  2. Task = React.createClass({
  3. propTypes: {
  4. // This component gets the task to display through a React prop.
  5. // We can use propTypes to indicate it is required.
  6. task: React.PropTypes.object.isRequired
  7. },
  8. toggleChecked() {
  9. // Set the checked property to the opposite of its current value.
  10. Tasks.update(this.props.task._id, {
  11. $set: { checked: !this.props.task.checked }
  12. });
  13. },
  14. deleteThisTask() {
  15. Tasks.remove(this.props.task._id);
  16. },
  17. render() {
  18. // Give tasks a different clasSName when they are checked off,
  19. // so that we can style them nicely in CSS.
  20. const taskClassName = this.props.task.checked ? 'checked' : '';
  21. let result = (
  22. <li className={taskClassName}>
  23. <button className="delete" onClick={this.deleteThisTask}>
  24. &times;
  25. </button>
  26. <input type="checkbox" readOnly="{true}" checked={this.props.task.checked} onClick={this.toggleChecked} />
  27. <span className="text">{this.props.task.text}</span>
  28. </li>
  29. );
  30. return result;
  31. }
  32. });