1
0
Fork 1
mirror of https://github.com/SomboChea/ui synced 2024-05-18 09:21:37 +07:00
verdaccio-ui/src/components/Author/Author.tsx
Juan Picado @jotadeveloper 67d7188cf5
feat: update material-ui@4.x (#123)
* chore: update material-ui@4.x

* test: update test for ActionBar and TestField

* chore: add types

* chore: update types

* test: update test for Author

* chore: fixed bunch of unit test

* chore: remove unused import

* chore: remove comments

* chore: replace shallow my mount

* chore: update git hooks

* chore: fix styles

* chore: update dependencies

* chore: remove types material-ui
2019-08-31 02:02:46 -07:00

59 lines
1.6 KiB
TypeScript

import React, { Component, ReactNode, ReactElement } from 'react';
import Avatar from '@material-ui/core/Avatar';
import List from '@material-ui/core/List';
import { DetailContextConsumer } from '../../pages/Version';
import { Heading, AuthorListItem, AuthorListItemText } from './styles';
import { isEmail } from '../../utils/url';
class Authors extends Component {
public render(): ReactElement<HTMLElement> {
return (
<DetailContextConsumer>
{context => {
const { packageMeta } = context;
if (!packageMeta) {
return null;
}
return this.renderAuthor(packageMeta);
}}
</DetailContextConsumer>
);
}
public renderLinkForMail(email: string, avatarComponent: ReactNode, packageName: string, version: string): ReactElement<HTMLElement> | ReactNode {
if (!email || isEmail(email) === false) {
return avatarComponent;
}
return (
<a href={`mailto:${email}?subject=${packageName}@${version}`} target={'_top'}>
{avatarComponent}
</a>
);
}
public renderAuthor = ({ latest }) => {
const { author, name: packageName, version } = latest;
if (!author) {
return null;
}
const avatarComponent = <Avatar alt={author.name} src={author.avatar} />;
return (
<List subheader={<Heading variant={'subtitle1'}>{'Author'}</Heading>}>
<AuthorListItem button={true}>
{this.renderLinkForMail(author.email, avatarComponent, packageName, version)}
<AuthorListItemText primary={author.name} />
</AuthorListItem>
</List>
);
};
}
export default Authors;