{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "tw-user-avatar",
  "type": "registry:ui",
  "title": "react-tw/user-avatar.tsx",
  "description": "Carbon for IBM Products `UserAvatar` as React + Tailwind, the look of `<ui-user-avatar>`: a round avatar — the photo Copied from @purpurabog/ui 2.3.0; the package is the maintained source, this copy is yours to change. Icons from the Carbon Design System (Apache-2.0, © IBM Corp.; see THIRD-PARTY-NOTICES.md in the package).",
  "dependencies": [],
  "registryDependencies": [
    "@kanok-ui/core-position",
    "@kanok-ui/core-user-avatar",
    "@kanok-ui/tw-theme",
    "@kanok-ui/tw-tooltip",
    "@kanok-ui/tw-utils"
  ],
  "files": [
    {
      "path": "src/react-tw/user-avatar.tsx",
      "type": "registry:ui",
      "target": "components/ui/react-tw/user-avatar.tsx",
      "content": "import type { ComponentProps, CSSProperties, ReactNode } from 'react';\nimport type { Placement } from '../core/position.ts';\nimport { avatarInitials, USER_AVATAR_COLORS, USER_AVATAR_ICON_SIZE, type UserAvatarColor, type UserAvatarSize } from '../core/user-avatar.ts';\nimport { Tooltip } from './tooltip.tsx';\nimport { cn } from './lib/utils.ts';\n\nexport interface UserAvatarProps extends Omit<ComponentProps<'div'>, 'children'> {\n    /** The person's name or initials; the avatar shows the initials (\"thomas j. watson\" → \"TW\"). */\n    name?: string;\n    /** A photo's URL, shown instead of the initials. */\n    image?: string;\n    /** The photo's alt text. */\n    imageDescription?: string;\n    size?: UserAvatarSize;\n    /** One of Carbon's 12 avatar colours, `order-1-cyan` … `order-12-teal`. */\n    backgroundColor?: UserAvatarColor;\n    /** Shown in a tooltip and names the avatar, which becomes a button. */\n    tooltipText?: string;\n    tooltipAlignment?: Placement;\n    /** A custom icon in place of the initials / user icon (Carbon `renderIcon`), sized 16 / 20 / 24 / 32px. */\n    icon?: ReactNode;\n}\n\n// literal classes, so Tailwind sees every one\nconst BACKGROUND = ['bg-avatar-1', 'bg-avatar-2', 'bg-avatar-3', 'bg-avatar-4', 'bg-avatar-5', 'bg-avatar-6', 'bg-avatar-7', 'bg-avatar-8', 'bg-avatar-9', 'bg-avatar-10', 'bg-avatar-11', 'bg-avatar-12'];\n\nconst SIZE: Record<UserAvatarSize, string> = {\n    sm: 'size-6 type-caption [&_img]:size-6',\n    md: 'size-8 type-body-sm [&_img]:size-8',\n    lg: 'size-12 type-heading-03 tracking-normal [&_img]:size-12',\n    xl: 'size-16 type-heading-04 tracking-normal [&_img]:size-16',\n};\n\nfunction UserIcon({ px }: Readonly<{ px: number }>) {\n    if (px === 16) {\n        return (\n            <svg viewBox=\"0 0 16 16\" aria-hidden=\"true\">\n                <path d=\"M8,2c1.4,0,2.5,1.1,2.5,2.5S9.4,7,8,7S5.5,5.9,5.5,4.5S6.6,2,8,2 M8,1C6.1,1,4.5,2.6,4.5,4.5S6.1,8,8,8s3.5-1.6,3.5-3.5S9.9,1,8,1z\" />\n                <path d=\"M13,15h-1v-2.5c0-1.4-1.1-2.5-2.5-2.5h-3C5.1,10,4,11.1,4,12.5V15H3v-2.5C3,10.6,4.6,9,6.5,9h3c1.9,0,3.5,1.6,3.5,3.5V15z\" />\n            </svg>\n        );\n    }\n    return (\n        <svg viewBox=\"0 0 32 32\" aria-hidden=\"true\">\n            <path d=\"M16,4a5,5,0,1,1-5,5,5,5,0,0,1,5-5m0-2a7,7,0,1,0,7,7A7,7,0,0,0,16,2Z\" />\n            <path d=\"M26,30H24V25a5,5,0,0,0-5-5H13a5,5,0,0,0-5,5v5H6V25a7,7,0,0,1,7-7h6a7,7,0,0,1,7,7Z\" />\n        </svg>\n    );\n}\n\nfunction avatarContent({ image, imageDescription, icon, name, px }: Readonly<{ image?: string; imageDescription?: string; icon?: ReactNode; name?: string; px: number }>) {\n    if (image) return <img src={image} alt={imageDescription ?? ''} className=\"max-w-none flex-none rounded-[100%] object-fill\" />;\n    if (icon) return icon;\n    if (name) return avatarInitials(name);\n    return <UserIcon px={px} />;\n}\n\n/**\n * Carbon for IBM Products `UserAvatar` as React + Tailwind, the look of `<ui-user-avatar>`: a round avatar — the photo\n * (`image`), a custom `icon`, the initials of `name`, or the user icon, in that order; sm 24 / md 32 / lg 48 / xl 64px\n * in text-inverse on one of Carbon's 12 avatar colours (a lighter grade on g90 / g100). With `tooltipText` it becomes\n * a button named by that text, which shows it in a tooltip and takes a 2px focus ring. Start the text with the\n * initials (\"TW, Thomas J. Watson\", as Carbon's story) so the name holds what is seen (WCAG 2.5.3).\n */\nexport function UserAvatar({ name, image, imageDescription, size = 'md', backgroundColor = 'order-1-cyan', tooltipText, tooltipAlignment = 'bottom', icon, className, style, ...rest }: Readonly<UserAvatarProps>) {\n    const px = USER_AVATAR_ICON_SIZE[size] ?? 20;\n    const color = Math.max(USER_AVATAR_COLORS.indexOf(backgroundColor), 0);\n    const avatar = (\n        <div\n            {...rest}\n            style={{ '--_icon': `${px}px`, ...style } as CSSProperties}\n            className={cn(\n                'relative box-border inline-flex items-center justify-center rounded-[100%] align-middle border-[0.5px] border-solid border-transparent text-inverse-ink outline-offset-[3px]',\n                '[&_svg]:size-(--_icon) [&_svg]:flex-none [&_svg]:fill-current [&_svg]:text-icon-inverse',\n                'forced-colors:border-[CanvasText]',\n                BACKGROUND[color],\n                SIZE[size] ?? SIZE.md,\n                tooltipText && 'group-focus-visible:outline-[length:var(--ui-focus-width,2px)] group-focus-visible:outline-offset-1 group-focus-visible:outline-focus group-focus-visible:outline-solid',\n                className,\n            )}\n        >\n            {avatarContent({ image, imageDescription, icon, name, px })}\n        </div>\n    );\n    if (!tooltipText) return avatar;\n    return (\n        <Tooltip text={tooltipText} asLabel placement={tooltipAlignment} className=\"align-middle\">\n            <button type=\"button\" className=\"group flex cursor-default border-0 bg-transparent p-0 text-inherit outline-none\">\n                {avatar}\n            </button>\n        </Tooltip>\n    );\n}\n"
    }
  ]
}
