Skip to content

Commit

Permalink
@uppy/informer: migrate to TS (#4967)
Browse files Browse the repository at this point in the history
  • Loading branch information
Murderlon committed Feb 27, 2024
1 parent 71a8e54 commit 8cb3840
Show file tree
Hide file tree
Showing 8 changed files with 159 additions and 60 deletions.
1 change: 1 addition & 0 deletions packages/@uppy/informer/.npmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
tsconfig.*
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
import { h, Component, createRef } from 'preact'
import { h, Component, createRef, type ComponentChild } from 'preact'

const TRANSITION_MS = 300

export default class FadeIn extends Component {
ref = createRef()

componentWillEnter (callback) {
componentWillEnter(callback: () => void): void {
this.ref.current.style.opacity = '1'
this.ref.current.style.transform = 'none'
setTimeout(callback, TRANSITION_MS)
}

componentWillLeave (callback) {
componentWillLeave(callback: () => void): void {
this.ref.current.style.opacity = '0'
this.ref.current.style.transform = 'translateY(350%)'
setTimeout(callback, TRANSITION_MS)
}

render () {
render(): ComponentChild {
const { children } = this.props

return (
Expand Down
Original file line number Diff line number Diff line change
@@ -1,51 +1,57 @@
/* eslint-disable jsx-a11y/no-noninteractive-element-interactions */
/* eslint-disable jsx-a11y/click-events-have-key-events */
import { h } from 'preact'
import { h, type ComponentChild } from 'preact'
import { UIPlugin } from '@uppy/core'
import FadeIn from './FadeIn.jsx'
import TransitionGroup from './TransitionGroup.js'
import type { State, UIPluginOptions, Uppy } from '@uppy/core'
import type { Body, Meta } from '@uppy/utils/lib/UppyFile'
import FadeIn from './FadeIn.tsx'
import TransitionGroup from './TransitionGroup.ts'

// 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 type InformerOptions = UIPluginOptions

/**
* Informer
* Shows rad message bubbles
* used like this: `uppy.info('hello world', 'info', 5000)`
* or for errors: `uppy.info('Error uploading img.jpg', 'error', 5000)`
*
*/
export default class Informer extends UIPlugin {
export default class Informer<M extends Meta, B extends Body> extends UIPlugin<
UIPluginOptions,
M,
B
> {
static VERSION = packageJson.version

constructor (uppy, opts) {
constructor(uppy: Uppy<M, B>, opts?: UIPluginOptions) {
super(uppy, opts)
this.type = 'progressindicator'
this.id = this.opts.id || 'Informer'
this.title = 'Informer'

// set default options
const defaultOptions = {}
// merge default options with the ones set by user
this.opts = { ...defaultOptions, ...opts }
}

render = (state) => {
render = (state: State<M, B>): ComponentChild => {
return (
<div className="uppy uppy-Informer">
<TransitionGroup>
{state.info.map((info) => (
<FadeIn key={info.message}>
<p role="alert">
{info.message}
{' '}
{info.message}{' '}
{info.details && (
<span
aria-label={info.details}
data-microtip-position="top-left"
data-microtip-size="medium"
role="tooltip"
// eslint-disable-next-line no-alert
onClick={() => alert(`${info.message} \n\n ${info.details}`)}
onClick={() =>
// eslint-disable-next-line no-alert
alert(`${info.message} \n\n ${info.details}`)
}
>
?
</span>
Expand All @@ -58,7 +64,7 @@ export default class Informer extends UIPlugin {
)
}

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

0 comments on commit 8cb3840

Please sign in to comment.