import styles from '@patternfly/react-styles/css/components/Avatar/avatar'; import { css } from '@patternfly/react-styles'; export interface AvatarProps extends React.DetailedHTMLProps< React.ImgHTMLAttributes, HTMLImageElement > { /** Content rendered inside the avatar, such as custom svgs or icons. */ children?: React.ReactNode; /** Additional classes added to the avatar. */ className?: string; /** Specifies the URL of the image for the avatar. */ src?: string; /** Specifies the alternate text of the image for the avatar. Will instead set the aria-label when using children or initials; to hide the avatar * from assistive technologies when passing children or initials, pass an empty string to the alt prop. */ alt: string; /** Flag to indicate the avatar should have a border. */ isBordered?: boolean; /** Size variant of avatar. */ size?: 'sm' | 'md' | 'lg' | 'xl'; /** Color of the avatar. */ color?: 'red' | 'orangered' | 'orange' | 'yellow' | 'green' | 'teal' | 'blue' | 'purple' | 'gray'; /** Initials of the avatar. */ initials?: string; } export const Avatar: React.FunctionComponent = ({ children, className, src = '', alt, isBordered, size, color, initials, ...props }: AvatarProps) => { const avatarClasses = css(styles.avatar, styles.modifiers[size], isBordered && styles.modifiers.bordered, className); const isAltEmptyString = alt === ''; if (initials || children) { return (
{initials && ( )} {children && children}
); } return {alt}; }; Avatar.displayName = 'Avatar';