RocketChat/Rocket.Chat

View on GitHub
packages/ui-avatar/src/components/UserAvatar.tsx

Summary

Maintainability
A
0 mins
Test Coverage
import { useUserAvatarPath } from '@rocket.chat/ui-contexts';
import type { FC } from 'react';
import { memo } from 'react';

import type { BaseAvatarProps } from './BaseAvatar';
import BaseAvatar from './BaseAvatar';

type UserAvatarProps = Omit<BaseAvatarProps, 'url' | 'title'> & {
    username: string;
    etag?: string;
    url?: string;
    title?: string;
};

const UserAvatar: FC<UserAvatarProps> = ({ username, etag, ...rest }) => {
    const getUserAvatarPath = useUserAvatarPath();
    const { url = getUserAvatarPath(username, etag), ...props } = rest;

    return <BaseAvatar url={url} data-username={username} title={username} {...props} />;
};

export default memo(UserAvatar);