11import { clsx } from 'clsx'
22import React from 'react'
3- import Box from '../Box'
43import type { SxProp } from '../sx'
54import type { ResponsiveValue } from '../hooks/useResponsiveValue'
65import { isResponsiveValue } from '../hooks/useResponsiveValue'
76import { defaultSxProp } from '../utils/defaultSxProp'
7+ import { BoxWithFallback } from '../internal/components/BoxWithFallback'
88import classes from './Avatar.module.css'
99
1010export const DEFAULT_AVATAR_SIZE = 20
@@ -24,7 +24,7 @@ export type AvatarProps = {
2424 React . ComponentPropsWithoutRef < 'img' >
2525
2626const 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 } ,
2828 ref ,
2929) {
3030 const isResponsive = isResponsiveValue ( size )
@@ -38,27 +38,9 @@ const Avatar = React.forwardRef<HTMLImageElement, AvatarProps>(function Avatar(
3838 cssSizeVars [ '--avatarSize-regular' ] = `${ size } px`
3939 }
4040
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-
6041 return (
61- < img
42+ < BoxWithFallback
43+ as = "img"
6244 data-component = "Avatar"
6345 className = { clsx ( className , classes . Avatar ) }
6446 ref = { ref }
@@ -67,7 +49,15 @@ const Avatar = React.forwardRef<HTMLImageElement, AvatarProps>(function Avatar(
6749 data-square = { square ? '' : undefined }
6850 width = { isResponsive ? undefined : size }
6951 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 }
7161 { ...rest }
7262 />
7363 )
0 commit comments