11import * as AvatarBase from "@radix-ui/react-avatar" ;
2- import { ReactNode , useMemo } from "react" ;
2+ import { useMemo } from "react" ;
33import { tv , VariantProps } from "tailwind-variants" ;
44
55const avatar = tv ( {
66 slots : {
7- root : "relative inline-flex aspect-square" ,
7+ root : "relative inline-flex aspect-square overflow-hidden " ,
88 image : "h-full w-full object-cover" ,
9- fallback : [
10- "flex h-full w-full text-center items-center justify-center bg-brand-500 text-sm font-medium uppercase" ,
11- "text-accent-50 dark:bg-brand-400" ,
12- ] ,
9+ fallback :
10+ "flex h-full w-full text-center items-center justify-center bg-primary text-primary-foreground text-sm font-medium uppercase" ,
1311 } ,
1412 variants : {
1513 size : {
@@ -36,18 +34,15 @@ const avatar = tv({
3634 } ,
3735 rounded : {
3836 full : {
39- image : "rounded-full" ,
40- fallback : "rounded-full" ,
37+ root : "rounded-full" ,
4138 } ,
4239 sm : {
43- image : "rounded-lg" ,
44- fallback : "rounded-lg" ,
40+ root : "rounded-lg" ,
4541 } ,
4642 } ,
4743 border : {
4844 wide : {
49- image : "border-4 border-light-100 dark:border-dark-900" ,
50- fallback : "border-4 border-light-100 dark:border-dark-900" ,
45+ root : "border-4 border-background" ,
5146 } ,
5247 } ,
5348 } ,
@@ -61,14 +56,12 @@ export type AvatarProps = {
6156 src ?: string | null ;
6257 fallback ?: string ;
6358 alt ?: string ;
64- asImage ?: ReactNode ;
6559 className ?: string ;
6660} & VariantProps < typeof avatar > ;
6761
6862export function Avatar ( {
6963 size,
7064 fallback,
71- asImage,
7265 src,
7366 alt,
7467 border,
@@ -89,22 +82,17 @@ export function Avatar({
8982 return (
9083 < AvatarBase . Root
9184 { ...props }
85+ key = { src }
9286 className = { styles . root ( { className : props . className } ) }
9387 >
9488 { src != null && (
9589 < AvatarBase . Image
9690 alt = { fallback ?? alt ?? "avatar" }
9791 src = { src }
9892 className = { styles . image ( ) }
99- asChild = { asImage != null }
100- >
101- { asImage }
102- </ AvatarBase . Image >
93+ />
10394 ) }
104- < AvatarBase . Fallback
105- className = { styles . fallback ( ) }
106- delayMs = { src != null ? 200 : 0 }
107- >
95+ < AvatarBase . Fallback className = { styles . fallback ( ) } delayMs = { 0 } >
10896 < p > { fallbackText } </ p >
10997 </ AvatarBase . Fallback >
11098 </ AvatarBase . Root >
0 commit comments