import type { Body, Meta, State, Uppy, UppyFile } from '@uppy/core' import type { I18n } from '@uppy/utils' import classNames from 'classnames' import { CancelBtn, DoneBtn, PauseResumeButton, ProgressBarComplete, ProgressBarError, ProgressBarProcessing, ProgressBarUploading, RetryBtn, UploadBtn, } from './Components.js' import calculateProcessingProgress from './calculateProcessingProgress.js' import statusBarStates from './StatusBarStates.js' const { STATE_ERROR, STATE_WAITING, STATE_PREPROCESSING, STATE_UPLOADING, STATE_POSTPROCESSING, STATE_COMPLETE, } = statusBarStates export interface StatusBarUIProps { newFiles: number allowNewUpload: boolean isUploadInProgress: boolean isAllPaused: boolean resumableUploads: boolean error: any hideUploadButton?: boolean hidePauseResumeButton?: boolean hideCancelButton?: boolean hideRetryButton?: boolean recoveredState: State['recoveredState'] uploadState: (typeof statusBarStates)[keyof typeof statusBarStates] totalProgress: number files: Record> supportsUploadProgress: boolean hideAfterFinish?: boolean isSomeGhost: boolean doneButtonHandler?: (() => void) | null isUploadStarted: boolean i18n: I18n startUpload: () => void uppy: Uppy isAllComplete: boolean hideProgressDetails?: boolean numUploads: number complete: number totalSize: number | null totalETA: number | null totalUploadedSize: number } export default function StatusBarUI({ newFiles, allowNewUpload, isUploadInProgress, isAllPaused, resumableUploads, error, hideUploadButton = undefined, hidePauseResumeButton = false, hideCancelButton = false, hideRetryButton = false, recoveredState, uploadState, totalProgress, files, supportsUploadProgress, hideAfterFinish = false, isSomeGhost, doneButtonHandler = undefined, isUploadStarted, i18n, startUpload, uppy, isAllComplete, hideProgressDetails = undefined, numUploads, complete, totalSize, totalETA, totalUploadedSize, }: StatusBarUIProps) { function getProgressValue(): number | null { switch (uploadState) { case STATE_POSTPROCESSING: case STATE_PREPROCESSING: { const progress = calculateProcessingProgress(files) if (progress.mode === 'determinate') { return progress.value * 100 } return totalProgress } case STATE_ERROR: { return null } case STATE_UPLOADING: { if (!supportsUploadProgress) { return null } return totalProgress } default: return totalProgress } } function getIsIndeterminate(): boolean { switch (uploadState) { case STATE_POSTPROCESSING: case STATE_PREPROCESSING: { const { mode } = calculateProcessingProgress(files) return mode === 'indeterminate' } case STATE_UPLOADING: { if (!supportsUploadProgress) { return true } return false } default: return false } } const progressValue = getProgressValue() const width = progressValue ?? 100 const showUploadBtn = !error && newFiles && ((!isUploadInProgress && !isAllPaused) || recoveredState) && allowNewUpload && !hideUploadButton const showCancelBtn = !hideCancelButton && uploadState !== STATE_WAITING && uploadState !== STATE_COMPLETE const showPauseResumeBtn = resumableUploads && !hidePauseResumeButton && uploadState === STATE_UPLOADING const showRetryBtn = error && !isAllComplete && !hideRetryButton const showDoneBtn = doneButtonHandler && uploadState === STATE_COMPLETE const progressClassNames = classNames('uppy-StatusBar-progress', { 'is-indeterminate': getIsIndeterminate(), }) const statusBarClassNames = classNames( 'uppy-StatusBar', `is-${uploadState}`, { 'has-ghosts': isSomeGhost }, ) const progressBarStateEl = (() => { switch (uploadState) { case STATE_PREPROCESSING: case STATE_POSTPROCESSING: return ( ) case STATE_COMPLETE: return case STATE_ERROR: return ( ) case STATE_UPLOADING: return ( ) default: return null } })() const atLeastOneAction = showUploadBtn || showRetryBtn || showPauseResumeBtn || showCancelBtn || showDoneBtn const thereIsNothingInside = !atLeastOneAction && !progressBarStateEl const isHidden = thereIsNothingInside || (uploadState === STATE_COMPLETE && hideAfterFinish) if (isHidden) { return null } return (
{progressBarStateEl}
{showUploadBtn ? ( ) : null} {showRetryBtn ? : null} {showPauseResumeBtn ? ( ) : null} {showCancelBtn ? : null} {showDoneBtn ? ( ) : null}
) }