{"$schema":"https://ui.shadcn.com/schema/registry-item.json","name":"avatar-group","type":"registry:ui","title":"Avatar Group","description":"Overlapping avatar stack that fans apart on hover, with name tooltips and a +N overflow chip.","dependencies":[],"registryDependencies":["utils"],"files":[{"path":"registry/ui/avatar-group.tsx","type":"registry:ui","content":"\"use client\";\n/* eslint-disable @next/next/no-img-element */\n\nimport { useState, type CSSProperties, type ReactNode } from \"react\";\nimport { cn } from \"@/lib/utils\";\n\nexport interface AvatarGroupPerson {\n  name: string;\n  src?: string;\n}\n\nexport interface AvatarGroupProps {\n  people: AvatarGroupPerson[];\n  /** Avatars shown before collapsing the rest into a \"+N\" chip. */\n  max?: number;\n  /** Avatar diameter in px. */\n  size?: number;\n  /** Px each avatar tucks under its neighbour at rest. */\n  overlap?: number;\n  /** Fan the avatars apart while the group is hovered or focused. */\n  spread?: boolean;\n  className?: string;\n}\n\nconst initials = (name: string) =>\n  name\n    .split(/\\s+/)\n    .filter(Boolean)\n    .map((w, i, a) => (i === 0 || i === a.length - 1 ? w[0] : \"\"))\n    .join(\"\")\n    .toUpperCase();\n\nfunction hue(name: string) {\n  let h = 0;\n  for (const c of name) h = (h * 31 + c.charCodeAt(0)) % 360;\n  return h;\n}\n\nfunction Face({ person }: { person: AvatarGroupPerson }) {\n  const [failed, setFailed] = useState<string | null>(null);\n  const h = hue(person.name);\n  return (\n    <span\n      aria-hidden\n      className=\"grid size-full place-items-center overflow-hidden rounded-full font-semibold\"\n      style={{\n        background: `linear-gradient(135deg, oklch(0.78 0.11 ${h}), oklch(0.62 0.14 ${(h + 40) % 360}))`,\n        color: `oklch(0.22 0.05 ${h})`,\n        fontSize: \"calc(var(--ag-size) * 0.36)\",\n      }}\n    >\n      {person.src && failed !== person.src ? (\n        <img src={person.src} alt=\"\" draggable={false} onError={() => setFailed(person.src!)} className=\"size-full object-cover\" />\n      ) : (\n        initials(person.name)\n      )}\n    </span>\n  );\n}\n\nfunction Tip({ children }: { children: ReactNode }) {\n  return (\n    <span\n      aria-hidden\n      className={cn(\n        \"pointer-events-none absolute bottom-full left-1/2 z-20 mb-2 w-max max-w-56 -translate-x-1/2 translate-y-1 scale-90 rounded-md bg-foreground px-2 py-1 text-xs font-medium text-background opacity-0 shadow-lg\",\n        \"transition-[opacity,translate,scale] duration-200 ease-[cubic-bezier(.3,1.4,.5,1)] motion-reduce:transition-none\",\n        \"group-hover/item:translate-y-0 group-hover/item:scale-100 group-hover/item:opacity-100 group-focus-visible/item:translate-y-0 group-focus-visible/item:scale-100 group-focus-visible/item:opacity-100\",\n      )}\n    >\n      {children}\n    </span>\n  );\n}\n\nexport function AvatarGroup({ people, max = 4, size = 44, overlap = 14, spread = true, className }: AvatarGroupProps) {\n  const shown = people.slice(0, max);\n  const rest = people.slice(max);\n  const item = cn(\n    \"group/item relative -ml-[var(--ag-overlap)] rounded-full outline-none ring-[3px] ring-background first:ml-0\",\n    \"size-[var(--ag-size)] transition-[margin,translate] duration-300 ease-[cubic-bezier(.3,1.3,.5,1)] motion-reduce:transition-none\",\n    \"hover:z-10 hover:-translate-y-1 focus-visible:z-10 focus-visible:-translate-y-1 focus-visible:ring-ring\",\n    spread && \"group-hover/ag:ml-1 group-hover/ag:first:ml-0 group-focus-within/ag:ml-1 group-focus-within/ag:first:ml-0\",\n  );\n\n  return (\n    <ul\n      aria-label={`${people.length} people`}\n      className={cn(\"group/ag flex items-center\", className)}\n      style={{ \"--ag-size\": `${size}px`, \"--ag-overlap\": `${overlap}px` } as CSSProperties}\n    >\n      {shown.map((p) => (\n        <li key={p.name} aria-label={p.name} tabIndex={0} className={item}>\n          <Face person={p} />\n          <Tip>{p.name}</Tip>\n        </li>\n      ))}\n      {rest.length > 0 && (\n        <li\n          aria-label={`and ${rest.length} more: ${rest.map((p) => p.name).join(\", \")}`}\n          tabIndex={0}\n          className={cn(item, \"grid place-items-center bg-muted font-semibold text-muted-foreground\")}\n          style={{ fontSize: `calc(var(--ag-size) * 0.32)` }}\n        >\n          <span aria-hidden>+{rest.length}</span>\n          <Tip>\n            {rest.slice(0, 4).map((p) => p.name).join(\", \")}\n            {rest.length > 4 && ` and ${rest.length - 4} more`}\n          </Tip>\n        </li>\n      )}\n    </ul>\n  );\n}\n"}]}