Task.jsx 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  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. Meteor.call("setChecked", this.props.task._id, ! this.props.task.checked);
  11. },
  12. deleteThisTask() {
  13. Meteor.call("removeTask", this.props.task._id);
  14. },
  15. render() {
  16. // Give tasks a different clasSName when they are checked off,
  17. // so that we can style them nicely in CSS.
  18. const taskClassName = this.props.task.checked ? 'checked' : '';
  19. let result = (
  20. <li className={taskClassName}>
  21. <button className="delete" onClick={this.deleteThisTask}>
  22. &times;
  23. </button>
  24. <input
  25. type="checkbox"
  26. readOnly="{true}"
  27. checked={this.props.task.checked}
  28. onClick={this.toggleChecked}
  29. />
  30. <strong>{this.props.task.username}</strong>: <span className="text">{this.props.task.text}</span>
  31. </li>
  32. );
  33. return result;
  34. }
  35. });