-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtodo-list.html
More file actions
62 lines (57 loc) · 1.75 KB
/
todo-list.html
File metadata and controls
62 lines (57 loc) · 1.75 KB
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
<!DOCTYPE html>
<html>
<body>
<script src="https://unpkg.com/react@16.3.2/umd/react.production.min.js"></script>
<script src="https://unpkg.com/react-dom@16.3.2/umd/react-dom.production.min.js"></script>
<script
src="https://cdnjs.cloudflare.com/ajax/libs/babel-standalone/6.26.0/babel.min.js"
charset="utf-8"
></script>
<script type="text/babel">
const TodoItem = (props) => (
<li onClick={props.onClick}>{props.item.text}</li>
);
class TodoList extends React.Component {
render() {
const { items, onListClick } = this.props;
return (
<ul onClick={onListClick}>
{items.map((item, index) => (
<TodoItem
item={item}
key={index}
onClick={this.handleItemClick.bind(this, item)}
/>
))}
</ul>
);
}
handleItemClick(item, event) {
if (!item.done) {
event.persist();
this.props.onItemClick(item, event);
} else {
event.stopPropagation();
}
}
}
const items = [
{ text: "Buy grocery", done: true },
{ text: "Play guitar", done: false },
{ text: "Romantic dinner", done: false },
];
const App = (props) => (
<TodoList
items={props.items}
onListClick={(event) => console.log("List clicked!")}
onItemClick={(item, event) => {
console.log("itemclick", item, event);
}}
/>
);
const rootElement = document.getElementById("root");
ReactDOM.render(<App items={items} />, rootElement);
</script>
<div id="root"></div>
</body>
</html>