1
0
mirror of https://github.com/uetchy/namae.git synced 2025-07-04 23:30:03 +09:00
namae/src/components/Contributors.tsx

72 lines
1.5 KiB
TypeScript
Raw Normal View History

2020-08-20 00:57:33 +09:00
import React from 'react'
import styled from 'styled-components'
import useSWR from 'swr'
2020-07-30 15:39:14 +09:00
export interface Contributors {
2020-08-20 00:57:33 +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-20 00:57:33 +09:00
login: string
name: string
avatar_url: string
profile: string
contributions: string[]
2020-07-30 15:39:14 +09:00
}
2020-08-20 00:57:33 +09:00
const fetcher = (url: string) => fetch(url).then((r) => r.json())
2020-07-30 15:39:14 +09:00
const Contributors: React.FC = () => {
const { data } = useSWR<Contributors>(
'https://raw.githubusercontent.com/uetchy/namae/master/.all-contributorsrc',
2020-08-20 00:57:33 +09:00
fetcher
)
2020-07-30 15:39:14 +09:00
2020-08-20 00:57:33 +09:00
if (!data) return <Container>Loading</Container>
2020-07-30 15:39:14 +09:00
return (
<Container>
{data.contributors.map((contributor) => (
<Item key={contributor.login}>
<a
href={contributor.profile}
target="_blank"
rel="noopener noreferrer"
>
<Avatar src={contributor.avatar_url} alt={contributor.name} />
</a>
</Item>
))}
</Container>
2020-08-20 00:57:33 +09:00
)
}
2020-07-30 15:39:14 +09:00
const Container = styled.div`
display: flex;
flex-direction: row;
2020-08-20 00:57:33 +09:00
`
2020-07-30 15:39:14 +09:00
const Item = styled.div`
margin-left: 10px;
:first-child {
margin-left: 0;
}
2020-08-20 00:57:33 +09:00
`
2020-07-30 15:39:14 +09:00
2020-08-20 00:57:33 +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-20 00:57:33 +09:00
`
2020-07-30 15:39:14 +09:00
2020-08-20 00:57:33 +09:00
export default Contributors