1
0
mirror of https://github.com/SomboChea/ui synced 2024-11-05 06:04:28 +07:00
verdaccio-ui/src/components/Repository/Repository.tsx
2019-06-24 21:42:34 +01:00

60 lines
1.7 KiB
TypeScript

/* eslint react/jsx-max-depth: 0 */
import React, { Component, Fragment, 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/Version';
import CopyToClipBoard from '../CopyToClipBoard';
import { Heading, GithubLink, RepositoryListItem } from './styles';
import git from './img/git.png';
import { isURL } from '../../utils/url';
class Repository extends Component {
public render(): ReactElement<HTMLElement> {
return (
<DetailContextConsumer>
{context => {
return context && context.packageMeta && this.renderRepository(context.packageMeta);
}}
</DetailContextConsumer>
);
}
private renderRepositoryText(url: string): ReactElement<HTMLElement> {
return (
<GithubLink href={url} target="_blank">
{url}
</GithubLink>
);
}
private renderRepository = packageMeta => {
const { repository: { url = null } = {} } = packageMeta.latest;
if (!url || isURL(url) === false) {
return null;
}
return (
<Fragment>
<List dense={true} subheader={<Heading variant="subheading">{'Repository'}</Heading>}>
<RepositoryListItem>
<Avatar src={git} />
<ListItemText primary={this.renderContent(url)} />
</RepositoryListItem>
</List>
</Fragment>
);
};
private renderContent(url: string): ReactElement<HTMLElement> {
return <CopyToClipBoard text={url}>{this.renderRepositoryText(url)}</CopyToClipBoard>;
}
}
export default Repository;