import type { Body, DefinePluginOpts, Meta, State, UIPluginOptions, Uppy, } from '@uppy/core' import { UIPlugin } from '@uppy/core' import { type ComponentChild, h } from 'preact' import packageJson from '../package.json' with { type: 'json' } export interface ProgressBarOptions extends UIPluginOptions { hideAfterFinish?: boolean fixed?: boolean } // set default options, must kept in sync with @uppy/react/src/ProgressBar.js const defaultOptions = { fixed: false, hideAfterFinish: true, } type Opts = DefinePluginOpts /** * Progress bar * */ export default class ProgressBar< M extends Meta, B extends Body, > extends UIPlugin { static VERSION = packageJson.version constructor(uppy: Uppy, opts?: ProgressBarOptions) { super(uppy, { ...defaultOptions, ...opts }) this.id = this.opts.id || 'ProgressBar' this.title = 'Progress Bar' this.type = 'progressindicator' this.render = this.render.bind(this) } render(state: State): ComponentChild { const { totalProgress } = state // before starting and after finish should be hidden if specified in the options const isHidden = (totalProgress === 0 || totalProgress === 100) && this.opts.hideAfterFinish return (
{totalProgress}
) } install(): void { const { target } = this.opts if (target) { this.mount(target, this) } } uninstall(): void { this.unmount() } }