-
-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathct-input-wrapper.ts
More file actions
87 lines (81 loc) · 1.6 KB
/
ct-input-wrapper.ts
File metadata and controls
87 lines (81 loc) · 1.6 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
import { html } from "lit";
import { CtLit, customElement, property, query } from "./ct-lit.js";
/**
* # `ct-input-wrapper`
*
* @group ct-elements
* @element ct-input-wrapper
*/
@customElement("ct-input-wrapper")
export class CtInputWrapper extends CtLit {
@property({ type: String }) type:
| "hidden"
| "text"
| "search"
| "tel"
| "url"
| "email"
| "password"
| "datetime"
| "date"
| "month"
| "week"
| "time"
| "datetime-local"
| "number"
| "range"
| "color"
| "checkbox"
| "radio"
| "file"
| "submit"
| "image"
| "reset"
| "button" = "file";
@property({ type: String }) accept = "text";
@property({ type: Boolean }) multiple = false;
@query("#inputElement") $inputElement!: HTMLInputElement;
render() {
return html` <style>
:host {
display: block;
position: relative;
}
#inputElement {
bottom: 0;
height: 100%;
left: 0;
margin: 0;
opacity: 0;
padding: 0;
position: absolute;
right: 0;
top: 0;
width: 100%;
}
input {
cursor: pointer;
}
</style>
<slot></slot>
<input @change=${this.callOnChange} .type="${this.type}" .accept="${this.accept}" id="inputElement" ?multiple=${this.multiple} part="input" />`;
}
callOnChange(e: any) {
const files = (this.$inputElement as HTMLInputElement).files;
if (files && files.length > 0) {
this.dispatchEvent(
new CustomEvent("files", {
detail: { files: files }
})
);
}
}
clear() {
this.$inputElement.value = "";
}
}
declare global {
interface HTMLElementTagNameMap {
"ct-input-wrapper": CtInputWrapper;
}
}