import { LitElement, html, css } from 'lit'; import { customElement, query, property } from 'lit/decorators.js'; import '@material/mwc-button'; @customElement('usf-file-upload') export class FileUpload extends LitElement { static styles = css` mwc-button { vertical-align: middle; } `; fileChanged(e: Event) { this.requestUpdate(); this.dispatchEvent(new Event(e.type, e)); } buttonClicked() { this.fileInput.click(); } @query('#file') private fileInput!: HTMLInputElement; @property({ type: Boolean }) public disabled = false; @property() public accept?: string; get files() { if (!this.fileInput) { return null; } return this.fileInput.files; } render() { return html` ${this.files ? html`${this.files.length > 0 ? this.files[0].name : 'No file selected'}` : ''} `; } } declare global { interface HTMLElementTagNameMap { 'usf-file-upload': FileUpload; } }