-
Notifications
You must be signed in to change notification settings - Fork 94
Expand file tree
/
Copy pathtodo-footer.ts
More file actions
137 lines (123 loc) · 4.11 KB
/
todo-footer.ts
File metadata and controls
137 lines (123 loc) · 4.11 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
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
137
import { LitElement, html, css, nothing } from "lit";
import { customElement } from "lit/decorators/custom-element.js";
import { property } from "lit/decorators/property.js";
import { classMap } from "lit/directives/class-map.js";
import { todoStyles } from "./todo.css.js";
import { type Todos } from "./todos.js";
import { updateOnEvent } from "./utils.js";
import { ClearCompletedEvent } from "./events.js";
@customElement("todo-footer")
export class TodoFooter extends LitElement {
static override styles = [
todoStyles,
css`
:host {
display: block;
padding: 10px 15px;
height: 20px;
text-align: center;
font-size: 15px;
border-top: 1px solid #e6e6e6;
}
:host:before {
content: "";
position: absolute;
right: 0;
bottom: 0;
left: 0;
height: 50px;
overflow: hidden;
box-shadow: 0 1px 1px rgba(0, 0, 0, 0.2), 0 8px 0 -3px #f6f6f6, 0 9px 1px -3px rgba(0, 0, 0, 0.2), 0 16px 0 -6px #f6f6f6, 0 17px 2px -6px rgba(0, 0, 0, 0.2);
}
.todo-count {
float: left;
text-align: left;
}
.todo-count strong {
font-weight: 300;
}
.filters {
margin: 0;
padding: 0;
list-style: none;
position: absolute;
right: 0;
left: 0;
}
li {
display: inline;
}
li a {
color: inherit;
margin: 3px;
padding: 3px 7px;
text-decoration: none;
border: 1px solid transparent;
border-radius: 3px;
}
a:hover {
border-color: #db7676;
}
a.selected {
border-color: #ce4646;
}
.clear-completed,
:host .clear-completed:active {
float: right;
position: relative;
line-height: 19px;
text-decoration: none;
cursor: pointer;
}
.clear-completed:hover {
text-decoration: underline;
}
`,
];
@updateOnEvent("change")
@property({ attribute: false })
accessor todoList: Todos | undefined;
override render() {
if (this.todoList === undefined || this.todoList.all.length === 0)
return nothing;
const allFilter = filterLink({
text: "All",
filter: "all",
selectedFilter: this.todoList?.filter,
});
const activeFilter = filterLink({
text: "Active",
filter: "active",
selectedFilter: this.todoList?.filter,
});
const completedFilter = filterLink({
text: "Completed",
filter: "completed",
selectedFilter: this.todoList?.filter,
});
return html`
<span class="todo-count">
<strong>${this.todoList?.active.length}</strong>
items left
</span>
<ul class="filters">
<li>${allFilter}</li>
<li>${activeFilter}</li>
<li>${completedFilter}</li>
</ul>
${(this.todoList?.completed.length ?? 0) > 0 ? html`<button @click=${this.#onClearCompletedClick} class="clear-completed">Clear Completed</button>` : nothing}
`;
}
#onClearCompletedClick() {
this.dispatchEvent(new ClearCompletedEvent());
}
}
function filterLink({ text, filter, selectedFilter }: { text: string; filter: string; selectedFilter: string | undefined }) {
return html`<a class="${classMap({ selected: filter === selectedFilter })}" href="#/${filter}">${text}</a>`;
}
declare global {
// eslint-disable-next-line no-unused-vars
interface HTMLElementTagNameMap {
"todo-footer": TodoFooter;
}
}