import * as React from "react"; import { ComponentProps } from "./BaseComponent"; import styled from "styled-components"; export interface StyledImageProps { defaultImageUrl: string; imageUrl?: string; backgroundColor?: string; } export const StyledImage = styled.div< StyledImageProps & { imageError: boolean; } >` position: relative; display: flex; flex-direction: "row"; background: ${props => props.backgroundColor}; background-image: url("${props => props.imageError ? props.defaultImageUrl : props.imageUrl}"); background-position: center; background-repeat: no-repeat; background-size: contain; height: 100%; width: 100%; `; class ImageComponent extends React.Component< ImageComponentProps, { imageError: boolean; } > { constructor(props: ImageComponentProps) { super(props); this.state = { imageError: false, }; } render() { return ( {this.props.widgetName} ); } onImageError = () => { this.setState({ imageError: true, }); }; onImageLoad = () => { this.setState({ imageError: false, }); }; } export interface ImageComponentProps extends ComponentProps { imageUrl: string; defaultImageUrl: string; isLoading: boolean; } export default ImageComponent;