-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
132 lines (114 loc) · 3.34 KB
/
index.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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<link rel="stylesheet" href="./styles.css">
</head>
<body>
<div class="wrapper">
<todo-app></todo-app>
</div>
<script type="module">
import { LitElement, html, css } from 'https://unpkg.com/lit-element?module';
import './todo-list.js';
import './add-todo-form.js';
const author = '@mdrahiem';
const homepage = 'http://github.com/mdrahiem/';
const footerTemplate = html`
<div class="footer">Made with 🧡 by <a href="${homepage}" target="_blank">${author}</a></div>
`;
class TodoApp extends LitElement {
static get properties() {
return {
todos: { type: Array },
};
}
static get styles() {
return css`
header {
font-size: 30px;
font-weight: 600;
text-align: center;
}
.footer {
text-align: center;
padding: 10px;
}
.footer a {
padding: 6px 10px;
border-radius: 3px;
border: none;
outline: none;
color: #fff;
font-weight: 400;
font-size: 16px;
margin-left: 5px;
background: #8E49E8;
cursor: pointer;
opacity: 0.6;
transition: all 0.3s ease;
}
.stats {
display: flex;
justify-content: space-around;
padding: 20px;
}
.stats div {
background: #91bcf1;
padding: 5px 10px;
border-radius: 3px;
color: black;
}
`;
}
connectedCallback() {
super.connectedCallback(); // IT IS MANDATORY to avoid bugs
this.todos = [
{ text: 'Do A', finished: true },
{ text: 'Do B', finished: false },
{ text: 'Do C', finished: false },
];
}
_addTodo(e) {
this.todos = [...this.todos, { text: e.detail, finished: false }];
}
_removeTodo(e) {
this.todos = this.todos.filter(todo => todo !== e.detail);
}
_changeTodoFinished(e) {
const { changedTodo, finished } = e.detail;
this.todos = this.todos.map((todo) => {
if (todo !== changedTodo) {
return todo;
}
return { ...changedTodo, finished };
});
}
render() {
const finishedCount = this.todos.filter(e => e.finished).length;
const unfinishedCount = this.todos.length - finishedCount;
return html`
<header>📝 Todo app</header>
<add-todo-form
@add-todo="${this._addTodo}"
></add-todo-form>
<todo-list
.todos="${this.todos}"
@change-todo-finished="${this._changeTodoFinished}"
@remove-todo="${this._removeTodo}"
></todo-list>
<div class="stats">
<div>✅ Finished: ${finishedCount}</div>
<div>❌ Unfinished: ${unfinishedCount}</div>
</div>
${footerTemplate}
`;
}
}
customElements.define('todo-app', TodoApp);
</script>
</body>
</html>