From da46eefe2eea9507ae12ed678b15047f1c74366f Mon Sep 17 00:00:00 2001 From: Brandon Millman Date: Mon, 18 Jun 2018 12:09:31 -0700 Subject: Create a shared Image component --- .../components/relayer_index/relayer_grid_tile.tsx | 46 ++++++---------------- packages/website/ts/components/ui/image.tsx | 37 +++++++++++++++++ 2 files changed, 48 insertions(+), 35 deletions(-) create mode 100644 packages/website/ts/components/ui/image.tsx (limited to 'packages/website/ts') diff --git a/packages/website/ts/components/relayer_index/relayer_grid_tile.tsx b/packages/website/ts/components/relayer_index/relayer_grid_tile.tsx index 0b0e75312..98d6dc0b3 100644 --- a/packages/website/ts/components/relayer_index/relayer_grid_tile.tsx +++ b/packages/website/ts/components/relayer_index/relayer_grid_tile.tsx @@ -5,6 +5,7 @@ import * as React from 'react'; import { TopTokens } from 'ts/components/relayer_index/relayer_top_tokens'; import { Container } from 'ts/components/ui/container'; +import { Image } from 'ts/components/ui/image'; import { Island } from 'ts/components/ui/island'; import { colors } from 'ts/style/colors'; import { WebsiteBackendRelayerInfo } from 'ts/types'; @@ -74,8 +75,16 @@ export const RelayerGridTile: React.StatelessComponent = (
-
- +
+
@@ -112,36 +121,3 @@ const Section = (props: SectionProps) => { }; const NoContent = () =>
{NO_CONTENT_MESSAGE}
; - -interface ImgWithFallbackProps { - src?: string; - fallbackSrc: string; -} -interface ImgWithFallbackState { - imageLoadFailed: boolean; -} -class ImgWithFallback extends React.Component { - constructor(props: ImgWithFallbackProps) { - super(props); - this.state = { - imageLoadFailed: false, - }; - } - public render(): React.ReactNode { - return ( -
- {this._renderImg()} -
- ); - } - private _renderImg(): React.ReactNode { - const src = - this.state.imageLoadFailed || _.isUndefined(this.props.src) ? this.props.fallbackSrc : this.props.src; - return ; - } - private _onError(): void { - this.setState({ - imageLoadFailed: true, - }); - } -} diff --git a/packages/website/ts/components/ui/image.tsx b/packages/website/ts/components/ui/image.tsx new file mode 100644 index 000000000..0958d2e5e --- /dev/null +++ b/packages/website/ts/components/ui/image.tsx @@ -0,0 +1,37 @@ +import * as _ from 'lodash'; +import * as React from 'react'; + +export interface ImageProps { + className?: string; + src?: string; + fallbackSrc?: string; + height?: string; +} +interface ImageState { + imageLoadFailed: boolean; +} +export class Image extends React.Component { + constructor(props: ImageProps) { + super(props); + this.state = { + imageLoadFailed: false, + }; + } + public render(): React.ReactNode { + const src = + this.state.imageLoadFailed || _.isUndefined(this.props.src) ? this.props.fallbackSrc : this.props.src; + return ( + + ); + } + private _onError(): void { + this.setState({ + imageLoadFailed: true, + }); + } +} -- cgit v1.2.3