-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathtodo-summary.html
116 lines (96 loc) · 2.24 KB
/
todo-summary.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
<template id="todo-summary">
<label class="items-left">
{{props.active}} {{itemsLeft}}
</label>
<section class="filters">
{{#filters}}
<button class="filter {{selected}}">
{{desc}}
</button>
{{/filters}}
</section>
<button class="clear-completed" hidden="{{noItems}}">
Clear completed
</button>
<style>
:host {
display: block;
padding: 7px;
text-align: center;
}
:host[active="0"][completed="0"] {
display: none;
}
.items-left {
float: left;
font-size: 15px;
color: #aaa;
width: 80px;
}
.filters {
margin-left: auto;
margin-right: auto;
width: 190px;
display: inline-block;
}
.filter:first-letter {
text-transform:capitalize;
}
.filter:hover {
text-decoration: none;
}
.filter:focus {
outline: none;
}
.filter.selected {
border-bottom: 1px solid var(--light-red);
}
button {
cursor: pointer;
border: none;
background: white;
font-size: 13px;
color: var(--gray);
border: 1px solid transparent;
}
button:hover {
text-decoration: underline;
}
.clear-completed {
float: right;
}
@media (max-width: 500px) {
.items-left, .filters, .clear-completed {
display: block;
width: 100%;
float: none;
}
}
</style>
</template>
<script>
class TodoSummary extends HTMLComponent {
init() {
this.render()
.on('click', '.filter', e => this.changeFilter(e))
.on('click', '.clear-completed', e => this.emit('clear-completed'))
}
get total() { return this.props.active + this.props.completed }
get noItems() { return this.total == 0 }
get itemsLeft() {
return `${this.props.active == 1 ? 'item' : 'items'} left`
}
get filters() {
return [ 'all', 'active', 'completed' ].map(filter => {
var selected = filter == this.props.filter ? 'selected' : ''
return { desc: filter, selected: selected }
})
}
changeFilter(e) {
var filter = e.target.textContent.trim()
this.update({ filter: filter })
this.emit('change-filter', filter)
}
}
TodoSummary.register()
</script>