import React, { useState, useEffect } from 'react'; import classnames from 'classnames'; import { AvatarBase, AvatarBaseProps } from '../avatar-base'; import { Display, AlignItems, JustifyContent, TextColor, BorderColor, BackgroundColor, } from '../../../helpers/constants/design-system'; import type { PolymorphicRef } from '../box'; import type { AvatarTokenComponent } from './avatar-token.types'; import { AvatarTokenProps, AvatarTokenSize } from './avatar-token.types'; export const AvatarToken: AvatarTokenComponent = React.forwardRef( ( { size = AvatarTokenSize.Md, name, src, showHalo, color = TextColor.textDefault, backgroundColor = BackgroundColor.backgroundAlternative, borderColor = BorderColor.transparent, className = '', ...props }: AvatarTokenProps, ref: PolymorphicRef, ) => { const [showFallback, setShowFallback] = useState(false); useEffect(() => { setShowFallback(!src); }, [src]); const handleOnError = () => { setShowFallback(true); }; const fallbackString = name?.[0] ?? '?'; return ( ), }} > {showFallback ? ( fallbackString ) : ( <> {showHalo && ( )} {`${name} )} ); }, );