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