Skip to content

Local UI to run and train LLMs and diffusion models. Supports GGUF, MLX, Qwen3.8, DeepSeek-V4.1, MiniMax-H3, Gemma 4, FLUX and more.

1.6 KB
Raw Blame
// SPDX-License-Identifier: AGPL-3.0-only
// Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0

import { cn } from "@/lib/utils";
import { avatarBgStyle, initialsFromName } from "../utils/avatar-initials";
import {
  useUserProfileStore,
  type AvatarShape,
} from "../stores/user-profile-store";

type UserAvatarProps = {
  name: string;
  imageUrl: string | null;
  size: "sm" | "md" | "lg";
  className?: string;
  shape?: AvatarShape;
};

const SIZE: Record<"sm" | "md" | "lg", string> = {
  sm: "size-9 text-xs",
  md: "size-11 text-sm",
  lg: "size-[calc(106px*var(--ui-space-scale,1))] text-[calc(1.65rem*var(--ui-font-scale,1))]",
};

const SHAPE: Record<AvatarShape, string> = {
  circle: "rounded-full",
  rounded: "rounded-[22%]",
};

export function UserAvatar({
  name,
  imageUrl,
  size,
  className,
  shape,
}: UserAvatarProps) {
  const label = initialsFromName(name);
  const storedShape = useUserProfileStore((s) => s.avatarShape);
  const shapeClass = SHAPE[shape ?? storedShape];

  if (imageUrl) {
    return (
      <span
        className={cn(
          "relative inline-flex shrink-0 overflow-hidden bg-transparent",
          shapeClass,
          SIZE[size],
          className,
        )}
      >
        <img src={imageUrl} alt="" className="size-full object-cover" />
      </span>
    );
  }

  return (
    <span
      style={avatarBgStyle()}
      className={cn(
        "inline-flex shrink-0 items-center justify-center font-semibold",
        shapeClass,
        SIZE[size],
        className,
      )}
      aria-hidden
    >
      {label}
    </span>
  );
}