react: fix typescript proptypes for DashboardModal, fixes #2124 (#2136)

This commit is contained in:
Renée Kooi 2020-03-16 15:22:03 +01:00 committed by GitHub
parent 0aa511a476
commit ab3d7cb067
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 32 additions and 4 deletions

View file

@ -1,13 +1,23 @@
import { DashboardProps } from './Dashboard'
import { Omit, ToUppyProps } from './CommonTypes'
import Dashboard = require('@uppy/dashboard')
export interface DashboardModalProps extends DashboardProps {
// This type is mapped into `DashboardModalProps` below so IntelliSense doesn't display this big mess of nested types
type DashboardModalPropsInner = {
open?: boolean
onRequestClose?: VoidFunction
} & Omit<
ToUppyProps<Dashboard.DashboardOptions>,
// Remove the inline-only and force-overridden props
'inline' | 'onRequestCloseModal'
>
export type DashboardModalProps = {
[K in keyof DashboardModalPropsInner]: DashboardModalPropsInner[K]
}
/**
* React Component that renders a Dashboard for an Uppy instance in a Modal
* dialog. Visibility of the Modal is toggled using the `open` prop.
* React Component that renders a Dashboard for an Uppy instance. This component
* renders the Dashboard inline so you can put it anywhere you want.
*/
declare const DashboardModal: React.ComponentType<DashboardModalProps>
export default DashboardModal

View file

@ -18,6 +18,8 @@ function TestComponent() {
// inline option should be removed from proptypes because it is always overridden
// by the component
expectError(<components.Dashboard inline />)
expectError(<components.DashboardModal inline />)
expectError(<components.DashboardModal replaceTargetContent />)
{
const el = (
@ -38,3 +40,19 @@ expectError(<components.Dashboard inline />)
/>
)
}
{
const el = (
<components.DashboardModal
uppy={uppy}
open
animateOpenClose
onRequestClose={() => {
alert('no')
}}
/>
)
// use onRequestClose instead.
expectError(<components.DashboardModal onRequestCloseModal />)
}