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
1 change: 1 addition & 0 deletions packages/@uppy/progress-bar/.npmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
tsconfig.*
58 changes: 0 additions & 58 deletions packages/@uppy/progress-bar/src/ProgressBar.jsx

This file was deleted.

73 changes: 73 additions & 0 deletions packages/@uppy/progress-bar/src/ProgressBar.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
import { h, type ComponentChild } from 'preact'
import { UIPlugin, Uppy, type UIPluginOptions, type State } from '@uppy/core'
import type { Body, Meta } from '@uppy/utils/lib/UppyFile'
import type { DefinePluginOpts } from '@uppy/core/lib/BasePlugin.js'

// 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'

export interface ProgressBarOptions extends UIPluginOptions {
target?: HTMLElement | string
mifi marked this conversation as resolved.
Show resolved Hide resolved
hideAfterFinish?: boolean
fixed?: boolean
}
// set default options, must kept in sync with @uppy/react/src/ProgressBar.js
const defaultOptions = {
target: 'body',
fixed: false,
hideAfterFinish: true,
}

type Opts = DefinePluginOpts<ProgressBarOptions, keyof typeof defaultOptions>

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

constructor(uppy: Uppy<M, B>, 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<M, B>): 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
return (
<div
className="uppy uppy-ProgressBar"
style={{ position: this.opts.fixed ? 'fixed' : 'initial' }}
aria-hidden={isHidden}
>
<div
className="uppy-ProgressBar-inner"
style={{ width: `${progress}%` }}
/>
<div className="uppy-ProgressBar-percentage">{progress}</div>
</div>
)
}

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

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'
25 changes: 25 additions & 0 deletions packages/@uppy/progress-bar/tsconfig.build.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
{
"extends": "../../../tsconfig.shared",
"compilerOptions": {
"noImplicitAny": false,
Murderlon marked this conversation as resolved.
Show resolved Hide resolved
"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"
}
]
}
21 changes: 21 additions & 0 deletions packages/@uppy/progress-bar/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"extends": "../../../tsconfig.shared",
"compilerOptions": {
"emitDeclarationOnly": false,
Murderlon marked this conversation as resolved.
Show resolved Hide resolved
"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",
},
],
}
3 changes: 2 additions & 1 deletion packages/@uppy/status-bar/src/StatusBar.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import type { ComponentChild } from 'preact'
import type { Body, Meta, UppyFile } from '@uppy/utils/lib/UppyFile'
import type { Uppy, State } from '@uppy/core/src/Uppy.ts'
import type { DefinePluginOpts } from '@uppy/core/lib/BasePlugin.ts'
Expand Down Expand Up @@ -151,7 +152,7 @@ export default class StatusBar<M extends Meta, B extends Body> extends UIPlugin<
}) as () => undefined)
}

render(state: State<M, B>): JSX.Element {
render(state: State<M, B>): ComponentChild {
const {
capabilities,
files,
Expand Down