Merge pull request #28944 from 8enSmith/react-image-fallback

Added typings for react-image-fallback package
This commit is contained in:
Nathan Shively-Sanders
2018-09-18 10:47:40 -07:00
committed by GitHub
4 changed files with 89 additions and 0 deletions
+25
View File
@@ -0,0 +1,25 @@
// 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
// TypeScript Version: 2.8
import * as React from "react";
export default class ReactImageFallback extends React.Component<
ReactImageFallbackProps &
React.DetailedHTMLProps<
React.ImgHTMLAttributes<HTMLImageElement>,
HTMLImageElement
>,
any
> { }
export interface ReactImageFallbackProps {
src: string;
fallbackImage: string | React.ReactElement<any> | string[] | Array<React.ReactElement<any>>;
initialImage?: string | React.ReactElement<any>;
onLoad?: (event: React.SyntheticEvent<HTMLImageElement>) => void;
onError?: (event: React.SyntheticEvent<HTMLImageElement>) => void;
initialTimeout?: number;
}
@@ -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" />;
}
}
+24
View File
@@ -0,0 +1,24 @@
{
"compilerOptions": {
"module": "commonjs",
"lib": [
"es6"
],
"noImplicitAny": true,
"noImplicitThis": true,
"strictNullChecks": true,
"strictFunctionTypes": 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" }