{"$schema":"https://ui.shadcn.com/schema/registry-item.json","name":"avatar-spread","type":"registry:block","title":"Avatar spread","description":"A collaborator stack that fans out on hover or focus, with status dots, per-person tooltips and a line that follows the person under the pointer.","dependencies":["motion"],"registryDependencies":["utils"],"files":[{"path":"registry/prequel/avatar-spread/avatar-spread.tsx","type":"registry:component","content":"\"use client\";\n\nimport { useRef, useState } from \"react\";\nimport {\n  MotionConfig,\n  motion,\n  useInView,\n  useReducedMotion,\n} from \"motion/react\";\nimport { cn } from \"@/lib/utils\";\n\nconst EASE: [number, number, number, number] = [0.22, 1, 0.36, 1];\n\n/* ------------------------------------------------------------------ */\n/* types                                                               */\n/* ------------------------------------------------------------------ */\n\nexport type AvatarSpreadPerson = {\n  id: string;\n  name: string;\n  role?: string;\n  /** online shows a green dot, away a grey one, busy a red one. */\n  status?: \"online\" | \"away\" | \"busy\";\n};\n\nexport type AvatarSpreadProps = {\n  className?: string;\n  title?: string;\n  description?: string;\n  people?: AvatarSpreadPerson[];\n  /** Person that gets the filled avatar. Defaults to the first person. */\n  currentId?: string;\n  /** Extra people who do not get an avatar of their own. Defaults to 3. */\n  moreCount?: number;\n  /** Short line under the group. Defaults to a real-looking team count. */\n  note?: string;\n};\n\n/* ------------------------------------------------------------------ */\n/* deterministic demo data                                             */\n/* ------------------------------------------------------------------ */\n\nconst DEFAULT_PEOPLE: AvatarSpreadPerson[] = [\n  { id: \"ama\", name: \"Ama Mensah\", role: \"Product\", status: \"online\" },\n  { id: \"lucas\", name: \"Lucas Ferreira\", role: \"Design\", status: \"online\" },\n  { id: \"mei\", name: \"Mei Tanaka\", role: \"Engineering\", status: \"away\" },\n  { id: \"jonas\", name: \"Jonas Weber\", role: \"Data\", status: \"online\" },\n  { id: \"priya\", name: \"Priya Nair\", role: \"Support\", status: \"busy\" },\n];\n\n/* ------------------------------------------------------------------ */\n/* helpers                                                             */\n/* ------------------------------------------------------------------ */\n\nfunction initials(name: string) {\n  return name\n    .split(\" \")\n    .filter(Boolean)\n    .slice(0, 2)\n    .map((part) => part.charAt(0).toUpperCase())\n    .join(\"\");\n}\n\nconst STATUS_COLOR: Record<NonNullable<AvatarSpreadPerson[\"status\"]>, string> = {\n  online: \"bg-success\",\n  away: \"bg-muted-foreground\",\n  busy: \"bg-destructive\",\n};\n\nconst STATUS_LABEL: Record<NonNullable<AvatarSpreadPerson[\"status\"]>, string> = {\n  online: \"online\",\n  away: \"away\",\n  busy: \"in a meeting\",\n};\n\n/* ------------------------------------------------------------------ */\n/* one avatar                                                          */\n/* ------------------------------------------------------------------ */\n\ntype AvatarButtonProps = {\n  person: AvatarSpreadPerson;\n  index: number;\n  total: number;\n  spread: boolean;\n  show: boolean;\n  reduce: boolean;\n  current: boolean;\n  hovered: boolean;\n  onHover: (id: string | null) => void;\n};\n\nfunction AvatarButton({\n  person,\n  index,\n  total,\n  spread,\n  show,\n  reduce,\n  current,\n  hovered,\n  onHover,\n}: AvatarButtonProps) {\n  const status = person.status ?? \"away\";\n  const offset = index - (total - 1) / 2;\n\n  return (\n    <motion.button\n      type=\"button\"\n      onMouseEnter={() => onHover(person.id)}\n      onMouseLeave={() => onHover(null)}\n      onFocus={() => onHover(person.id)}\n      onBlur={() => onHover(null)}\n      aria-label={`${person.name}${person.role ? `, ${person.role}` : \"\"}, ${STATUS_LABEL[status]}`}\n      initial={reduce ? false : { opacity: 0, y: 8 }}\n      animate={{\n        opacity: show || reduce ? 1 : 0,\n        y: show || reduce ? 0 : 8,\n        x: spread && !reduce ? index * 15 : 0,\n        rotate: spread && !reduce ? offset * 2.6 : 0,\n      }}\n      transition={{\n        duration: reduce ? 0 : 0.45,\n        ease: EASE,\n        delay: reduce ? 0 : index * 0.05,\n        x: reduce\n          ? { duration: 0 }\n          : { type: \"spring\", stiffness: 340, damping: 28, mass: 0.7 },\n        rotate: reduce\n          ? { duration: 0 }\n          : { type: \"spring\", stiffness: 340, damping: 28, mass: 0.7 },\n      }}\n      style={{ zIndex: hovered ? 30 : total - index }}\n      className={cn(\n        \"group relative -ml-2 grid h-9 w-9 shrink-0 place-items-center rounded-full border border-border text-[11px] font-semibold tracking-tight first:ml-0\",\n        \"transition-colors duration-200 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 focus-visible:ring-offset-card motion-reduce:transition-none\",\n        current\n          ? \"bg-foreground text-background\"\n          : \"bg-muted text-foreground hover:bg-secondary\",\n        \"sm:h-10 sm:w-10 sm:text-[12px]\"\n      )}\n    >\n      <span aria-hidden=\"true\">{initials(person.name)}</span>\n\n      <span\n        aria-hidden=\"true\"\n        className={cn(\n          \"absolute -bottom-0.5 -right-0.5 h-2.5 w-2.5 rounded-full border-2 border-card\",\n          STATUS_COLOR[status]\n        )}\n      />\n\n      <span\n        aria-hidden=\"true\"\n        className=\"pointer-events-none absolute bottom-full left-1/2 z-40 mb-2 -translate-x-1/2 whitespace-nowrap rounded-md border border-border bg-popover px-2 py-1 text-[11px] font-medium text-popover-foreground opacity-0 shadow-sm transition-opacity duration-150 group-hover:opacity-100 group-focus-visible:opacity-100\"\n      >\n        {person.name}\n        {current ? \" · you\" : \"\"}\n      </span>\n    </motion.button>\n  );\n}\n\n/* ------------------------------------------------------------------ */\n/* block                                                               */\n/* ------------------------------------------------------------------ */\n\nexport function AvatarSpread({\n  className,\n  title = \"In this file\",\n  description = \"Pricing page · design review\",\n  people = DEFAULT_PEOPLE,\n  currentId,\n  moreCount = 3,\n  note,\n}: AvatarSpreadProps) {\n  const ref = useRef<HTMLDivElement>(null);\n  const inView = useInView(ref, { once: true, margin: \"-10% 0px\" });\n  const reduce = Boolean(useReducedMotion());\n\n  const safePeople = people.length > 0 ? people : DEFAULT_PEOPLE;\n  const [spread, setSpread] = useState(false);\n  const [hovered, setHovered] = useState<string | null>(null);\n\n  const shown = safePeople.slice(0, 6);\n  const extra = Math.max(0, moreCount) + Math.max(0, safePeople.length - shown.length);\n  const active = shown.find((person) => person.id === hovered) ?? shown[0];\n  const activeStatus = active?.status ?? \"online\";\n  const current = currentId ?? shown[0]?.id;\n\n  const online = shown.filter((person) => person.status === \"online\").length;\n\n  return (\n    <MotionConfig reducedMotion=\"user\">\n      <motion.div\n        ref={ref}\n        initial={reduce ? false : { opacity: 0, y: 16 }}\n        animate={inView || reduce ? { opacity: 1, y: 0 } : { opacity: 0, y: 16 }}\n        transition={{ duration: reduce ? 0 : 0.6, ease: EASE }}\n        className={cn(\n          \"w-full rounded-xl border border-border bg-card p-5 text-card-foreground sm:p-6\",\n          className\n        )}\n      >\n        <div className=\"flex flex-wrap items-start justify-between gap-3\">\n          <div className=\"min-w-0\">\n            <h2 className=\"text-[15px] font-semibold tracking-tight\">{title}</h2>\n            <p className=\"mt-0.5 text-[13px] text-muted-foreground\">{description}</p>\n          </div>\n\n          <span className=\"inline-flex shrink-0 items-center gap-1.5 rounded-full border border-border px-2.5 py-1 text-[11.5px] font-medium text-muted-foreground\">\n            <span\n              aria-hidden=\"true\"\n              className=\"relative flex h-2 w-2 items-center justify-center\"\n            >\n              <span aria-hidden=\"true\" className=\"absolute h-2 w-2 rounded-full bg-success/25\" />\n              <span aria-hidden=\"true\" className=\"h-1 w-1 rounded-full bg-success\" />\n            </span>\n            <span className=\"tabular-nums\">{online} editing</span>\n          </span>\n        </div>\n\n        <div\n          className=\"mt-6 flex min-h-[44px] items-center\"\n          onMouseEnter={() => setSpread(true)}\n          onMouseLeave={() => {\n            setSpread(false);\n            setHovered(null);\n          }}\n          onFocusCapture={() => setSpread(true)}\n          onBlurCapture={(event) => {\n            if (!event.currentTarget.contains(event.relatedTarget as Node | null)) {\n              setSpread(false);\n              setHovered(null);\n            }\n          }}\n        >\n          <div className=\"flex items-center pr-14\">\n            {shown.map((person, index) => (\n              <AvatarButton\n                key={person.id}\n                person={person}\n                index={index}\n                total={shown.length}\n                spread={spread}\n                show={inView}\n                reduce={reduce}\n                current={person.id === current}\n                hovered={person.id === hovered}\n                onHover={setHovered}\n              />\n            ))}\n\n            {extra > 0 ? (\n              <motion.span\n                aria-hidden=\"true\"\n                initial={reduce ? false : { opacity: 0, scale: 0.8 }}\n                animate={{\n                  opacity: inView || reduce ? 1 : 0,\n                  scale: inView || reduce ? 1 : 0.8,\n                  x: spread && !reduce ? shown.length * 15 : 0,\n                }}\n                transition={{\n                  duration: reduce ? 0 : 0.4,\n                  ease: EASE,\n                  delay: reduce ? 0 : shown.length * 0.05,\n                  x: reduce\n                    ? { duration: 0 }\n                    : { type: \"spring\", stiffness: 340, damping: 28, mass: 0.7 },\n                }}\n                style={{ zIndex: 0 }}\n                className=\"relative -ml-2 grid h-9 w-9 shrink-0 place-items-center rounded-full border border-dashed border-border bg-background text-[10.5px] font-medium tabular-nums text-muted-foreground sm:h-10 sm:w-10\"\n              >\n                +{extra}\n              </motion.span>\n            ) : null}\n          </div>\n        </div>\n\n        <p className=\"mt-5 min-h-9 text-[12.5px] leading-5 text-muted-foreground\">\n          {active ? (\n            <>\n              <span className=\"font-medium text-foreground\">{active.name}</span>\n              {active.role ? ` · ${active.role}` : \"\"} ·{\" \"}\n              <span\n                className={cn(\n                  activeStatus === \"online\" ? \"text-success\" : undefined\n                )}\n              >\n                {STATUS_LABEL[activeStatus]}\n              </span>\n              . {note ?? `Everyone else can comment until Friday.`}\n            </>\n          ) : (\n            note ?? \"Everyone else can comment until Friday.\"\n          )}\n        </p>\n\n        <div className=\"mt-4 flex flex-wrap items-center justify-between gap-2 border-t border-border pt-3.5\">\n          <span className=\"text-[11.5px] text-muted-foreground\">\n            Hover the stack to fan it out\n          </span>\n          <span className=\"inline-flex items-center gap-1.5 text-[11px] text-muted-foreground\">\n            <span aria-hidden=\"true\" className=\"h-2 w-2 rounded-full bg-success\" />\n            live\n            <span aria-hidden=\"true\" className=\"text-border\">\n              /\n            </span>\n            <span className=\"tabular-nums\">updated 4 min ago</span>\n          </span>\n        </div>\n      </motion.div>\n    </MotionConfig>\n  );\n}\n\nexport default AvatarSpread;\n"}]}