phantasmal-world/src/new/core/gui/FileInput.ts

31 lines
890 B
TypeScript
Raw Normal View History

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";
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");
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([]);
}
};
this.element.textContent = text;
this.element.append(this.input);
}
2019-08-20 21:02:58 +08:00
readonly files = new Property<File[]>([]);
}