1
1
import { clsx } from 'clsx'
2
2
import React from 'react'
3
- import Box from '../Box'
4
3
import type { SxProp } from '../sx'
5
4
import type { ResponsiveValue } from '../hooks/useResponsiveValue'
6
5
import { isResponsiveValue } from '../hooks/useResponsiveValue'
7
6
import { defaultSxProp } from '../utils/defaultSxProp'
7
+ import { BoxWithFallback } from '../internal/components/BoxWithFallback'
8
8
import classes from './Avatar.module.css'
9
9
10
10
export const DEFAULT_AVATAR_SIZE = 20
@@ -24,7 +24,7 @@ export type AvatarProps = {
24
24
React . ComponentPropsWithoutRef < 'img' >
25
25
26
26
const Avatar = React . forwardRef < HTMLImageElement , AvatarProps > ( function Avatar (
27
- { alt = '' , size = DEFAULT_AVATAR_SIZE , square = false , sx : sxProp = defaultSxProp , className, ...rest } ,
27
+ { alt = '' , size = DEFAULT_AVATAR_SIZE , square = false , sx : sxProp = defaultSxProp , className, style , ...rest } ,
28
28
ref ,
29
29
) {
30
30
const isResponsive = isResponsiveValue ( size )
@@ -38,27 +38,9 @@ const Avatar = React.forwardRef<HTMLImageElement, AvatarProps>(function Avatar(
38
38
cssSizeVars [ '--avatarSize-regular' ] = `${ size } px`
39
39
}
40
40
41
- if ( sxProp !== defaultSxProp ) {
42
- return (
43
- < Box
44
- as = { 'img' }
45
- data-component = "Avatar"
46
- className = { clsx ( className , classes . Avatar ) }
47
- ref = { ref }
48
- alt = { alt }
49
- data-responsive = { isResponsive ? '' : undefined }
50
- data-square = { square ? '' : undefined }
51
- width = { isResponsive ? undefined : size }
52
- height = { isResponsive ? undefined : size }
53
- style = { cssSizeVars as React . CSSProperties }
54
- sx = { sxProp }
55
- { ...rest }
56
- />
57
- )
58
- }
59
-
60
41
return (
61
- < img
42
+ < BoxWithFallback
43
+ as = "img"
62
44
data-component = "Avatar"
63
45
className = { clsx ( className , classes . Avatar ) }
64
46
ref = { ref }
@@ -67,7 +49,15 @@ const Avatar = React.forwardRef<HTMLImageElement, AvatarProps>(function Avatar(
67
49
data-square = { square ? '' : undefined }
68
50
width = { isResponsive ? undefined : size }
69
51
height = { isResponsive ? undefined : size }
70
- style = { cssSizeVars as React . CSSProperties }
52
+ style = {
53
+ style
54
+ ? {
55
+ ...cssSizeVars ,
56
+ ...style ,
57
+ }
58
+ : ( cssSizeVars as React . CSSProperties )
59
+ }
60
+ sx = { sxProp }
71
61
{ ...rest }
72
62
/>
73
63
)
0 commit comments