aboutsummaryrefslogtreecommitdiffstats
path: root/packages/website/ts/components/ui
diff options
context:
space:
mode:
authorBrandon Millman <brandon.millman@gmail.com>2018-06-19 03:09:31 +0800
committerBrandon Millman <brandon.millman@gmail.com>2018-06-19 03:09:31 +0800
commitda46eefe2eea9507ae12ed678b15047f1c74366f (patch)
treef0734b0cce7381221fb4d6a0c8d03c9d97bca6ba /packages/website/ts/components/ui
parent2ad411ea290697fc33786f9a0daa32116d51bd09 (diff)
downloaddexon-sol-tools-da46eefe2eea9507ae12ed678b15047f1c74366f.tar
dexon-sol-tools-da46eefe2eea9507ae12ed678b15047f1c74366f.tar.gz
dexon-sol-tools-da46eefe2eea9507ae12ed678b15047f1c74366f.tar.bz2
dexon-sol-tools-da46eefe2eea9507ae12ed678b15047f1c74366f.tar.lz
dexon-sol-tools-da46eefe2eea9507ae12ed678b15047f1c74366f.tar.xz
dexon-sol-tools-da46eefe2eea9507ae12ed678b15047f1c74366f.tar.zst
dexon-sol-tools-da46eefe2eea9507ae12ed678b15047f1c74366f.zip
Create a shared Image component
Diffstat (limited to 'packages/website/ts/components/ui')
-rw-r--r--packages/website/ts/components/ui/image.tsx37
1 files changed, 37 insertions, 0 deletions
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<ImageProps, ImageState> {
+ 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 (
+ <img
+ className={this.props.className}
+ onError={this._onError.bind(this)}
+ src={src}
+ height={this.props.height}
+ />
+ );
+ }
+ private _onError(): void {
+ this.setState({
+ imageLoadFailed: true,
+ });
+ }
+}