{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "chat-bubble",
  "title": "Chat Bubble",
  "description": "Chat message bubbles for both sides of a conversation: runs from the same person group together with tight inner corners and one avatar, outgoing messages show sending, delivered and read ticks, reactions pop in under a bubble, and a typing bubble bounces while someone writes.",
  "dependencies": [
    "motion",
    "clsx",
    "tailwind-merge"
  ],
  "files": [
    {
      "path": "registry/new-york/chat-bubble/chat-bubble.tsx",
      "content": "\"use client\";\n\nimport * as React from \"react\";\nimport { motion, AnimatePresence, useReducedMotion } 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 ChatStatus = \"sending\" | \"sent\" | \"delivered\" | \"read\";\n\nexport interface ChatReaction {\n  emoji: string;\n  count: number;\n  /** Whether the current user added this one. */\n  mine?: boolean;\n}\n\nexport interface ChatBubbleProps {\n  /** in: from someone else, on the left. out: from you, on the right. */\n  side?: \"in\" | \"out\";\n  children?: React.ReactNode;\n  /** Shown above the first bubble of an incoming group. */\n  name?: string;\n  /** Avatar image URL, or initials are made from name. Shown beside the last bubble of a group. */\n  avatar?: string;\n  time?: string;\n  /** Delivery ticks for outgoing messages. */\n  status?: ChatStatus;\n  /** Where the bubble sits in a run from the same sender; shapes the corners and places the avatar. */\n  position?: \"single\" | \"first\" | \"middle\" | \"last\";\n  reactions?: ChatReaction[];\n  onReact?: (emoji: string) => void;\n  theme?: \"dark\" | \"light\";\n  className?: string;\n}\n\nconst PALETTES = {\n  dark: { text: \"#F5F4F1\", muted: \"rgba(245,244,241,0.5)\", inBg: \"#1A1A1A\", inBorder: \"rgba(255,255,255,0.08)\", outBg: \"#F5F4F1\", outText: \"#0A0A0A\", outMuted: \"rgba(10,10,10,0.5)\", avatar: \"rgba(255,255,255,0.1)\", chip: \"#1A1A1A\", chipMine: \"rgba(255,255,255,0.14)\", chipBorder: \"rgba(255,255,255,0.12)\", read: \"#5B9DFF\", focus: \"rgba(245,244,241,0.85)\" },\n  light: { text: \"#0A0A0A\", muted: \"rgba(10,10,10,0.5)\", inBg: \"#F1F1EF\", inBorder: \"rgba(10,10,10,0.06)\", outBg: \"#0A0A0A\", outText: \"#FFFFFF\", outMuted: \"rgba(255,255,255,0.6)\", avatar: \"rgba(10,10,10,0.08)\", chip: \"#FFFFFF\", chipMine: \"rgba(10,10,10,0.08)\", chipBorder: \"rgba(10,10,10,0.12)\", read: \"#2F6FDB\", focus: \"rgba(10,10,10,0.85)\" },\n};\n\nconst initials = (n?: string) =>\n  (n ?? \"?\")\n    .split(/\\s+/)\n    .map((w) => w[0])\n    .slice(0, 2)\n    .join(\"\")\n    .toUpperCase();\n\nfunction Ticks({ status, color, readColor, reduce }: { status: ChatStatus; color: string; readColor: string; reduce: boolean }) {\n  if (status === \"sending\") {\n    return (\n      <motion.svg width=\"12\" height=\"12\" viewBox=\"0 0 24 24\" fill=\"none\" stroke={color} strokeWidth=\"2.4\" strokeLinecap=\"round\" aria-hidden=\"true\" animate={reduce ? undefined : { rotate: 360 }} transition={{ duration: 1.2, repeat: Infinity, ease: \"linear\" }}>\n        <path d=\"M12 3a9 9 0 1 0 9 9\" />\n      </motion.svg>\n    );\n  }\n  const c = status === \"read\" ? readColor : color;\n  const two = status !== \"sent\";\n  return (\n    <svg width=\"16\" height=\"12\" viewBox=\"0 0 28 20\" fill=\"none\" stroke={c} strokeWidth=\"2.6\" strokeLinecap=\"round\" strokeLinejoin=\"round\" aria-hidden=\"true\" style={{ transition: \"stroke 0.3s ease\" }}>\n      <motion.path d=\"m2 10.5 5 5L17.5 4\" initial={false} animate={{ pathLength: 1 }} />\n      <motion.path d=\"m12.5 14 1.5 1.5L24 4\" initial={false} animate={{ pathLength: two ? 1 : 0, opacity: two ? 1 : 0 }} transition={{ duration: reduce ? 0 : 0.25 }} />\n    </svg>\n  );\n}\n\nexport function ChatBubble({ side = \"in\", children, name, avatar, time, status, position = \"single\", reactions = [], onReact, theme = \"dark\", className }: ChatBubbleProps) {\n  const p = PALETTES[theme];\n  const reduce = Boolean(useReducedMotion());\n  const out = side === \"out\";\n  const tail = position === \"single\" || position === \"last\";\n  const top = position === \"single\" || position === \"first\";\n\n  // Corners: big everywhere, small on the sender's side where bubbles in a run touch.\n  const R = 18;\n  const r = 6;\n  const near = out ? [\"TopRight\", \"BottomRight\"] : [\"TopLeft\", \"BottomLeft\"];\n  const radius: React.CSSProperties = {\n    borderRadius: R,\n    [`border${near[0]}Radius`]: top ? R : r,\n    [`border${near[1]}Radius`]: r,\n  };\n\n  const label = out ? \"You\" : (name ?? \"Them\");\n  const statusText = status ? { sending: \"sending\", sent: \"sent\", delivered: \"delivered\", read: \"read\" }[status] : null;\n\n  return (\n    <div className={cn(\"flex w-full items-end\", out ? \"flex-row-reverse\" : \"flex-row\", className)} style={{ gap: 8, fontFamily: \"Inter, sans-serif\", marginTop: top ? 10 : 2 }}>\n      {!out && (\n        <span className=\"flex shrink-0 items-center justify-center overflow-hidden rounded-full text-[11px] font-semibold\" style={{ width: 28, height: 28, background: tail ? p.avatar : \"transparent\", color: p.text, visibility: tail ? \"visible\" : \"hidden\" }} aria-hidden=\"true\">\n          {avatar ? (\n            // eslint-disable-next-line @next/next/no-img-element\n            <img src={avatar} alt=\"\" className=\"h-full w-full object-cover\" />\n          ) : (\n            initials(name)\n          )}\n        </span>\n      )}\n      <div className={cn(\"flex max-w-[78%] min-w-0 flex-col\", out ? \"items-end\" : \"items-start\")} style={{ gap: 4 }}>\n        {!out && name && top && (\n          <span className=\"text-[12px] font-medium\" style={{ color: p.muted, paddingLeft: 4 }}>\n            {name}\n          </span>\n        )}\n        <motion.div\n          className=\"relative\"\n          style={{ transformOrigin: out ? \"100% 100%\" : \"0% 100%\" }}\n          initial={reduce ? { opacity: 0 } : { opacity: 0, scale: 0.85, y: 8 }}\n          animate={{ opacity: 1, scale: 1, y: 0 }}\n          transition={{ type: \"spring\", stiffness: 520, damping: 32 }}\n        >\n          <div\n            className=\"text-[14.5px] leading-[1.45] break-words\"\n            role=\"group\"\n            aria-label={`${label}${time ? ` at ${time}` : \"\"}${statusText ? `, ${statusText}` : \"\"}`}\n            style={{ ...radius, padding: \"9px 13px\", background: out ? p.outBg : p.inBg, color: out ? p.outText : p.text, border: out ? \"none\" : `1px solid ${p.inBorder}` }}\n          >\n            {children}\n            {(time || status) && (\n              <span className=\"float-right inline-flex items-center tabular-nums\" style={{ gap: 4, marginLeft: 10, marginTop: 6, marginBottom: -3, fontSize: 11, color: out ? p.outMuted : p.muted }}>\n                {time}\n                {out && status && <Ticks status={status} color={p.outMuted} readColor={p.read} reduce={reduce} />}\n              </span>\n            )}\n          </div>\n          <AnimatePresence initial={false}>\n            {reactions.length > 0 && (\n              <motion.div key=\"reactions\" className={cn(\"absolute -bottom-4 flex\", out ? \"right-2\" : \"left-2\")} style={{ gap: 4 }} initial={{ opacity: 0, scale: 0.6 }} animate={{ opacity: 1, scale: 1 }} exit={{ opacity: 0, scale: 0.6 }} transition={{ type: \"spring\", stiffness: 600, damping: 28 }}>\n                {reactions.map((re) => (\n                  <motion.button\n                    key={re.emoji}\n                    type=\"button\"\n                    layout\n                    onClick={() => onReact?.(re.emoji)}\n                    aria-pressed={Boolean(re.mine)}\n                    aria-label={`${re.emoji} ${re.count}`}\n                    className=\"flex cursor-pointer items-center rounded-full text-[12px] leading-none tabular-nums outline-none focus-visible:ring-2\"\n                    style={{ gap: 3, height: 22, padding: \"0 7px\", background: re.mine ? p.chipMine : p.chip, border: `1px solid ${p.chipBorder}`, color: p.text, [\"--tw-ring-color\" as string]: p.focus }}\n                    whileTap={{ scale: 0.9 }}\n                  >\n                    <span>{re.emoji}</span>\n                    {re.count > 1 && <span style={{ color: p.muted }}>{re.count}</span>}\n                  </motion.button>\n                ))}\n              </motion.div>\n            )}\n          </AnimatePresence>\n        </motion.div>\n        {reactions.length > 0 && <span style={{ height: 12 }} />}\n      </div>\n    </div>\n  );\n}\n\n/** Three bouncing dots in an incoming bubble, for \"someone is typing\". */\nexport function TypingBubble({ name, avatar, theme = \"dark\", className }: { name?: string; avatar?: string; theme?: \"dark\" | \"light\"; className?: string }) {\n  const p = PALETTES[theme];\n  const reduce = Boolean(useReducedMotion());\n  return (\n    <motion.div className={cn(\"flex items-end\", className)} style={{ gap: 8, marginTop: 10, fontFamily: \"Inter, sans-serif\" }} initial={{ opacity: 0, y: 6 }} animate={{ opacity: 1, y: 0 }} exit={{ opacity: 0, y: 6, transition: { duration: 0.12 } }} role=\"status\" aria-label={`${name ?? \"Someone\"} is typing`}>\n      <span className=\"flex shrink-0 items-center justify-center overflow-hidden rounded-full text-[11px] font-semibold\" style={{ width: 28, height: 28, background: p.avatar, color: p.text }} aria-hidden=\"true\">\n        {avatar ? (\n          // eslint-disable-next-line @next/next/no-img-element\n          <img src={avatar} alt=\"\" className=\"h-full w-full object-cover\" />\n        ) : (\n          initials(name)\n        )}\n      </span>\n      <span className=\"flex items-center\" style={{ gap: 4, height: 38, padding: \"0 14px\", borderRadius: 18, borderBottomLeftRadius: 6, background: p.inBg, border: `1px solid ${p.inBorder}` }}>\n        {[0, 1, 2].map((i) => (\n          <motion.span key={i} className=\"block rounded-full\" style={{ width: 6, height: 6, background: p.muted }} animate={reduce ? undefined : { y: [0, -4, 0], opacity: [0.5, 1, 0.5] }} transition={{ duration: 0.9, repeat: Infinity, delay: i * 0.15, ease: \"easeInOut\" }} />\n        ))}\n      </span>\n    </motion.div>\n  );\n}\n\nexport default ChatBubble;\n",
      "type": "registry:component"
    }
  ],
  "type": "registry:component"
}