-
Notifications
You must be signed in to change notification settings - Fork 31
/
index.js
72 lines (65 loc) · 2.04 KB
/
index.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
function createElement(tag, attributes, children) {
const element = document.createElement(tag);
if (attributes) {
Object.keys(attributes).forEach((key) => {
element.setAttribute(key, attributes[key]);
});
}
if (Array.isArray(children)) {
children.forEach((child) => {
if (typeof child === "string") {
element.appendChild(document.createTextNode(child));
} else if (child instanceof HTMLElement) {
element.appendChild(child);
}
});
} else if (typeof children === "string") {
element.appendChild(document.createTextNode(children));
} else if (children instanceof HTMLElement) {
element.appendChild(children);
}
return element;
}
class Component {
constructor() {
}
getDomNode() {
this._domNode = this.render();
return this._domNode;
}
}
class TodoList extends Component {
render() {
return createElement("div", { class: "todo-list" }, [
createElement("h1", {}, "TODO List"),
createElement("div", { class: "add-todo" }, [
createElement("input", {
id: "new-todo",
type: "text",
placeholder: "Задание",
}),
createElement("button", { id: "add-btn" }, "+"),
]),
createElement("ul", { id: "todos" }, [
createElement("li", {}, [
createElement("input", { type: "checkbox" }),
createElement("label", {}, "Сделать домашку"),
createElement("button", {}, "🗑️")
]),
createElement("li", {}, [
createElement("input", { type: "checkbox" }),
createElement("label", {}, "Сделать практику"),
createElement("button", {}, "🗑️")
]),
createElement("li", {}, [
createElement("input", { type: "checkbox" }),
createElement("label", {}, "Пойти домой"),
createElement("button", {}, "🗑️")
]),
]),
]);
}
}
document.addEventListener("DOMContentLoaded", () => {
document.body.appendChild(new TodoList().getDomNode());
});