-
Notifications
You must be signed in to change notification settings - Fork 0
/
todo-list.js
84 lines (78 loc) · 1.85 KB
/
todo-list.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
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
import { LitElement, html, css } from 'https://unpkg.com/lit-element?module';
class TodoList extends LitElement {
static get properties() {
return {
todos: { type: Array }
}
}
static get styles() {
return css`
.todoList {
max-height: 250px;
overflow-y: auto;
margin: 0;
padding: 0
}
.todoList li {
position: relative;
list-style: none;
height: 45px;
line-height: 45px;
margin-bottom: 8px;
background: #f2f2f2;
border-radius: 3px;
padding: 0 15px;
cursor: default;
overflow: hidden;
list-style-position: inside;
}
.todoList li .icon {
position: absolute;
right: 0;
border: 0;
top: 12px;
width: 45px;
text-align: center;
color: #fff;
border-radius: 0 3px 3px 0;
cursor: pointer;
transition: all 0.2s ease;
}
.todoList li:hover .icon {
right: 0px;
}
`;
}
_changeTodoFinished(e, changedTodo) {
const eventDetails = { changedTodo, finished: e.target.checked };
this.dispatchEvent(new CustomEvent('change-todo-finished', { detail: eventDetails }));
}
_removeTodo(item) {
this.dispatchEvent(new CustomEvent('remove-todo', { detail: item }));
}
render() {
if (!this.todos) {
return html``;
}
return html`
<ul class="todoList">
${this.todos.map(
todo => html`
<li>
<input
type="checkbox"
.checked=${todo.finished}
@change=${e => this._changeTodoFinished(e, todo)}
/>
${todo.text}
<button class="icon" @click=${() => this._removeTodo(todo)}>
⛔
</button>
</li>
`,
)}
</ol>
`;
}
}
customElements.define('todo-list', TodoList);