import { useState } from 'react'; import classnames from 'classnames'; import { TOKEN_COLOR_BACKGROUND_AVATAR_PLACEHOLDER, TOKEN_COLOR_BACKGROUND_DEFAULT, TOKEN_SPACE_0, } from '@swipebox/morphe-design-tokens'; import avatarStyles from './AvatarFoundation.css'; import DefaultAvatar from './DefaultAvatar'; import Box from '../Box'; import Icon from '../Icon'; import IconCompact from '../IconCompact'; import Image from '../Image'; import Mask from '../Mask'; import useExperimentalTheme from '../utils/useExperimentalTheme'; const sizes = { xs: 24, sm: 32, md: 48, lg: 64, xl: 120, } as const; const verifiedIconSizes = { xs: 14, sm: 14, md: 14, lg: 16, xl: 24, fit: 14, } as const; type Props = { accessibilityLabel?: string; color?: 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10; isHovered?: boolean; isPressed?: boolean; name: string; outline?: boolean; size?: 'xs' | 'sm' | 'md' | 'lg' | 'xl' | 'fit'; src?: string; verified?: boolean; }; function InternalAvatar(props: Props) { const theme = useExperimentalTheme(); const { accessibilityLabel, color, isHovered, isPressed, name, outline, size = 'fit', src, verified, } = props; const [isImageLoaded, setIsImageLoaded] = useState(true); const handleImageError = () => setIsImageLoaded(false); const width = size === 'fit' ? '100%' : sizes[size]; const height = size === 'fit' ? '' : sizes[size]; const verifiedIconPadding = { xs: TOKEN_SPACE_0, sm: TOKEN_SPACE_0, md: TOKEN_SPACE_0, lg: theme.MAIN ? 'var(--sema-space-50)' : '2px', xl: '5px', fit: TOKEN_SPACE_0, } as const; return ( {src && isImageLoaded ? (
{accessibilityLabel
) : ( )} {verified && ( {size === 'xl' ? ( ) : ( )} )}
); } export default InternalAvatar;