{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "avatar",
  "title": "Avatar",
  "description": "A user avatar with image, initials or icon fallback, 5 sizes, circle, rounded and square shapes, a presence status dot with pulse, an accent ring and an optional click state.",
  "dependencies": [
    "motion",
    "clsx",
    "tailwind-merge"
  ],
  "files": [
    {
      "path": "registry/new-york/avatar/avatar.tsx",
      "content": "\"use client\";\n\nimport * as React from \"react\";\nimport { motion } from \"motion/react\";\nimport { clsx, type ClassValue } from \"clsx\";\nimport { twMerge } from \"tailwind-merge\";\n\nfunction cn(...inputs: ClassValue[]) {\n  return twMerge(clsx(inputs));\n}\n\nexport type AvatarSize = \"xs\" | \"sm\" | \"md\" | \"lg\" | \"xl\";\nexport type AvatarShape = \"circle\" | \"rounded\" | \"square\";\nexport type AvatarStatus = \"online\" | \"offline\" | \"busy\" | \"away\";\n\nexport interface AvatarProps {\n  src?: string;\n  alt?: string;\n  name?: string;\n  size?: AvatarSize | number;\n  shape?: AvatarShape;\n  status?: AvatarStatus;\n  pulse?: boolean;\n  ring?: boolean;\n  ringColor?: string;\n  theme?: \"dark\" | \"light\";\n  color?: string;\n  onClick?: () => void;\n  className?: string;\n}\n\nconst SIZE_PX: Record<AvatarSize, number> = { xs: 24, sm: 32, md: 44, lg: 56, xl: 80 };\n\nconst FALLBACK_COLORS = [\"#87FFE3\", \"#F2A841\", \"#FF7A6B\", \"#8FB8FF\", \"#B8A6FF\", \"#F59EC5\", \"#C4F26B\"];\n\nconst STATUS_COLORS: Record<\"dark\" | \"light\", Record<AvatarStatus, string>> = {\n  dark: { online: \"#87FFE3\", offline: \"#7A7A7A\", busy: \"#FF7A6B\", away: \"#F2A841\" },\n  light: { online: \"#0E9F80\", offline: \"#9A9A9A\", busy: \"#E5484D\", away: \"#D9822B\" },\n};\n\nfunction hash(str: string) {\n  let h = 0;\n  for (let i = 0; i < str.length; i++) h = (h * 31 + str.charCodeAt(i)) | 0;\n  return Math.abs(h);\n}\n\nfunction initialsOf(name: string) {\n  const parts = name.trim().split(/\\s+/).filter(Boolean);\n  if (parts.length === 0) return \"\";\n  if (parts.length === 1) return parts[0].slice(0, 2).toUpperCase();\n  return (parts[0][0] + parts[parts.length - 1][0]).toUpperCase();\n}\n\nfunction PersonIcon({ size }: { size: number }) {\n  return (\n    <svg width={size} height={size} viewBox=\"0 0 24 24\" fill=\"none\" stroke=\"currentColor\" strokeWidth=\"1.8\" strokeLinecap=\"round\" strokeLinejoin=\"round\" aria-hidden=\"true\">\n      <circle cx=\"12\" cy=\"8.5\" r=\"3.6\" />\n      <path d=\"M4.8 20c.9-3.6 3.7-5.6 7.2-5.6s6.3 2 7.2 5.6\" />\n    </svg>\n  );\n}\n\nexport function Avatar({ src, alt, name, size = \"md\", shape = \"circle\", status, pulse = false, ring = false, ringColor = \"#F2A841\", theme = \"dark\", color, onClick, className }: AvatarProps) {\n  const px = typeof size === \"number\" ? size : SIZE_PX[size];\n  const [failed, setFailed] = React.useState(false);\n  const [loaded, setLoaded] = React.useState(false);\n  const [prevSrc, setPrevSrc] = React.useState(src);\n  if (src !== prevSrc) {\n    setPrevSrc(src);\n    setFailed(false);\n    setLoaded(false);\n  }\n  const showImage = Boolean(src) && !failed;\n  const bg = color ?? (name ? FALLBACK_COLORS[hash(name) % FALLBACK_COLORS.length] : theme === \"dark\" ? \"rgba(255,255,255,0.1)\" : \"rgba(10,10,10,0.08)\");\n  const fg = color ? \"#0A0A0A\" : name ? \"#0A0A0A\" : theme === \"dark\" ? \"rgba(245,244,241,0.6)\" : \"rgba(10,10,10,0.5)\";\n  const radius = shape === \"circle\" ? \"50%\" : shape === \"rounded\" ? px * 0.28 : px * 0.08;\n  const cut = theme === \"dark\" ? \"#0E0E0E\" : \"#FFFFFF\";\n  const dot = Math.max(8, Math.round(px * 0.27));\n  const interactive = Boolean(onClick);\n  const Tag = interactive ? motion.button : motion.span;\n\n  return (\n    <Tag\n      {...(interactive ? { type: \"button\" as const, onClick } : {})}\n      role={showImage ? undefined : \"img\"}\n      aria-label={alt ?? name ?? \"Avatar\"}\n      className={cn(\"relative inline-flex shrink-0 select-none border-none bg-transparent p-0 outline-none\", interactive && \"cursor-pointer focus-visible:ring-2\", className)}\n      style={{ width: px, height: px, [\"--tw-ring-color\" as string]: ringColor }}\n      whileHover={interactive ? { scale: 1.06 } : undefined}\n      whileTap={interactive ? { scale: 0.95 } : undefined}\n      transition={{ type: \"spring\", stiffness: 420, damping: 24 }}\n    >\n      <span\n        className=\"relative flex h-full w-full items-center justify-center overflow-hidden font-semibold\"\n        style={{\n          borderRadius: radius,\n          background: showImage && loaded ? \"transparent\" : bg,\n          color: fg,\n          fontSize: px * 0.38,\n          fontFamily: \"Inter, sans-serif\",\n          letterSpacing: \"-0.01em\",\n          boxShadow: ring ? `0 0 0 2px ${cut}, 0 0 0 ${2 + Math.max(2, px * 0.05)}px ${ringColor}` : undefined,\n          transition: \"box-shadow 0.2s ease\",\n        }}\n      >\n        {showImage ? (\n          // eslint-disable-next-line @next/next/no-img-element\n          <img\n            ref={(el) => {\n              if (el?.complete) {\n                if (el.naturalWidth > 0) setLoaded(true);\n                else setFailed(true);\n              }\n            }}\n            src={src}\n            alt={alt ?? name ?? \"\"}\n            draggable={false}\n            onLoad={() => setLoaded(true)}\n            onError={() => setFailed(true)}\n            className=\"absolute inset-0 h-full w-full object-cover\"\n            style={{ opacity: loaded ? 1 : 0, transition: \"opacity 0.3s ease\" }}\n          />\n        ) : null}\n        {(!showImage || !loaded) && (name ? <span>{initialsOf(name)}</span> : <PersonIcon size={px * 0.56} />)}\n      </span>\n\n      {status && (\n        <span className=\"absolute\" style={{ right: shape === \"circle\" ? px * 0.02 : -dot * 0.15, bottom: shape === \"circle\" ? px * 0.02 : -dot * 0.15, width: dot, height: dot }} aria-label={status}>\n          {pulse && status === \"online\" && (\n            <motion.span className=\"absolute inset-0 rounded-full\" style={{ background: STATUS_COLORS[theme][status] }} animate={{ scale: [1, 2.3], opacity: [0.5, 0] }} transition={{ duration: 1.6, ease: \"easeOut\", repeat: Infinity }} />\n          )}\n          <span className=\"absolute inset-0 rounded-full\" style={{ background: STATUS_COLORS[theme][status], boxShadow: `0 0 0 ${Math.max(2, dot * 0.2)}px ${cut}` }} />\n        </span>\n      )}\n    </Tag>\n  );\n}\n",
      "type": "registry:component"
    }
  ],
  "type": "registry:component"
}