page FileUploadProgresscomponent { seo { title = "FileUploadProgress component" description = "Theme-aware, responsive file upload progress component." } view {
W WRNexusJS
base component

FileUploadProgress

Theme-aware, responsive file upload progress component.

@wrnexus/ui 0.5.013 props0 slots3 events

Usage

Components are auto-discovered. Use the component directly in any .wrn view:

<FileUploadProgress
  size="default"
  color="primary"
  label="Progress"
  value="50"
  max="100"
/>

Legacy mount name: data-component="FileUploadProgress".

Props and attributes

PropTypeRequirementDefault
sizestringOptional"default"
colorstringOptional"primary"
labelstringOptional"Progress"
valuenumberOptional50
maxnumberOptional100
showValuebooleanOptionaltrue
fileNamestringOptional""
fileSizestringOptional""
uploadedSizestringOptional""
statusstringOptional"uploading"
cancelLabelstringOptional"Cancel upload"
retryLabelstringOptional"Retry upload"
classstringOptional""

Slots

This component does not declare a slot.

Events

  • cancel
  • retry
  • complete

Source contract

Installed source: components/FileUploadProgress.wrn

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 {
        <div {...attrs} class="wire-next wire-next--color-{color} wire-next--size-{size} wire-next--file-upload-progress {class}" data-status="{currentStatus}" aria-live="polite">
        <div class="wire-next__row">
        <span>{#if fileName}<strong>{fileName}</strong>
        <small>{#if uploadedSize || fileSize}{uploadedSize}{#if uploadedSize && fileSize} of {/if}{fileSize}{:else}{label}{/if}</small>{:else}<strong>{label}</strong>{/if}</span>{#if showValue}<strong>{percent()}%</strong>{/if}</div>
        <progress value="{currentValue}" max="{max}" aria-label="{label}">
        </progress>
        <div class="wire-next__upload-status">
        <span class="wire-next__upload-status-icon" aria-hidden="true">
        </span>
        <span>{#if currentStatus === "uploading"}Uploading securely…{:else if currentStatus === "complete"}Upload complete{:else if currentStatus === "error"}Upload failed{:else}Upload cancelled{/if}</span>
        </div>
        <div class="wire-next__upload-actions">{#if currentStatus === "uploading"}<button type="button" @click="cancelUpload(event)">{cancelLabel}</button>
        <button type="button" @click="completeUpload(event)">Complete</button>{/if}{#if currentStatus === "error" || currentStatus === "cancelled"}<button type="button" @click="retryUpload(event)">{retryLabel}</button>{/if}</div>
        </div>
    }
}
} }