2023-12-17 15:33:54 +08:00
|
|
|
import React from 'react';
|
2023-12-26 12:08:50 +08:00
|
|
|
import type { AvatarListItem } from '@qixian.cs/github-contributors-list';
|
2023-12-17 15:33:54 +08:00
|
|
|
import { Avatar, Skeleton, Tooltip } from 'antd';
|
|
|
|
|
|
|
|
const AvatarPlaceholder: React.FC<{ num?: number }> = ({ num = 3 }) => (
|
|
|
|
<li>
|
2023-12-26 12:08:50 +08:00
|
|
|
{Array.from({ length: num }).map<React.ReactNode>((_, i) => (
|
|
|
|
<Skeleton.Avatar
|
|
|
|
size="small"
|
|
|
|
active
|
|
|
|
key={i}
|
|
|
|
style={{ marginInlineStart: i === 0 ? 0 : -8 }}
|
|
|
|
/>
|
2023-12-17 15:33:54 +08:00
|
|
|
))}
|
|
|
|
</li>
|
|
|
|
);
|
|
|
|
|
|
|
|
interface ContributorAvatarProps {
|
|
|
|
loading?: boolean;
|
2023-12-26 12:08:50 +08:00
|
|
|
item?: AvatarListItem;
|
2023-12-17 15:33:54 +08:00
|
|
|
}
|
|
|
|
|
2023-12-26 12:08:50 +08:00
|
|
|
const ContributorAvatar: React.FC<ContributorAvatarProps> = (props) => {
|
|
|
|
const {
|
|
|
|
item: { username, url } = {},
|
|
|
|
loading,
|
|
|
|
} = props;
|
2023-12-17 15:33:54 +08:00
|
|
|
if (loading) {
|
|
|
|
return <AvatarPlaceholder />;
|
|
|
|
}
|
|
|
|
if (username?.includes('github-actions')) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
return (
|
|
|
|
<Tooltip title={username}>
|
|
|
|
<li>
|
|
|
|
<a href={`https://github.com/${username}`} target="_blank" rel="noopener noreferrer">
|
|
|
|
<Avatar size="small" src={url} alt={username}>
|
|
|
|
{username}
|
|
|
|
</Avatar>
|
|
|
|
</a>
|
|
|
|
</li>
|
|
|
|
</Tooltip>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
export default ContributorAvatar;
|