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.

71 changes: 71 additions & 0 deletions packages/@uppy/progress-bar/src/ProgressBar.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
import { h, type ComponentChild } from 'preact'
import { UIPlugin, Uppy, type UIPluginOptions } 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<M extends Meta, B extends Body> extends UIPluginOptions {

Check warning on line 11 in packages/@uppy/progress-bar/src/ProgressBar.tsx

View workflow job for this annotation

GitHub Actions / Lint JavaScript/TypeScript

'M' is defined but never used

Check warning on line 11 in packages/@uppy/progress-bar/src/ProgressBar.tsx

View workflow job for this annotation

GitHub Actions / Lint JavaScript/TypeScript

'B' is defined but never used
mifi marked this conversation as resolved.
Show resolved Hide resolved
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<M extends Meta, B extends Body> = DefinePluginOpts<
ProgressBarOptions<M, B>,
mifi marked this conversation as resolved.
Show resolved Hide resolved
keyof typeof defaultOptions
>

/**
* Progress bar
*
*/
export default class ProgressBar<M extends Meta, B extends Body>
extends UIPlugin<Opts<M, B>, M, B> {
mifi marked this conversation as resolved.
Show resolved Hide resolved
static VERSION = packageJson.version

constructor (uppy: Uppy<M, B>, opts?: ProgressBarOptions<M, B>) {
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: ProgressBarState): ComponentChild {

Check failure on line 45 in packages/@uppy/progress-bar/src/ProgressBar.tsx

View workflow job for this annotation

GitHub Actions / Type tests

Cannot find name 'ProgressBarState'.

Check failure on line 45 in packages/@uppy/progress-bar/src/ProgressBar.tsx

View workflow job for this annotation

GitHub Actions / Type tests

Cannot find name 'ProgressBarState'.
Murderlon marked this conversation as resolved.
Show resolved Hide resolved
mifi marked this conversation as resolved.
Show resolved Hide resolved
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'
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,
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"
}
]
}
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,
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"
}
]
}