mirror of
https://github.com/DaanVandenBosch/phantasmal-world.git
synced 2025-04-06 08:08:28 +08:00
30 lines
825 B
TypeScript
30 lines
825 B
TypeScript
![]() |
import { create_el } from "./dom";
|
||
|
import { View } from "./View";
|
||
|
import "./FileInput.css";
|
||
|
import "./Button.css";
|
||
|
|
||
|
function dummy_function(): void {}
|
||
|
|
||
|
export class FileInput extends View {
|
||
|
private input: HTMLInputElement = create_el("input", "core_FileInput_input");
|
||
|
|
||
|
element: HTMLLabelElement = create_el("label", "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) {
|
||
|
this.on_files_chosen([...this.input.files!]);
|
||
|
}
|
||
|
};
|
||
|
|
||
|
this.element.textContent = text;
|
||
|
this.element.append(this.input);
|
||
|
}
|
||
|
|
||
|
on_files_chosen: (files: File[]) => void = dummy_function;
|
||
|
}
|