import React, { FunctionComponent, ImgHTMLAttributes } from 'react'; import getClassName from '../../helpers/getClassName'; import classNames from '../../lib/classNames'; import usePlatform from '../../hooks/usePlatform'; import { HasRootRef } from '../../types'; export interface AvatarProps extends ImgHTMLAttributes, HasRootRef { size?: 80 | 72 | 64 | 56 | 48 | 44 | 40 | 36 | 32 | 28 | 24; src?: string; mode?: 'default' | 'image' | 'app'; } const Avatar: FunctionComponent = ({ src, size, mode, style, className, children, getRootRef, ...restProps }: AvatarProps) => { const Component = src ? 'img' : 'div'; const platform = usePlatform(); let borderRadius; switch (mode) { case 'default': borderRadius = '50%'; break; case 'image': borderRadius = 4; break; case 'app': borderRadius = Math.floor(size * 10 / 48); break; } return (
{children &&
{children}
}
); }; Avatar.defaultProps = { size: 48, mode: 'default', }; export default Avatar;