Skip to content

Commit

Permalink
clients: Better Avatar fallback with initials in case of Gravatar
Browse files Browse the repository at this point in the history
  • Loading branch information
birkjernstrom committed Dec 17, 2024
1 parent 2b54017 commit 4da6d5a
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions clients/packages/polarkit/src/components/ui/atoms/Avatar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ const Avatar = ({
width?: number | undefined
}) => {
const initials = getInitials(name)
const isGravatar = avatar_url && avatar_url.includes("gravatar.com")
// Always add initials below image in case of Gravatar since they return a transparent image if the user does not have a Gravatar account
const showInitials = isGravatar || !avatar_url

return (
<div
Expand All @@ -22,10 +25,11 @@ const Avatar = ({
className,
)}
>
{/* Always add initials below image because Gravatar returns a transparent image if the user does not have a Gravatar account */}
<div className="absolute inset-0 flex items-center justify-center bg-transparent">
<span>{initials}</span>
</div>
{showInitials && (
<div className="absolute inset-0 flex items-center justify-center bg-transparent">
<span>{initials}</span>
</div>
)}
{avatar_url && (
<>
{/* eslint-disable-next-line @next/next/no-img-element */}
Expand Down

0 comments on commit 4da6d5a

Please sign in to comment.