component FileUploadProgress { props { @event cancel = function @event retry = function @event complete = function size = "default" color = "primary" label = "Progress" value = 50 max = 100 showValue = true fileName = "" fileSize = "" uploadedSize = "" status = "uploading" cancelLabel = "Cancel upload" retryLabel = "Retry upload" class = "" } state currentValue = value state currentStatus = status functions { function percent() { if (!Number(max)) { return 0 } return Math.max(0, Math.min(100, Math.round(Number(currentValue) / Number(max) * 100))) } function detail(sourceEvent) { return { value: currentValue, max: max, percent: percent(), status: currentStatus, fileName: fileName, sourceEvent: sourceEvent } } function cancelUpload(sourceEvent) { currentStatus = "cancelled"; $emit("cancel", detail(sourceEvent)) } function retryUpload(sourceEvent) { currentValue = 0; currentStatus = "uploading"; $emit("retry", detail(sourceEvent)) } function completeUpload(sourceEvent) { currentValue = max; currentStatus = "complete"; $emit("complete", detail(sourceEvent)) } } view {
{#if fileName}{fileName}{#if uploadedSize || fileSize}{uploadedSize}{#if uploadedSize && fileSize} of {/if}{fileSize}{:else}{label}{/if}{:else}{label}{/if}{#if showValue}{percent()}%{/if}
{#if currentStatus === "uploading"}Uploading securely…{:else if currentStatus === "complete"}Upload complete{:else if currentStatus === "error"}Upload failed{:else}Upload cancelled{/if}
{#if currentStatus === "uploading"}{/if}{#if currentStatus === "error" || currentStatus === "cancelled"}{/if}
} }