import { html, css, CSSResult, property } from '@skhemata/skhemata-base'; import { Dropzone } from '@spectrum-web-components/dropzone'; import { IllustratedMessage } from '@spectrum-web-components/illustrated-message'; import { SkhemataFormInput } from './SkhemataFormInput'; export class SkhemataFormDropzone extends SkhemataFormInput { @property({type: String }) imageurl = ""; static get scopedElements() { return { 'sp-dropzone': Dropzone, 'sp-message': IllustratedMessage, }; } static get styles() { return [ ...super.styles, css` button.dropzone { cursor: pointer; border: none; margin: 0; padding: 0; width: 100%; height: 100%; border-radius: 4px; background: transparent; } #dropzone { border: none; } img { max-height: 15rem; } #sp-message { padding: 1rem; } .description { margin-bottom: 1rem; } `, ]; } @property({ type: Object, attribute: false }) dropzone: any; @property({ type: HTMLElement }) fileInput: any; @property({ type: String }) helpMessage = 'Drag and Drop, or Click to Upload Your File'; async firstUpdated() { this.fileInput = this.shadowRoot?.getElementById('file-input'); } handleClick = () => { this.fileInput.click(); }; handleFileUpload(e: any) { if (e.detail?.dataTransfer?.files) { [this.value] = e.detail.dataTransfer.files; } else { [this.value] = this.fileInput.files; } } render() { const field = html`
${this.label && !this.horizontal ? html`` : null}
${this.description && !this.horizontal ? html`

${this.description}

` : null}
${this.value || this.imageurl ? html`
${this.value ? this.value.name : ''}
` : null}
${!this.valid ? html`

${this.errorMessage}

` : ``}
`; const horizontalFieldLabel = html`
${this.label ? html`` : null} ${this.description ? html`

${this.description}

` : null}
`; const horizontalField = html`
${this.label || this.description ? horizontalFieldLabel : null}
${field}
`; return this.horizontal ? horizontalField : field; } }