import { html, TemplateResult } from 'lit'; import './nile-file-upload.css'; import { DragHandler } from './utils/drag-drop.util'; import { classMap } from 'lit-html/directives/class-map.js'; import { FileUploadDefaults, FileUploadState } from './types/file-upload.enums'; import { truncateString } from './utils/file-validation.util'; import { NileFileUpload } from './nile-file-upload'; const baseHorizontalState = ( browseFiles: Function, title: string, subtitle: string, disabled: boolean, dragHandler: DragHandler, state: FileUploadState, errorMessage: string, allowedTypes: string[], nileFileUpload: NileFileUpload ): TemplateResult => { truncateString(nileFileUpload); return html`
${title}
${subtitle}
{ dragHandler.handleFiles(e) }} ?multiple=${nileFileUpload.allowMultiple} accept=${allowedTypes.join(',')} /> Browse File
${errorMessage || nileFileUpload.state === FileUploadState.ERROR ? html`
${ nileFileUpload.isStringTruncated ? html` ${errorMessage || FileUploadDefaults.CUSTOM_ERROR} ` : html`${errorMessage || FileUploadDefaults.CUSTOM_ERROR}` }
`: html`` }
`; } export const getHorizontalDefaultState = ( browseFiles: Function, title: string, subtitle: string, dragHandler: DragHandler, state: FileUploadState, errorMessage: string, allowedTypes: string[], nileFileUpload: NileFileUpload ): TemplateResult => baseHorizontalState(browseFiles, title, subtitle, false, dragHandler, state, errorMessage, allowedTypes, nileFileUpload); export const getHorizontalDisabledState = ( browseFiles: Function, title: string, subtitle: string, dragHandler: DragHandler, state: FileUploadState, errorMessage: string, allowedTypes: string[], nileFileUpload: NileFileUpload ): TemplateResult => baseHorizontalState(browseFiles, title, subtitle, true, dragHandler, state, errorMessage, allowedTypes, nileFileUpload); export const getHorizontalErrorState = ( browseFiles: Function, title: string, subtitle: string, dragHandler: DragHandler, state: FileUploadState, errorMessage: string, allowedTypes: string[], nileFileUpload: NileFileUpload ): TemplateResult => baseHorizontalState(browseFiles, title, subtitle, false, dragHandler, state, errorMessage, allowedTypes, nileFileUpload); export const getHorizontalDragState = (): TemplateResult => html`

${FileUploadDefaults.DRAG_STATE_DEFAULT}

`; // Vertical States const baseVerticalState = ( browseFiles: Function, title: string, subtitle: string, disabled: boolean, dragHandler: DragHandler, errorMessage: string, allowedTypes: string[], nileFileUpload: NileFileUpload ): TemplateResult => { truncateString(nileFileUpload); return html`
${title}
${subtitle}
dragHandler.handleFiles(e)} multiple accept=${allowedTypes.join(',')} /> Browse File
${errorMessage || nileFileUpload.state === FileUploadState.ERROR ? html`
${ nileFileUpload.isStringTruncated ? html` ${errorMessage || FileUploadDefaults.CUSTOM_ERROR} ` : html`${errorMessage || FileUploadDefaults.CUSTOM_ERROR}` }
` : html`` }
`; } export const getVerticalDefaultState = ( browseFiles: Function, title: string, subtitle: string, dragHandler: DragHandler, errorMessage: string, allowedTypes: string[], nileFileUpload: NileFileUpload ): TemplateResult => baseVerticalState(browseFiles, title, subtitle, false, dragHandler, errorMessage, allowedTypes, nileFileUpload); export const getVerticalDisabledState = ( browseFiles: Function, title: string, subtitle: string, dragHandler: DragHandler, errorMessage: string, allowedTypes: string[], nileFileUpload: NileFileUpload ): TemplateResult => baseVerticalState(browseFiles, title, subtitle, true, dragHandler, errorMessage, allowedTypes, nileFileUpload); export const getVerticalErrorState = ( browseFiles: Function, title: string, subtitle: string, dragHandler: DragHandler, errorMessage: string, allowedTypes: string[], nileFileUpload: NileFileUpload ): TemplateResult => baseVerticalState(browseFiles, title, subtitle, false, dragHandler, errorMessage, allowedTypes, nileFileUpload); export const getVerticalDragState = (): TemplateResult => html`

${FileUploadDefaults.DRAG_STATE_DEFAULT}

`;