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/progress-bar: refactor to TypeScript #4921

Merged
merged 12 commits into from
Feb 28, 2024
Next Next commit
port progress-bar
  • Loading branch information
mifi committed Feb 15, 2024
commit a074e1eba48964b05cea5e5112ea314f12fa31de
2 changes: 2 additions & 0 deletions packages/@uppy/progress-bar/.npmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@

tsconfig.*
Original file line number Diff line number Diff line change
@@ -1,16 +1,38 @@
import { h } from 'preact'
import { UIPlugin } from '@uppy/core'
import { h, type ComponentChild } from 'preact'
import { UIPlugin, Uppy, type UIPluginOptions } from '@uppy/core'
import type { Body, Meta } from '@uppy/utils/lib/UppyFile'

// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore We don't want TS to generate types for the package.json
import packageJson from '../package.json'


interface ProgressBarOptions extends UIPluginOptions {
target?: HTMLElement | string
hideAfterFinish?: boolean,
fixed?: boolean,
}
interface ProgressBarState {
audioReady: boolean
recordingLengthSeconds: number
hasAudio: boolean
cameraError: null
audioSources: MediaDeviceInfo[]
currentDeviceId?: null | string | MediaStreamTrack
isRecording: boolean
showAudioSourceDropdown: boolean
[id: string]: unknown
}

/**
* Progress bar
*
*/
export default class ProgressBar extends UIPlugin {
export default class ProgressBar<M extends Meta, B extends Body>
extends UIPlugin<ProgressBarOptions, M, B, ProgressBarState> {
static VERSION = packageJson.version

constructor (uppy, opts) {
constructor (uppy: Uppy<M, B>, opts?: ProgressBarOptions) {
super(uppy, opts)
this.id = this.opts.id || 'ProgressBar'
this.title = 'Progress Bar'
@@ -29,7 +51,7 @@ export default class ProgressBar extends UIPlugin {
this.render = this.render.bind(this)
}

render (state) {
render (state: ProgressBarState): ComponentChild {
const progress = state.totalProgress || 0
// before starting and after finish should be hidden if specified in the options
const isHidden = (progress === 0 || progress === 100) && this.opts.hideAfterFinish
@@ -45,14 +67,14 @@ export default class ProgressBar extends UIPlugin {
)
}

install () {
install (): void {
const { target } = this.opts
if (target) {
this.mount(target, this)
}
}

uninstall () {
uninstall (): void {
this.unmount()
}
}
1 change: 0 additions & 1 deletion packages/@uppy/progress-bar/src/index.js

This file was deleted.

1 change: 1 addition & 0 deletions packages/@uppy/progress-bar/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { default } from './ProgressBar.tsx'
35 changes: 35 additions & 0 deletions packages/@uppy/progress-bar/tsconfig.build.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
{
"extends": "../../../tsconfig.shared",
"compilerOptions": {
"noImplicitAny": false,
"outDir": "./lib",
"paths": {
"@uppy/utils/lib/*": [
"../utils/src/*"
],
"@uppy/core": [
"../core/src/index.js"
],
"@uppy/core/lib/*": [
"../core/src/*"
]
},
"resolveJsonModule": false,
"rootDir": "./src",
"skipLibCheck": true
},
"include": [
"./src/**/*.*"
],
"exclude": [
"./src/**/*.test.ts"
],
"references": [
{
"path": "../utils/tsconfig.build.json"
},
{
"path": "../core/tsconfig.build.json"
}
]
}
30 changes: 30 additions & 0 deletions packages/@uppy/progress-bar/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
{
"extends": "../../../tsconfig.shared",
"compilerOptions": {
"emitDeclarationOnly": false,
"noEmit": true,
"paths": {
"@uppy/utils/lib/*": [
"../utils/src/*"
],
"@uppy/core": [
"../core/src/index.js"
],
"@uppy/core/lib/*": [
"../core/src/*"
]
}
},
"include": [
"./package.json",
"./src/**/*.*"
],
"references": [
{
"path": "../utils/tsconfig.build.json"
},
{
"path": "../core/tsconfig.build.json"
}
]
}