mirror of
https://github.com/SomboChea/ui
synced 2024-05-18 09:21:37 +07:00
67d7188cf5
* 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
59 lines
1.6 KiB
TypeScript
59 lines
1.6 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 { DetailContextConsumer } from '../../pages/Version';
|
|
import CopyToClipBoard from '../CopyToClipBoard';
|
|
|
|
import { Heading, GithubLink, RepositoryListItem, RepositoryListItemText } 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="subtitle1">{'Repository'}</Heading>}>
|
|
<RepositoryListItem button={true}>
|
|
<Avatar src={git} />
|
|
<RepositoryListItemText primary={this.renderContent(url)} />
|
|
</RepositoryListItem>
|
|
</List>
|
|
</Fragment>
|
|
);
|
|
};
|
|
|
|
private renderContent(url: string): ReactElement<HTMLElement> {
|
|
return <CopyToClipBoard text={url}>{this.renderRepositoryText(url)}</CopyToClipBoard>;
|
|
}
|
|
}
|
|
|
|
export default Repository;
|