2021-09-14 08:45:28 +00:00
|
|
|
import * as AvatarPrimitive from "@radix-ui/react-avatar";
|
|
|
|
import * as Tooltip from "@radix-ui/react-tooltip";
|
2021-09-22 19:52:38 +00:00
|
|
|
|
2022-07-22 17:27:06 +00:00
|
|
|
import { Maybe } from "@calcom/trpc/server";
|
|
|
|
|
2021-09-14 08:45:28 +00:00
|
|
|
import classNames from "@lib/classNames";
|
2021-09-22 19:52:38 +00:00
|
|
|
import { defaultAvatarSrc } from "@lib/profile";
|
2021-09-14 08:45:28 +00:00
|
|
|
|
|
|
|
export type AvatarProps = {
|
|
|
|
className?: string;
|
2021-09-27 14:47:55 +00:00
|
|
|
size?: number;
|
|
|
|
imageSrc?: Maybe<string>;
|
2021-09-14 08:45:28 +00:00
|
|
|
title?: string;
|
|
|
|
alt: string;
|
|
|
|
gravatarFallbackMd5?: string;
|
|
|
|
};
|
|
|
|
|
2022-07-14 10:28:46 +00:00
|
|
|
/**
|
|
|
|
* @deprecated Use AvatarSSR instead. Once, there is no usage of Avatar, AvatarSSR can be renamed.
|
|
|
|
*/
|
2021-09-27 14:47:55 +00:00
|
|
|
export default function Avatar(props: AvatarProps) {
|
|
|
|
const { imageSrc, gravatarFallbackMd5, size, alt, title } = props;
|
|
|
|
const className = classNames("rounded-full", props.className, size && `h-${size} w-${size}`);
|
2021-09-14 08:45:28 +00:00
|
|
|
const avatar = (
|
|
|
|
<AvatarPrimitive.Root>
|
|
|
|
<AvatarPrimitive.Image
|
2021-09-27 14:47:55 +00:00
|
|
|
src={imageSrc ?? undefined}
|
2021-09-14 08:45:28 +00:00
|
|
|
alt={alt}
|
2021-09-14 13:27:41 +00:00
|
|
|
className={classNames("rounded-full", `h-auto w-${size}`, props.className)}
|
2021-09-14 08:45:28 +00:00
|
|
|
/>
|
|
|
|
<AvatarPrimitive.Fallback delayMs={600}>
|
|
|
|
{gravatarFallbackMd5 && (
|
2022-05-14 13:49:39 +00:00
|
|
|
// eslint-disable-next-line @next/next/no-img-element
|
2021-09-14 08:45:28 +00:00
|
|
|
<img src={defaultAvatarSrc({ md5: gravatarFallbackMd5 })} alt={alt} className={className} />
|
|
|
|
)}
|
|
|
|
</AvatarPrimitive.Fallback>
|
|
|
|
</AvatarPrimitive.Root>
|
|
|
|
);
|
|
|
|
|
|
|
|
return title ? (
|
2021-09-14 13:27:41 +00:00
|
|
|
<Tooltip.Tooltip delayDuration={300}>
|
2021-09-14 08:45:28 +00:00
|
|
|
<Tooltip.TooltipTrigger className="cursor-default">{avatar}</Tooltip.TooltipTrigger>
|
2022-07-15 16:39:11 +00:00
|
|
|
<Tooltip.Content className="rounded-sm bg-black p-2 text-sm text-white">
|
2021-09-14 08:45:28 +00:00
|
|
|
<Tooltip.Arrow />
|
|
|
|
{title}
|
|
|
|
</Tooltip.Content>
|
|
|
|
</Tooltip.Tooltip>
|
|
|
|
) : (
|
|
|
|
<>{avatar}</>
|
|
|
|
);
|
|
|
|
}
|