2019-08-20 05:49:40 +08:00
|
|
|
import { create_el } from "./dom";
|
|
|
|
import { View } from "./View";
|
|
|
|
import "./FileInput.css";
|
|
|
|
import "./Button.css";
|
2019-08-20 21:02:58 +08:00
|
|
|
import { Property } from "../observable/Property";
|
2019-08-20 05:49:40 +08:00
|
|
|
|
|
|
|
export class FileInput extends View {
|
|
|
|
private input: HTMLInputElement = create_el("input", "core_FileInput_input");
|
|
|
|
|
2019-08-20 21:02:58 +08:00
|
|
|
element: HTMLLabelElement = create_el("label", "core_FileInput core_Button");
|
2019-08-20 05:49:40 +08:00
|
|
|
|
|
|
|
constructor(text: string, accept: string = "") {
|
|
|
|
super();
|
|
|
|
|
|
|
|
this.input.type = "file";
|
|
|
|
this.input.accept = accept;
|
|
|
|
this.input.onchange = () => {
|
|
|
|
if (this.input.files && this.input.files.length) {
|
2019-08-20 21:02:58 +08:00
|
|
|
this.files.set([...this.input.files!]);
|
|
|
|
} else {
|
|
|
|
this.files.set([]);
|
2019-08-20 05:49:40 +08:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
this.element.textContent = text;
|
|
|
|
this.element.append(this.input);
|
|
|
|
}
|
|
|
|
|
2019-08-20 21:02:58 +08:00
|
|
|
readonly files = new Property<File[]>([]);
|
2019-08-20 05:49:40 +08:00
|
|
|
}
|