avatar.tsx 771 B

123456789101112131415161718192021222324252627282930
  1. "use client";
  2. import type { ComponentRenderProps } from "./types";
  3. import { baseClass, getCustomClass } from "./utils";
  4. export function Avatar({ element }: ComponentRenderProps) {
  5. const { props } = element;
  6. const customClass = getCustomClass(props);
  7. const name = (props.name as string) || "?";
  8. const initials = name
  9. .split(" ")
  10. .map((n) => n[0])
  11. .join("")
  12. .slice(0, 2)
  13. .toUpperCase();
  14. const avatarSize =
  15. props.size === "lg"
  16. ? "w-10 h-10 text-sm"
  17. : props.size === "sm"
  18. ? "w-6 h-6 text-[8px]"
  19. : "w-8 h-8 text-[10px]";
  20. return (
  21. <div
  22. className={`${avatarSize} rounded-full bg-muted flex items-center justify-center font-medium ${baseClass} ${customClass}`}
  23. >
  24. {initials}
  25. </div>
  26. );
  27. }