1+ import * as RadixAvatar from '@radix-ui/react-avatar' ;
12import classNames from 'classnames' ;
2- import type { HTMLAttributes , ElementType } from 'react' ;
3+ import type { HTMLAttributes } from 'react' ;
34import { forwardRef } from 'react' ;
45
56import type { LinkLike } from '#ui/types' ;
@@ -14,12 +15,8 @@ export type AvatarProps = {
1415 size ?: 'small' | 'medium' ;
1516 url ?: string ;
1617 as ?: LinkLike | 'div' ;
17- img ?: ElementType | 'img' ;
1818} ;
1919
20- // @TODO : We temporarily removed the Avatar Radix UI primitive, since it was causing flashing
21- // during initial load and not being able to render nicely when images are already cached.
22- // @see https://github.com/radix-ui/primitives/pull/3008
2320const Avatar = forwardRef <
2421 HTMLSpanElement ,
2522 HTMLAttributes < HTMLSpanElement > & AvatarProps
@@ -33,14 +30,13 @@ const Avatar = forwardRef<
3330 url,
3431 size = 'small' ,
3532 as : Component = 'a' ,
36- img : Image = 'img' ,
3733 ...props
3834 } ,
3935 ref
4036 ) => {
4137 if ( ! url ) Component = 'div' ;
4238 return (
43- < span
39+ < RadixAvatar . Root
4440 { ...props }
4541 ref = { ref }
4642 className = { classNames ( styles . avatar , styles [ size ] , props . className ) }
@@ -50,25 +46,20 @@ const Avatar = forwardRef<
5046 target = { url ? '_blank' : undefined }
5147 className = { styles . wrapper }
5248 >
53- { image && (
54- < Image
55- width = { 40 }
56- height = { 40 }
57- loading = "lazy"
58- decoding = "async"
59- src = { image }
60- alt = { name || nickname }
61- className = { styles . item }
62- />
63- ) }
64-
65- { ! image && (
66- < span className = { classNames ( styles . item , styles [ size ] ) } >
67- { fallback }
68- </ span >
69- ) }
49+ < RadixAvatar . Image
50+ loading = "lazy"
51+ decoding = "async"
52+ src = { image }
53+ alt = { name || nickname }
54+ className = { styles . item }
55+ />
56+ < RadixAvatar . Fallback
57+ className = { classNames ( styles . item , styles [ size ] ) }
58+ >
59+ { fallback }
60+ </ RadixAvatar . Fallback >
7061 </ Component >
71- </ span >
62+ </ RadixAvatar . Root >
7263 ) ;
7364 }
7465) ;
0 commit comments