From 7ab102e966891cb04e61c22eab6eccbb146ed098 Mon Sep 17 00:00:00 2001 From: Antoine du Hamel Date: Mon, 22 Jan 2024 17:12:33 +0100 Subject: [PATCH 1/3] @uppy/status-bar: fix `StatusBarOptions` type --- packages/@uppy/status-bar/src/StatusBar.tsx | 33 +++++++++---------- .../@uppy/status-bar/src/StatusBarOptions.ts | 18 +++++----- 2 files changed, 25 insertions(+), 26 deletions(-) diff --git a/packages/@uppy/status-bar/src/StatusBar.tsx b/packages/@uppy/status-bar/src/StatusBar.tsx index f0b9f04ab3..c22326c205 100644 --- a/packages/@uppy/status-bar/src/StatusBar.tsx +++ b/packages/@uppy/status-bar/src/StatusBar.tsx @@ -55,12 +55,25 @@ function getUploadingState( return state } +// set default options, must be kept in sync with @uppy/react/src/StatusBar.js +const defaultOptions = { + target: 'body', + hideUploadButton: false, + hideRetryButton: false, + hidePauseResumeButton: false, + hideCancelButton: false, + showProgressDetails: false, + hideAfterFinish: true, + doneButtonHandler: null, +} + /** * StatusBar: renders a status bar with upload/pause/resume/cancel/retry buttons, * progress percentage and time remaining. */ export default class StatusBar extends UIPlugin< - StatusBarOptions, + StatusBarOptions & + Required>, M, B > { @@ -74,28 +87,14 @@ export default class StatusBar extends UIPlugin< #previousETA: number | null - constructor(uppy: Uppy, opts?: Partial) { + constructor(uppy: Uppy, opts?: StatusBarOptions) { super(uppy, opts) - this.id = this.opts.id || 'StatusBar' + this.opts = { ...defaultOptions, ...opts, id: this.opts.id || 'StatusBar' } this.title = 'StatusBar' this.type = 'progressindicator' this.defaultLocale = locale - // set default options, must be kept in sync with @uppy/react/src/StatusBar.js - const defaultOptions = { - target: 'body', - hideUploadButton: false, - hideRetryButton: false, - hidePauseResumeButton: false, - hideCancelButton: false, - showProgressDetails: false, - hideAfterFinish: true, - doneButtonHandler: null, - } - - this.opts = { ...defaultOptions, ...opts } - this.i18nInit() this.render = this.render.bind(this) diff --git a/packages/@uppy/status-bar/src/StatusBarOptions.ts b/packages/@uppy/status-bar/src/StatusBarOptions.ts index 06ca34387d..c4cce9f334 100644 --- a/packages/@uppy/status-bar/src/StatusBarOptions.ts +++ b/packages/@uppy/status-bar/src/StatusBarOptions.ts @@ -1,14 +1,14 @@ -import type { UIPluginOptions } from '@uppy/core/src/UIPlugin.ts' +import type { UIPluginOptions } from '@uppy/core/lib/UIPlugin' import type StatusBarLocale from './locale.ts' export interface StatusBarOptions extends UIPluginOptions { - target: HTMLElement | string - showProgressDetails: boolean - hideUploadButton: boolean - hideAfterFinish: boolean - hideRetryButton: boolean - hidePauseResumeButton: boolean - hideCancelButton: boolean - doneButtonHandler: (() => void) | null + target?: HTMLElement | string + showProgressDetails?: boolean + hideUploadButton?: boolean + hideAfterFinish?: boolean + hideRetryButton?: boolean + hidePauseResumeButton?: boolean + hideCancelButton?: boolean + doneButtonHandler?: (() => void) | null locale?: typeof StatusBarLocale } From 9b694edf61a660a51ed5c4035d72005d31bf4181 Mon Sep 17 00:00:00 2001 From: Antoine du Hamel Date: Mon, 22 Jan 2024 17:22:00 +0100 Subject: [PATCH 2/3] fixup! @uppy/status-bar: fix `StatusBarOptions` type --- packages/@uppy/status-bar/src/StatusBar.tsx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/@uppy/status-bar/src/StatusBar.tsx b/packages/@uppy/status-bar/src/StatusBar.tsx index c22326c205..ff76bf6492 100644 --- a/packages/@uppy/status-bar/src/StatusBar.tsx +++ b/packages/@uppy/status-bar/src/StatusBar.tsx @@ -88,8 +88,8 @@ export default class StatusBar extends UIPlugin< #previousETA: number | null constructor(uppy: Uppy, opts?: StatusBarOptions) { - super(uppy, opts) - this.opts = { ...defaultOptions, ...opts, id: this.opts.id || 'StatusBar' } + super(uppy, { ...defaultOptions, ...opts }) + this.id = this.opts.id || 'StatusBar' this.title = 'StatusBar' this.type = 'progressindicator' From 7173488f555e16423470a2406499229605744916 Mon Sep 17 00:00:00 2001 From: Antoine du Hamel Date: Mon, 22 Jan 2024 17:29:18 +0100 Subject: [PATCH 3/3] add `satisfies` for the sake of it --- packages/@uppy/status-bar/src/StatusBar.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/@uppy/status-bar/src/StatusBar.tsx b/packages/@uppy/status-bar/src/StatusBar.tsx index ff76bf6492..2d7f64a31a 100644 --- a/packages/@uppy/status-bar/src/StatusBar.tsx +++ b/packages/@uppy/status-bar/src/StatusBar.tsx @@ -65,7 +65,7 @@ const defaultOptions = { showProgressDetails: false, hideAfterFinish: true, doneButtonHandler: null, -} +} satisfies StatusBarOptions /** * StatusBar: renders a status bar with upload/pause/resume/cancel/retry buttons,