Skip to content

Commit

Permalink
Created reusable component for contributors Avatar (ohcnetwork#521)
Browse files Browse the repository at this point in the history
  • Loading branch information
BarryByte authored Oct 20, 2024
1 parent c4092d6 commit 25a9a7c
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 17 deletions.
42 changes: 29 additions & 13 deletions components/contributors/ContributorImage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,36 +3,52 @@ import Image from "next/image";
interface ContributorImageProps {
contributorGithub: string;
rank: number | null;
height: number;
width: number;
size: "small" | "medium" | "large";
className?: string;
}

const sizes = {
small: { height: 30, width: 30 },
medium: { height: 50, width: 50 },
large: { height: 100, width: 100 },
};

const ContributorImage = ({
contributorGithub,
rank,
height,
width,
size,
className = "",
}: ContributorImageProps) => {
function contributorRankClasses(rank: number | null): string {
const { height, width } = sizes[size];
function topContributorClasses(rank: number | null): string {
if (!rank || rank > 3) {
return "text-purple-500";
return "border-4 border-purple-500";
}
const rankColor = ["text-yellow-600", "text-stone-600", "text-amber-700"][
rank - 1
const rankColors = [
"text-yellow-600 border-yellow-500 bg-yellow-100",
"text-stone-600 border-gray-500 bg-gray-200",
"text-amber-700 border-amber-700 bg-amber-100",
];
return `${rankColor} animate-circular-shadow`;
return `border-4 ${rankColors[rank - 1]} animate-circular-shadow`;
}

return (
<div
className={`dark:border-1 shrink-0 rounded-full border-2 border-current ${contributorRankClasses(rank)}`}
className={`relative inline-block shrink-0 overflow-hidden rounded-full ${topContributorClasses(
rank,
)} ${className}`}
style={{ width: `${width}px`, height: `${height}px` }}
>
<Image
className="rounded-full"
src={`https://avatars.githubusercontent.com/${contributorGithub}`}
alt={contributorGithub}
height={height}
alt={`Contributor ${contributorGithub}`}
width={width}
height={height}
className="rounded-full object-cover"
/>
{rank && rank <= 3 && (
<div className="absolute inset-0 rounded-full bg-black opacity-10"></div>
)}
</div>
);
};
Expand Down
3 changes: 1 addition & 2 deletions components/contributors/InfoCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,7 @@ export default async function InfoCard({
<ContributorImage
contributorGithub={contributor.github}
rank={rank}
height={112}
width={112}
size="large"
/>
</Link>
</div>
Expand Down
3 changes: 1 addition & 2 deletions components/contributors/LeaderboardCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,7 @@ export default function LeaderboardCard({
<ContributorImage
contributorGithub={contributor.user.social.github}
rank={position + 1}
height={56}
width={56}
size="large"
/>
<div className="ml-4 mr-4 basis-3/5 text-wrap pr-10">
<div className="w-[180px] truncate font-bold text-green-500">
Expand Down

0 comments on commit 25a9a7c

Please sign in to comment.