verdaccio-ui/src/components/Author/Author.tsx

45 lines
1.1 KiB
TypeScript
Raw Normal View History

import React, { FC, useContext } from 'react';
2019-02-03 17:23:33 +07:00
import { DetailContext } from '../../pages/Version';
import { isEmail } from '../../utils/url';
2019-10-06 23:30:05 +07:00
import Avatar from '../../muiComponents/Avatar';
2019-10-13 03:26:56 +07:00
import List from '../../muiComponents/List';
2019-10-06 23:30:05 +07:00
import { StyledText, AuthorListItem, AuthorListItemText } from './styles';
2019-10-06 23:30:05 +07:00
const Author: FC = () => {
const { packageMeta } = useContext(DetailContext);
if (!packageMeta) {
return null;
2019-02-03 17:23:33 +07:00
}
const { author, name: packageName, version } = packageMeta.latest;
if (!author) {
return null;
2019-03-28 05:39:06 +07:00
}
const { email, name } = author;
const avatarComponent = <Avatar alt={author.name} src={author.avatar} />;
return (
<List subheader={<StyledText variant={'subtitle1'}>{'Author'}</StyledText>}>
<AuthorListItem button={true}>
{!email || !isEmail(email) ? (
avatarComponent
) : (
<a href={`mailto:${email}?subject=${packageName}@${version}`} target={'_top'}>
{avatarComponent}
</a>
)}
<AuthorListItemText primary={name} />
</AuthorListItem>
</List>
);
};
2019-02-03 17:23:33 +07:00
2019-10-06 23:30:05 +07:00
export default Author;