import styles from './Avatar.styles'; import { AvatarProps } from './types'; import React from 'react'; import renderAvatarSVG from './images/guy'; import color from '../../styles/colors'; const { DivStyled, H4Styled } = styles; const avatarColors = ['#FEB7B7', '#E1B5F6', '#A7D6F9', '#AADCD6', '#F0DC7D']; const Avatar: React.FC = ({ avatarBackground, borderRadius, fontSize = 15, image, isRounded = false, size = 40, text, textColor = color.white, theme, avatarKey = 1, ...props }: AvatarProps) => { const getRandomColor = (): string => { if (avatarBackground) { return avatarBackground; } if (theme == 'image' || image) { return 'transparent'; } const pos = avatarKey < avatarColors.length ? avatarKey % avatarColors.length : avatarColors.length % avatarKey; return avatarColors[pos - 1]; }; return ( {theme === 'image' ? ( !image && renderAvatarSVG() ) : ( {text && text.length > 1 ? `${text[0]}${text[1]}` : text} )} ); }; export default Avatar;