2020-08-31 08:41:53 +09:00
|
|
|
import React from 'react';
|
|
|
|
import styled from 'styled-components';
|
|
|
|
import useSWR from 'swr';
|
2021-02-25 18:37:06 +09:00
|
|
|
import Tooltip from 'rc-tooltip';
|
2020-07-30 15:39:14 +09:00
|
|
|
|
2021-02-25 16:48:45 +09:00
|
|
|
export interface IContributors {
|
2020-08-31 08:41:53 +09:00
|
|
|
projectName: string;
|
|
|
|
projectOwner: string;
|
|
|
|
repoType: string;
|
|
|
|
repoHost: string;
|
|
|
|
files: string[];
|
|
|
|
imageSize: number;
|
|
|
|
commit: boolean;
|
|
|
|
commitConvention: string;
|
|
|
|
contributors: Contributor[];
|
|
|
|
contributorsPerLine: number;
|
|
|
|
skipCi: boolean;
|
2020-07-30 15:39:14 +09:00
|
|
|
}
|
|
|
|
|
|
|
|
export interface Contributor {
|
2020-08-31 08:41:53 +09:00
|
|
|
login: string;
|
|
|
|
name: string;
|
|
|
|
avatar_url: string;
|
|
|
|
profile: string;
|
|
|
|
contributions: string[];
|
2020-07-30 15:39:14 +09:00
|
|
|
}
|
|
|
|
|
2020-08-31 08:41:53 +09:00
|
|
|
const fetcher = (url: string) => fetch(url).then((r) => r.json());
|
2020-07-30 15:39:14 +09:00
|
|
|
|
|
|
|
const Contributors: React.FC = () => {
|
2021-02-25 16:48:45 +09:00
|
|
|
const { data } = useSWR<IContributors>(
|
2020-07-30 15:39:14 +09:00
|
|
|
'https://raw.githubusercontent.com/uetchy/namae/master/.all-contributorsrc',
|
2020-08-20 00:57:33 +09:00
|
|
|
fetcher
|
2020-08-31 08:41:53 +09:00
|
|
|
);
|
2020-07-30 15:39:14 +09:00
|
|
|
|
2020-08-31 08:41:53 +09:00
|
|
|
if (!data) return <Container>Loading</Container>;
|
2020-07-30 15:39:14 +09:00
|
|
|
|
|
|
|
return (
|
|
|
|
<Container>
|
|
|
|
{data.contributors.map((contributor) => (
|
2021-02-25 18:37:06 +09:00
|
|
|
<Tooltip
|
|
|
|
overlay={`${contributor.name} (${contributor.contributions.join(
|
|
|
|
', '
|
|
|
|
)})`}
|
|
|
|
placement="top"
|
|
|
|
trigger={['hover']}
|
|
|
|
>
|
|
|
|
<Item key={contributor.login}>
|
|
|
|
<a
|
|
|
|
href={contributor.profile}
|
|
|
|
target="_blank"
|
|
|
|
rel="noopener noreferrer"
|
|
|
|
>
|
|
|
|
<Avatar src={contributor.avatar_url} alt={contributor.name} />
|
|
|
|
</a>
|
|
|
|
</Item>
|
|
|
|
</Tooltip>
|
2020-07-30 15:39:14 +09:00
|
|
|
))}
|
|
|
|
</Container>
|
2020-08-31 08:41:53 +09:00
|
|
|
);
|
|
|
|
};
|
2020-07-30 15:39:14 +09:00
|
|
|
|
|
|
|
const Container = styled.div`
|
|
|
|
display: flex;
|
|
|
|
flex-direction: row;
|
2020-08-31 08:41:53 +09:00
|
|
|
`;
|
2020-07-30 15:39:14 +09:00
|
|
|
|
|
|
|
const Item = styled.div`
|
|
|
|
margin-left: 10px;
|
|
|
|
:first-child {
|
|
|
|
margin-left: 0;
|
|
|
|
}
|
2020-08-31 08:41:53 +09:00
|
|
|
`;
|
2020-07-30 15:39:14 +09:00
|
|
|
|
2020-08-31 08:41:53 +09:00
|
|
|
const avatarSize = 32;
|
2020-07-30 15:39:14 +09:00
|
|
|
const Avatar = styled.img.attrs({ width: avatarSize, height: avatarSize })`
|
|
|
|
border-radius: ${avatarSize}px;
|
2020-08-31 08:41:53 +09:00
|
|
|
`;
|
2020-07-30 15:39:14 +09:00
|
|
|
|
2020-08-31 08:41:53 +09:00
|
|
|
export default Contributors;
|