1
1
import * as AvatarBase from "@radix-ui/react-avatar" ;
2
- import { ReactNode , useMemo } from "react" ;
2
+ import { useMemo } from "react" ;
3
3
import { tv , VariantProps } from "tailwind-variants" ;
4
4
5
5
const avatar = tv ( {
6
6
slots : {
7
- root : "relative inline-flex aspect-square" ,
7
+ root : "relative inline-flex aspect-square overflow-hidden " ,
8
8
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" ,
13
11
} ,
14
12
variants : {
15
13
size : {
@@ -36,18 +34,15 @@ const avatar = tv({
36
34
} ,
37
35
rounded : {
38
36
full : {
39
- image : "rounded-full" ,
40
- fallback : "rounded-full" ,
37
+ root : "rounded-full" ,
41
38
} ,
42
39
sm : {
43
- image : "rounded-lg" ,
44
- fallback : "rounded-lg" ,
40
+ root : "rounded-lg" ,
45
41
} ,
46
42
} ,
47
43
border : {
48
44
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" ,
51
46
} ,
52
47
} ,
53
48
} ,
@@ -61,14 +56,12 @@ export type AvatarProps = {
61
56
src ?: string | null ;
62
57
fallback ?: string ;
63
58
alt ?: string ;
64
- asImage ?: ReactNode ;
65
59
className ?: string ;
66
60
} & VariantProps < typeof avatar > ;
67
61
68
62
export function Avatar ( {
69
63
size,
70
64
fallback,
71
- asImage,
72
65
src,
73
66
alt,
74
67
border,
@@ -89,22 +82,17 @@ export function Avatar({
89
82
return (
90
83
< AvatarBase . Root
91
84
{ ...props }
85
+ key = { src }
92
86
className = { styles . root ( { className : props . className } ) }
93
87
>
94
88
{ src != null && (
95
89
< AvatarBase . Image
96
90
alt = { fallback ?? alt ?? "avatar" }
97
91
src = { src }
98
92
className = { styles . image ( ) }
99
- asChild = { asImage != null }
100
- >
101
- { asImage }
102
- </ AvatarBase . Image >
93
+ />
103
94
) }
104
- < AvatarBase . Fallback
105
- className = { styles . fallback ( ) }
106
- delayMs = { src != null ? 200 : 0 }
107
- >
95
+ < AvatarBase . Fallback className = { styles . fallback ( ) } delayMs = { 0 } >
108
96
< p > { fallbackText } </ p >
109
97
</ AvatarBase . Fallback >
110
98
</ AvatarBase . Root >
0 commit comments