/** * A base component for svg/img graphics * https://github.com/yr/graphics-component * @copyright Yr * @license MIT */ import React from 'react'; export type GraphicType = 'img' | 'svg'; export interface GraphicProps { fallback?: boolean; height?: string; id: string; rootImagePath?: string; type?: GraphicType; width?: string; } export class Graphic extends React.PureComponent { static defaultProps = { type: 'svg', fallback: true, height: '25px', width: '25px' }; render() { const { id, type, fallback, height, width } = this.props; let { rootImagePath = '' } = this.props; if (!id) { return null; } if (rootImagePath && rootImagePath.charAt(rootImagePath.length - 1) !== '/') { rootImagePath += '/'; } if (type === 'svg') { return ( {fallback ? ( // @ts-ignore src is a valid attribute on the tag ) : null} ); } else { return ; } } }