-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.html
136 lines (98 loc) · 2.18 KB
/
app.html
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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
<html>
<head>
<script src="https://unpkg.com/react@15/dist/react.js"></script>
<script src="https://unpkg.com/react-dom@15/dist/react-dom.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/babel-core/5.8.23/browser.min.js"></script>
<script src="https://npmcdn.com/react-router/umd/ReactRouter.min.js"></script>
<style>
.header {
background-color: green;
padding:5px;
color:white;
}
.menu {
list-style-type: none;
}
.menu li {
padding:5px;
display:inline;
margin:5px;
}
.content {
background-color: pink;
width:100%;
height:100%;
}
.active {
background-color: #0099FF;
}
.taskItemsContainer {
list-style: none;
}
.taskItemsContainer li {
background-color: pink;
color:white;
padding:10;
margin:5;
}
.todoListContainer {
background-color: orange;
height:200px;
width:200px;
}
</style>
</head>
<body>
<div id="container"></div>
<script type="text/babel">
var container = document.querySelector("#container");
var TodoList = React.createClass({
getInitialState: function() {
return {
tasks :[]
}
},
addTask : function() {
var tasks = this.state.tasks;
tasks.push({
title: this._inputElement.value,
key:Date.now()
});
this.setState({
tasks : tasks
});
this._inputElement.value = ""
},
render: function() {
return (
<div className="todoListContainer">
<input ref={(a) => this._inputElement = a} type="text"/>
<button onClick={this.addTask}>Add</button>
<TodoListItems tasks={this.state.tasks} />
</div>
)
}
});
var TodoListItems = React.createClass({
render: function() {
function createTaskItem(task) {
return <li key={task.key}>{task.title}</li>
}
var tasks = this.props.tasks;
var taskItemList = tasks.map(createTaskItem);
return (
<div>
<ul className="taskItemsContainer">
{taskItemList}
</ul>
</div>
)
}
});
ReactDOM.render(
<TodoList />,
container
)
</script>
</body>
</html>