1- import * as RadixAvatar from '@radix-ui/react-avatar' ;
21import classNames from 'classnames' ;
3- import type { ComponentPropsWithoutRef , ElementRef } from 'react ' ;
4- import { forwardRef } from 'react' ;
2+ import Image from 'next/image ' ;
3+ import type { FC , HTMLAttributes } from 'react' ;
54
65import Link from '@/components/Link' ;
76
@@ -16,38 +15,47 @@ export type AvatarProps = {
1615 url ?: string ;
1716} ;
1817
19- const Avatar = forwardRef <
20- ElementRef < typeof RadixAvatar . Root > ,
21- ComponentPropsWithoutRef < typeof RadixAvatar . Root > & AvatarProps
22- > ( ( { image, nickname, name, fallback, url, size = 'small' , ...props } , ref ) => {
18+ const Avatar : FC < HTMLAttributes < HTMLSpanElement > & AvatarProps > = ( {
19+ image,
20+ nickname,
21+ name,
22+ fallback,
23+ url,
24+ size = 'small' ,
25+ ...props
26+ } ) => {
2327 const Wrapper = url ? Link : 'div' ;
2428
2529 return (
26- < RadixAvatar . Root
30+ < span
2731 { ...props }
2832 className = { classNames ( styles . avatar , styles [ size ] , props . className ) }
29- ref = { ref }
3033 >
3134 < Wrapper
3235 href = { url || undefined }
3336 target = { url ? '_blank' : undefined }
3437 className = { styles . wrapper }
3538 >
36- < RadixAvatar . Image
37- loading = "lazy"
38- src = { image }
39- alt = { name || nickname }
40- className = { styles . item }
41- />
42- < RadixAvatar . Fallback
43- delayMs = { 500 }
44- className = { classNames ( styles . item , styles [ size ] ) }
45- >
46- { fallback }
47- </ RadixAvatar . Fallback >
39+ { image && (
40+ < Image
41+ width = { 40 }
42+ height = { 40 }
43+ loading = "lazy"
44+ decoding = "async"
45+ src = { image }
46+ alt = { name || nickname }
47+ className = { styles . item }
48+ />
49+ ) }
50+
51+ { ! image && (
52+ < span className = { classNames ( styles . item , styles [ size ] ) } >
53+ { fallback }
54+ </ span >
55+ ) }
4856 </ Wrapper >
49- </ RadixAvatar . Root >
57+ </ span >
5058 ) ;
51- } ) ;
59+ } ;
5260
5361export default Avatar ;
0 commit comments