{
  "name": "reaction",
  "type": "registry:ui",
  "framework": "react",
  "title": "Reaction Pill",
  "description": "A toggleable emoji reaction pill, plus the group that rows them under a message.",
  "dependencies": [
    "class-variance-authority"
  ],
  "files": [
    {
      "path": "ui/reaction.tsx",
      "content": "\"use client\"\n\nimport { cva, type VariantProps } from \"class-variance-authority\"\nimport * as React from \"react\"\n\nimport { cn } from \"@/lib/utils\"\n\nconst reactionVariants = cva(\n  \"inline-flex items-center gap-1 rounded-[var(--newt-radius-md)] border px-2 py-0.5 text-[13px] transition-[background-color,border-color] duration-fast ease-newt focus-visible:outline focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-newt-text-link\",\n  {\n    variants: {\n      active: {\n        false: \"border-newt-border bg-newt-bg-surface text-newt-text-secondary\",\n        true: \"border-newt-brand bg-[color-mix(in_srgb,var(--newt-brand)_15%,transparent)] text-newt-mention-text\",\n      },\n      /* `false` for a read-only reaction: no pointer, no hover. */\n      interactive: {\n        true: \"cursor-pointer\",\n        false: \"cursor-[inherit]\",\n      },\n    },\n    compoundVariants: [\n      { active: false, interactive: true, class: \"hover:bg-newt-bg-hover\" },\n    ],\n    defaultVariants: {\n      active: false,\n      interactive: true,\n    },\n  }\n)\n\nfunction isStringNode(value: React.ReactNode): value is string {\n  return Object.prototype.toString.call(value) === \"[object String]\"\n}\n\n/** What the accessible name of a reaction is built from. */\nexport interface ReactionLabelState {\n  /** The emoji's text, or `emojiAlt` for an image emoji, or `\"Emoji\"`. */\n  emoji: string\n  count: number\n  active: boolean\n}\n\n/** The English default. Pass `formatLabel` to translate it. */\nexport function defaultReactionLabel({\n  emoji,\n  count,\n  active,\n}: ReactionLabelState): string {\n  return `${emoji} reaction, ${count} ${count === 1 ? \"person\" : \"people\"}${\n    active ? \", you reacted\" : \"\"\n  }`\n}\n\nexport interface ReactionProps\n  extends\n    React.ButtonHTMLAttributes<HTMLButtonElement>,\n    Omit<VariantProps<typeof reactionVariants>, \"interactive\"> {\n  /**\n   * The emoji, drawn by your own component: an icon or an image component.\n   * Wins over `emoji` and `emojiSrc`. Set `emojiAlt` to name it.\n   */\n  children?: React.ReactNode\n  /** Emoji or icon rendered on the left. Optional when `emojiSrc` is set. */\n  emoji?: React.ReactNode\n  /** Image URL of a server (custom) emoji, rendered instead of `emoji`. */\n  emojiSrc?: string\n  /** Name of the emoji, for the accessible name: `:wolf:` or `wolf`. */\n  emojiAlt?: string\n  /** Number of users who reacted. */\n  count: number\n  /** Controlled active state. */\n  active?: boolean\n  /** Initial active state when uncontrolled. */\n  defaultActive?: boolean\n  /** Called with the next active state when toggled. */\n  onActiveChange?: (active: boolean) => void\n  /**\n   * Show the count without a toggle: renders a `<span>` that is not focusable\n   * and ignores clicks, for feeds that only display reactions.\n   */\n  readonly?: boolean\n  /** Builds the accessible name; `aria-label` still wins when both are set. */\n  formatLabel?: (state: ReactionLabelState) => string\n}\n\n/* Widens the tag so one ref type serves both elements it can be. */\nfunction asElementType(element: \"span\" | \"button\"): React.ElementType {\n  return element\n}\n\nconst Reaction = React.forwardRef<HTMLElement, ReactionProps>(\n  (\n    {\n      className,\n      children,\n      emoji,\n      emojiSrc,\n      emojiAlt,\n      count,\n      active: activeProp,\n      defaultActive = false,\n      onActiveChange,\n      onClick,\n      readonly = false,\n      formatLabel = defaultReactionLabel,\n      \"aria-label\": ariaLabel,\n      ...props\n    },\n    ref\n  ) => {\n    const [uncontrolled, setUncontrolled] = React.useState(defaultActive)\n    const isControlled = activeProp !== undefined\n    const active = isControlled ? activeProp : uncontrolled\n\n    const handleClick = (event: React.MouseEvent<HTMLButtonElement>) => {\n      onClick?.(event)\n      if (event.defaultPrevented) return\n      const next = !active\n      if (!isControlled) setUncontrolled(next)\n      onActiveChange?.(next)\n    }\n\n    const label =\n      ariaLabel ??\n      formatLabel({\n        emoji: emojiAlt ?? (isStringNode(emoji) ? emoji : \"Emoji\"),\n        count,\n        active,\n      })\n\n    const content = (\n      <>\n        {React.Children.toArray(children).length > 0 ? (\n          <span\n            aria-hidden=\"true\"\n            className=\"inline-flex shrink-0 items-center\"\n          >\n            {children}\n          </span>\n        ) : emojiSrc ? (\n          <img\n            src={emojiSrc}\n            alt=\"\"\n            aria-hidden=\"true\"\n            draggable={false}\n            className=\"h-4 w-4 object-contain\"\n          />\n        ) : (\n          <span aria-hidden=\"true\">{emoji}</span>\n        )}\n        <span aria-hidden=\"true\" className=\"text-xs font-semibold\">\n          {count}\n        </span>\n      </>\n    )\n\n    /*\n     * Read-only renders a `<span>`: it keeps every attribute a caller passes\n     * (`style`, `data-*`, `aria-describedby`, handlers other than `onClick`)\n     * but drops the ones only a button understands, and never toggles.\n     */\n    const Tag = asElementType(readonly ? \"span\" : \"button\")\n    const {\n      type: _type,\n      disabled: _disabled,\n      form: _form,\n      formAction: _formAction,\n      formEncType: _formEncType,\n      formMethod: _formMethod,\n      formNoValidate: _formNoValidate,\n      formTarget: _formTarget,\n      name: _name,\n      value: _value,\n      ...shared\n    } = props\n    const elementProps = readonly\n      ? { role: \"img\", ...shared }\n      : {\n          type: \"button\",\n          \"aria-pressed\": active,\n          onClick: handleClick,\n          ...props,\n        }\n\n    return (\n      <Tag\n        ref={ref}\n        aria-label={label}\n        data-state={active ? \"active\" : \"inactive\"}\n        className={cn(\n          reactionVariants({ active, interactive: !readonly }),\n          className\n        )}\n        {...elementProps}\n      >\n        {content}\n      </Tag>\n    )\n  }\n)\nReaction.displayName = \"Reaction\"\n\n/* The row of reactions under a message. */\nconst ReactionGroup = React.forwardRef<\n  HTMLDivElement,\n  React.HTMLAttributes<HTMLDivElement>\n>(({ className, ...props }, ref) => (\n  <div\n    ref={ref}\n    className={cn(\"mt-1 flex flex-wrap items-center gap-1\", className)}\n    {...props}\n  />\n))\nReactionGroup.displayName = \"ReactionGroup\"\n\nexport { Reaction, ReactionGroup, reactionVariants }\n",
      "type": "registry:ui"
    }
  ]
}