-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathadd-todo-form.js
75 lines (69 loc) · 1.68 KB
/
add-todo-form.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
import { LitElement, html, css } from 'https://unpkg.com/lit-element?module';
class AddTodoForm extends LitElement {
constructor() {
super();
}
static get styles() {
return css`
.inputField{
margin: 20px 0;
width: 100%;
display: flex;
height: 45px;
}
.inputField input{
width: 85%;
height: 100%;
outline: none;
border-radius: 3px;
border: 1px solid #ccc;
font-size: 17px;
padding-left: 15px;
transition: all 0.3s ease;
}
.inputField input:focus{
border-color: #8E49E8;
}
.inputField button{
width: 50px;
height: 100%;
border: none;
color: #fff;
margin-left: 5px;
font-size: 21px;
outline: none;
background: #8E49E8;
cursor: pointer;
border-radius: 3px;
opacity: 0.6;
transition: all 0.3s ease;
}
.inputField button:hover,
.footer button:hover{
background: #721ce3;
}
.inputField button.active{
opacity: 1;
pointer-events: auto;
}
`;
}
_addTodo(e) {
if (e) {
e.preventDefault();
}
const input = this.shadowRoot.getElementById('addTodoInput');
const text = input.value;
input.value = '';
this.dispatchEvent(new CustomEvent('add-todo', { detail: text }));
}
render() {
return html`
<form class="inputField" @submit="${e => this._addTodo(e)}">
<input id="addTodoInput" placeholder="Name" />
<button type="button" @click="${this._addTodo}">Add</button>
</form>
`
}
}
customElements.define('add-todo-form', AddTodoForm);