-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathform-element.js
106 lines (95 loc) · 2.56 KB
/
form-element.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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
class FormTemplate extends HTMLElement {
constructor() {
super();
}
connectedCallback() {
const shadowRoot = this.attachShadow({ mode: 'open' });
const styles = `
form {
width: 50vw;
}
@media only screen and (max-width: 500px) {
form {
width: 100%;
}
}
.form__row {
display: flex;
flex-direction: column;
gap: 0.5rem;
}
.form__row:not(:last-child) {
margin-bottom: 1rem;
}
.form__row:first-child {
position: relative;
}
.form__list {
font-size: 0.9rem;
border: 1px solid grey;
width: 100%;
position: absolute;
z-index: 2;
top: 3rem;
box-sizing: border-box;
background-color: white;
padding: 0.4rem;
transition: all 0.3s;
}
.form__list-info{
display: block;
font-size: 0.8rem;
color: grey;
margin-bottom: 0.8rem;
}
.form__list-item {
margin-bottom: 0.5rem;
cursor: pointer;
transition: all 0.3s;
}
.form__list-item:hover {
background-color: #e8ebed;
}
.form__list-item-info {
color: grey;
font-size: 0.7rem;
}
`;
const template = document.createElement('template');
template.innerHTML = `
<form>
<div class="form__row">
<label for="name">Компания или ИП</label>
<input type="text" id="name" name="name autocomplete="off""
placeholder="Введите название, ИНН, ОГРН или адрес организации"/>
<div class="form__list" id="name-list">
</div>
</div>
<div class="form__row">
<label for="short-name">Краткое наименование</label>
<input type="text" id="short-name" name="short-name" />
</div>
<div class="form__row">
<label for="full-name">Полное наименование</label>
<input type="text" id="full-name" name="full-name" />
</div>
<div class="form__row">
<label for="inn">ИНН / КПП</label>
<input type="text" id="inn" name="inn" />
</div>
<div class="form__row">
<label for="address">Адрес</label>
<input type="text" id="address" name="address" />
</div>
</form>
`;
shadowRoot.innerHTML = `
<style>${styles}</style>
`;
shadowRoot.appendChild(template.content.cloneNode(true));
}
returnShadowRoot() {
return this.shadowRoot;
}
}
customElements.define('form-template', FormTemplate);