-
Notifications
You must be signed in to change notification settings - Fork 0
/
vaadin-date-picker-2.js
57 lines (49 loc) · 1.4 KB
/
vaadin-date-picker-2.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
import { LitElement, html, css } from 'lit-element';
import { vaadinTextFieldStyles } from './vaadin-text-field-styles.js';
class VaadinDatePicker2 extends LitElement {
static get properties() { return {
label: { type: String },
value: { type: String },
error: { type: String },
required: { type: Boolean }
};}
constructor() {
super();
this.label = '';
this.error = '';
this.value = '';
this.required = false;
}
static get styles() {
return [vaadinTextFieldStyles, css``]
}
render() {
return html`
<label for="input">
${this.label}
${this.required ? html`<span aria-hidden="true">*</span>` : html``}
</label>
<div id="input-wrapper">
<slot name="prefix"></slot>
<input id="input" type="date" value="${this.value}">
<slot name="suffix"></slot>
</div>
<span id="error" aria-live="polite">${this.error}</span>
`;
}
firstUpdated() {
var input = this.shadowRoot.querySelector('#input');
if (this.required) {
input.setAttribute('required', '');
} else {
input.removeAttribute('required');
}
input.addEventListener('focus', event => {
this.setAttribute('focused', '');
});
input.addEventListener('blur', event => {
this.removeAttribute('focused');
});
}
}
customElements.define('vaadin-date-picker-2', VaadinDatePicker2);