import { useState } from "react"; import { faUser } from "@fortawesome/pro-duotone-svg-icons"; import { FontAwesomeIcon } from "@fortawesome/react-fontawesome"; import { cx } from "@/utils/cx"; import { type AvatarProps } from "./avatar"; import { AvatarOnlineIndicator, VerifiedTick } from "./base-components"; const styles = { sm: { root: "size-18 p-0.75", rootWithPlaceholder: "p-1", content: "", icon: "size-9", initials: "text-display-sm font-semibold", badge: "bottom-0.5 right-0.5", }, md: { root: "size-24 p-1", rootWithPlaceholder: "p-1.25", content: "shadow-xl", icon: "size-12", initials: "text-display-md font-semibold", badge: "bottom-1 right-1", }, lg: { root: "size-40 p-1.5", rootWithPlaceholder: "p-1.75", content: "shadow-2xl", icon: "size-20", initials: "text-display-xl font-semibold", badge: "bottom-2 right-2", }, }; const tickSizeMap = { sm: "2xl", md: "3xl", lg: "4xl", } as const; interface AvatarProfilePhotoProps extends AvatarProps { size: "sm" | "md" | "lg"; } export const AvatarProfilePhoto = ({ contrastBorder = true, size = "md", src, alt, initials, placeholder, placeholderIcon: PlaceholderIcon, verified, badge, status, className, }: AvatarProfilePhotoProps) => { const [isFailed, setIsFailed] = useState(false); const renderMainContent = () => { if (src && !isFailed) { return ( {alt} setIsFailed(true)} className={cx( "size-full rounded-full object-cover", contrastBorder && "outline-1 -outline-offset-1 outline-avatar-contrast-border", styles[size].content, )} /> ); } if (initials) { return (
{initials}
); } if (PlaceholderIcon) { return (
); } return (
{placeholder || }
); }; const renderBadgeContent = () => { if (status) { return ; } if (verified) { return ; } return badge; }; return (
{renderMainContent()} {renderBadgeContent()}
); };