Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

@uppy/status-bar: fix StatusBarOptions type #4883

Merged
merged 3 commits into from
Jan 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 16 additions & 17 deletions packages/@uppy/status-bar/src/StatusBar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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,
} satisfies StatusBarOptions

/**
* StatusBar: renders a status bar with upload/pause/resume/cancel/retry buttons,
* progress percentage and time remaining.
*/
export default class StatusBar<M extends Meta, B extends Body> extends UIPlugin<
StatusBarOptions,
StatusBarOptions &
Required<Pick<StatusBarOptions, keyof typeof defaultOptions>>,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if we're going to do this for every plugin, maybe we can do a utility type?

- StatusBarOptions & Required<Pick<StatusBarOptions, keyof typeof defaultOptions>
+ PluginOpts<StatusBarOptions, defaultOptions>

M,
B
> {
Expand All @@ -74,28 +87,14 @@ export default class StatusBar<M extends Meta, B extends Body> extends UIPlugin<

#previousETA: number | null

constructor(uppy: Uppy<M, B>, opts?: Partial<StatusBarOptions>) {
super(uppy, opts)
constructor(uppy: Uppy<M, B>, opts?: StatusBarOptions) {
super(uppy, { ...defaultOptions, ...opts })
this.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)
Expand Down
18 changes: 9 additions & 9 deletions packages/@uppy/status-bar/src/StatusBarOptions.ts
Original file line number Diff line number Diff line change
@@ -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
}
Loading