forked from nearbycoder/repo6
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCheckList.js
42 lines (35 loc) · 1.24 KB
/
CheckList.js
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
41
42
import React, { Component, PropTypes } from 'react';
class CheckList extends Component {
constructor() {
super(...arguments);
this.checkInputKeyPress = this.checkInputKeyPress.bind(this);
}
checkInputKeyPress(evt){
if(evt.key === 'Enter'){
this.props.taskCallbacks.add(this.props.cardId, evt.target.value);
evt.target.value = '';
}
}
render() {
let tasks = this.props.tasks.map((task,taskIndex) => ( <li key={task.id} className="checklist__task">
<input type="checkbox" checked={task.done} onChange={
this.props.taskCallbacks.toggle.bind(null, this.props.cardId, task.id, taskIndex)} />
{!task.done && ' '+task.name} {task.done && <s>{task.name}</s>} {' '}
<a href="#" className="checklist__task--remove" onClick={ () => this.props.taskCallbacks.delete(this.props.cardId, task.id, taskIndex) } />
</li> ) );
return (
<div className="checklist">
<ul>{tasks}</ul>
<input type="text"
className="checklist--add-task"
placeholder="Type then hit Enter to add a task" onKeyPress={this.checkInputKeyPress} />
</div>
);
}
};
CheckList.propTypes = {
cardId: PropTypes.number,
taskCallbacks: PropTypes.object,
tasks: PropTypes.arrayOf(PropTypes.object)
};
export default CheckList;