code/components/Repository.tsx

117 lines
2.9 KiB
TypeScript
Raw Normal View History

2021-10-17 18:41:15 +00:00
import { GithubLanguage } from '../types/github';
2021-07-12 08:23:02 +00:00
const image = {
folder: 'folder.svg',
star: 'star.svg',
};
2021-07-05 18:32:33 +00:00
function getLanguageColor(language: GithubLanguage) {
2021-07-12 08:23:02 +00:00
if (!language) {
return;
}
2021-07-05 18:32:33 +00:00
2021-07-12 08:23:02 +00:00
switch (language.toLowerCase()) {
case 'go':
return '#a1d5ed';
2021-07-05 18:32:33 +00:00
2021-07-12 08:23:02 +00:00
case 'julia':
return '#d35bde';
2021-07-05 18:32:33 +00:00
2021-07-12 08:23:02 +00:00
case 'javascript':
return '#e4f060';
2021-07-05 18:32:33 +00:00
2021-07-12 08:23:02 +00:00
case 'typescript':
return '#4e85de';
2021-07-05 18:32:33 +00:00
2021-07-12 08:23:02 +00:00
case 'vue':
return '#4ede85';
2021-07-05 18:32:33 +00:00
2021-07-12 08:23:02 +00:00
case 'shell':
return '#9dde4e';
2021-07-05 18:32:33 +00:00
2021-07-12 08:23:02 +00:00
case 'html':
return '#de704e';
2021-07-05 18:32:33 +00:00
2021-07-12 08:23:02 +00:00
default:
return '#bab7b6';
2021-07-05 18:32:33 +00:00
}
2021-07-12 08:23:02 +00:00
}
2021-07-05 18:32:33 +00:00
interface Props {
url: string;
name: string;
description: string;
language: string;
stars: number;
}
function Repository(props: Partial<Props>) {
2021-07-05 18:32:33 +00:00
return (
2022-08-06 08:44:27 +00:00
<div class='flex flex-col py-4 px-2 lg:px-0 opacity-80 hover:opacity-100 transition duration-500 ease-in-out'>
<div class='flex-1 text-sm hover:text-blue-300 font-bold transition duration-500 ease-in-out'>
<a href={props.url}>
2022-08-06 08:44:27 +00:00
<div class='flex flex-row items-center'>
<div class='flex-initial'>
2021-07-05 18:32:33 +00:00
<img
src={image.folder}
2022-08-06 08:44:27 +00:00
class='text-black dark:text-white h-3 w-3 fill-current inline'
alt='Repository'
2021-07-05 18:32:33 +00:00
/>
</div>
2022-08-06 08:44:27 +00:00
<div class='flex-initial px-4'>
{ props.name }
2021-07-05 18:32:33 +00:00
</div>
</div>
</a>
</div>
2022-08-06 08:44:27 +00:00
<div class='flex-2 text-xs opacity-80 lg:w-2/3'>
{ props.description }
2021-07-05 18:32:33 +00:00
</div>
2022-08-06 08:44:27 +00:00
<div class='flex-1'>
<div class='flex flex-row items-center'>
<div class='flex-1 text-xs'>
<div class='flex flex-row items-center content-center'>
<div class='flex-initial'>
2021-07-05 18:32:33 +00:00
<svg
2022-08-06 08:44:27 +00:00
v-show='language'
class='h-2 w-2 inline'
viewBox='0 0 100 100'
2021-07-05 18:32:33 +00:00
>
<circle
2022-08-06 08:44:27 +00:00
cx='50'
cy='50'
r='40'
fill={getLanguageColor(props.language as GithubLanguage)}
2021-07-05 18:32:33 +00:00
/>
</svg>
</div>
2022-08-06 08:44:27 +00:00
<div class='flex-initial px-2'>
{ props.language }
2021-07-05 18:32:33 +00:00
</div>
</div>
</div>
<div
2022-08-06 08:44:27 +00:00
v-show='stars > 0'
class='flex-2 text-xs'
2021-07-05 18:32:33 +00:00
>
2022-08-06 08:44:27 +00:00
<div class='flex flex-row items-center content-center'>
<div class='flex-initial'>
2021-07-05 18:32:33 +00:00
<img
src={image.star}
2022-08-06 08:44:27 +00:00
class='text-white font-bold h-3 w-3 fill-current -inset-y-1'
alt='Stargazers'
2021-07-05 18:32:33 +00:00
/>
</div>
2022-08-06 08:44:27 +00:00
<div class='flex-initial px-2'>
{ props.stars }
2021-07-05 18:32:33 +00:00
</div>
</div>
</div>
</div>
</div>
</div>
);
}
export default Repository;