import React, { Component, ReactNode, ReactElement } from 'react'; import Avatar from '@material-ui/core/Avatar'; import List from '@material-ui/core/List'; import ListItemText from '@material-ui/core/ListItemText'; import { DetailContextConsumer } from '../../pages/Version'; import { Heading, AuthorListItem } from './styles'; import { isEmail } from '../../utils/url'; class Authors extends Component { public render(): ReactElement { return ( {context => { return context && context.packageMeta && this.renderAuthor(context.packageMeta); }} ); } public renderLinkForMail(email: string, avatarComponent: ReactNode, packageName: string, version: string): ReactElement | ReactNode { if (!email || isEmail(email) === false) { return avatarComponent; } return ( {avatarComponent} ); } public renderAuthor = packageMeta => { const { author, name: packageName, version } = packageMeta.latest; if (!author) { return null; } const avatarComponent = ; return ( {'Author'}}> {this.renderLinkForMail(author.email, avatarComponent, packageName, version)} ); }; } export default Authors;