Added typings for react-image-fallback package

This commit is contained in:
UCLES\smithd
2018-09-17 16:05:01 +01:00
parent 6d9d1c7a92
commit f7fac83320
4 changed files with 91 additions and 0 deletions
+28
View File
@@ -0,0 +1,28 @@
// Type definitions for react-image-fallback 8.0
// Project: https://github.com/socialtables/react-image-fallback
// Definitions by: Ben Smith <https://github.com/8enSmith>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
declare module "react-image-fallback" {
import * as React from "react"
class ReactImageFallback extends React.Component<
ReactImageFallbackProps &
React.DetailedHTMLProps<
React.ImgHTMLAttributes<HTMLImageElement>,
HTMLImageElement
>,
any
> { }
export interface ReactImageFallbackProps {
src: string
fallbackImage: string | React.ReactElement<any> | any[]
initialImage?: string | React.ReactElement<any>
onLoad?: (event: React.SyntheticEvent<HTMLImageElement>) => void
onError?: (event: React.SyntheticEvent<HTMLImageElement>) => void
initialTimeout?: number
}
export default ReactImageFallback
}
@@ -0,0 +1,39 @@
import * as React from 'react';
import ReactImageFallback, { ReactImageFallbackProps } from 'react-image-fallback';
class ReactImageFallbackSimple extends React.Component<ReactImageFallbackProps> {
render() {
return <ReactImageFallback
src="my-image.png"
fallbackImage="my-backup.png" />;
}
}
class ReactImageFallbackWithOptionals extends React.Component<ReactImageFallbackProps> {
onLoad(event: React.SyntheticEvent<HTMLImageElement>) {
}
onError(event: React.SyntheticEvent<HTMLImageElement>) {
}
render() {
return <ReactImageFallback
src="my-image.png"
fallbackImage="my-backup.png"
initialImage="loader.gif"
onLoad={this.onLoad}
onError={this.onError}
initialTimeout={1000} />;
}
}
class ReactImageFallbackWithImageTagProps extends React.Component<ReactImageFallbackProps> {
render() {
return <ReactImageFallback
src="my-image.png"
fallbackImage="my-backup.png"
alt="alt text"
width="123"
className="customClass" />;
}
}
+23
View File
@@ -0,0 +1,23 @@
{
"compilerOptions": {
"module": "commonjs",
"lib": [
"es6"
],
"noImplicitAny": true,
"noImplicitThis": true,
"strictNullChecks": true,
"baseUrl": "../",
"typeRoots": [
"../"
],
"types": [],
"noEmit": true,
"forceConsistentCasingInFileNames": true,
"jsx": "react"
},
"files": [
"index.d.ts",
"react-image-fallback-tests.tsx"
]
}
+1
View File
@@ -0,0 +1 @@
{ "extends": "dtslint/dt.json" }