Task.jsx 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  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
  27. type="checkbox"
  28. readOnly="{true}"
  29. checked={this.props.task.checked}
  30. onClick={this.toggleChecked}
  31. />
  32. <strong>{this.props.task.username}</strong>: <span className="text">{this.props.task.text}</span>
  33. </li>
  34. );
  35. return result;
  36. }
  37. });