Skip to content

Commit 4cc4f24

Browse files
committed
perf: use next image for avatars
1 parent ebc74b8 commit 4cc4f24

File tree

1 file changed

+26
-2
lines changed

1 file changed

+26
-2
lines changed

src/components/ui/avatar.tsx

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ import * as AvatarPrimitive from "@radix-ui/react-avatar"
66

77
import { cn } from "@/lib/utils/cn"
88

9+
import { Image } from "../Image"
10+
911
import { Center } from "./flex"
1012
import { BaseLink, type LinkProps } from "./Link"
1113
import { LinkBox, LinkOverlay } from "./link-box"
@@ -162,7 +164,18 @@ const Avatar = React.forwardRef<
162164
<BaseLink {...commonLinkProps}>{label}</BaseLink>
163165
</LinkOverlay>
164166
<AvatarBase size={size}>
165-
<AvatarImage src={src} />
167+
{src ? (
168+
<Image
169+
className="object-fill"
170+
width={64}
171+
height={64}
172+
sizes="4rem"
173+
src={src}
174+
alt={name}
175+
/>
176+
) : (
177+
<AvatarImage />
178+
)}
166179
<AvatarFallback>{fallbackInitials}</AvatarFallback>
167180
</AvatarBase>
168181
</Center>
@@ -173,7 +186,18 @@ const Avatar = React.forwardRef<
173186
return (
174187
<AvatarBase ref={ref} size={size} className={className} asChild>
175188
<BaseLink title={dataTest} {...commonLinkProps}>
176-
<AvatarImage src={src} />
189+
{src ? (
190+
<Image
191+
className="object-fill"
192+
width={64}
193+
height={64}
194+
sizes="4rem"
195+
src={src}
196+
alt={name}
197+
/>
198+
) : (
199+
<AvatarImage />
200+
)}
177201
<AvatarFallback>{fallbackInitials}</AvatarFallback>
178202
</BaseLink>
179203
</AvatarBase>

0 commit comments

Comments
 (0)