import clsx from "clsx";
import { Avatar as AvatarPrimative } from "radix-ui";
import * as React from "react";
import * as styles from "./styles.module.css";
interface User {
profile_image_url?: { src?: string } | string;
given_name?: string;
family_name?: string;
}
function imgSrc(image?: string | { src?: string }) {
if (!image) return null;
if (typeof image === "string") {
return image;
}
return image?.src ?? null;
}
export function Avatar({
user,
className,
size = "md",
variant = "subtle",
...props
}: {
user: User;
className?: string;
size: "2xs" | "xs" | "sm" | "md" | "lg" | "xl" | "2xl" | "full";
variant?: "solid" | "subtle" | "outline";
}) {
const initials = React.useMemo(() => {
if (!user?.given_name && !user?.family_name) return "";
if (user?.given_name && user?.family_name) {
return `${user.given_name[0]}${user.family_name[0]}`;
} else if (user?.given_name) {
return user.given_name[0] ?? "";
}
return user?.family_name?.[0] ?? "";
}, [user?.given_name, user?.family_name]);
const img = imgSrc(user?.profile_image_url);
return (
{img ? (
) : null}
{initials || }
);
}
function UserIcon() {
return (
);
}