@@ -50,6 +50,8 @@ const avatarStatusVariants = cva(
5050 }
5151)
5252
53+ const AvatarSizeContext = React . createContext < VariantProps < typeof avatarVariants > [ 'size' ] > ( 'md' )
54+
5355type AvatarStatus = 'online' | 'offline' | 'busy' | 'away'
5456
5557interface AvatarProps
@@ -93,22 +95,24 @@ interface AvatarProps
9395 */
9496const Avatar = React . forwardRef < React . ElementRef < typeof AvatarPrimitive . Root > , AvatarProps > (
9597 ( { className, size, status, children, ...props } , ref ) => (
96- < div className = 'relative inline-flex' >
97- < AvatarPrimitive . Root
98- ref = { ref }
99- className = { cn ( avatarVariants ( { size } ) , className ) }
100- { ...props }
101- >
102- { children }
103- </ AvatarPrimitive . Root >
104- { status && (
105- < span
106- data-slot = 'avatar-status'
107- className = { cn ( avatarStatusVariants ( { status, size } ) ) }
108- aria-label = { `Status: ${ status } ` }
109- />
110- ) }
111- </ div >
98+ < AvatarSizeContext . Provider value = { size ?? 'md' } >
99+ < div className = 'relative inline-flex' >
100+ < AvatarPrimitive . Root
101+ ref = { ref }
102+ className = { cn ( avatarVariants ( { size } ) , className ) }
103+ { ...props }
104+ >
105+ { children }
106+ </ AvatarPrimitive . Root >
107+ { status && (
108+ < span
109+ data-slot = 'avatar-status'
110+ className = { cn ( avatarStatusVariants ( { status, size } ) ) }
111+ aria-label = { `Status: ${ status } ` }
112+ />
113+ ) }
114+ </ div >
115+ </ AvatarSizeContext . Provider >
112116 )
113117)
114118Avatar . displayName = 'Avatar'
@@ -133,6 +137,7 @@ AvatarImage.displayName = 'AvatarImage'
133137
134138/**
135139 * Fallback component for Avatar. Displays initials or icon when image is unavailable.
140+ * The xs size uses 8px initials; other sizes retain text-xs.
136141 *
137142 * Carries the package's only hardcoded `font-medium`, and deliberately: one or
138143 * two capitals at `text-xs` on a filled disc are a glyph, not running text, and
@@ -142,16 +147,20 @@ AvatarImage.displayName = 'AvatarImage'
142147const AvatarFallback = React . forwardRef <
143148 React . ElementRef < typeof AvatarPrimitive . Fallback > ,
144149 React . ComponentPropsWithoutRef < typeof AvatarPrimitive . Fallback >
145- > ( ( { className, ...props } , ref ) => (
146- < AvatarPrimitive . Fallback
147- ref = { ref }
148- className = { cn (
149- 'flex h-full w-full items-center justify-center rounded-full border border-[var(--border-1)] bg-[var(--surface-4)] font-medium text-[var(--text-secondary)] text-xs' ,
150- className
151- ) }
152- { ...props }
153- />
154- ) )
150+ > ( ( { className, ...props } , ref ) => {
151+ const size = React . useContext ( AvatarSizeContext )
152+ return (
153+ < AvatarPrimitive . Fallback
154+ ref = { ref }
155+ className = { cn (
156+ 'flex h-full w-full items-center justify-center rounded-full border border-[var(--border-1)] bg-[var(--surface-4)] font-medium text-[var(--text-secondary)] text-xs' ,
157+ size === 'xs' && 'text-[8px]' ,
158+ className
159+ ) }
160+ { ...props }
161+ />
162+ )
163+ } )
155164AvatarFallback . displayName = 'AvatarFallback'
156165
157166export { Avatar , AvatarImage , AvatarFallback , avatarVariants , avatarStatusVariants }
0 commit comments