{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "reaction-bar",
  "title": "ReactionBar",
  "description": "A message's reactions: each one's emoji and how many chose it, with the person's own pressed and tinted, and quick reactions to add with a single press.",
  "registryDependencies": [
    "@ouro/badge",
    "@ouro/emoji",
    "@ouro/lib-class-name-check",
    "@ouro/lib-cn",
    "@ouro/lib-env",
    "@ouro/lib-use-dev-messages",
    "@ouro/tooltip"
  ],
  "files": [
    {
      "path": "registry/ouro/components/ouro/reaction-bar/reaction-bar.tsx",
      "content": "\"use client\";\n\nimport { useId, type HTMLAttributes, type JSX, type MouseEvent, type ReactNode, type Ref, type SVGProps } from \"react\";\nimport { Badge } from \"@/registry/ouro/components/ouro/badge/badge\";\nimport { Emoji, type EmojiCatalogue } from \"@/registry/ouro/components/ouro/emoji/emoji\";\nimport { catalogueIndex } from \"@/registry/ouro/components/ouro/emoji/emoji-styles\";\nimport { Tooltip } from \"@/registry/ouro/components/ouro/tooltip/tooltip\";\nimport { useAppearanceClassNameCheck } from \"@/registry/ouro/lib/ouro/class-name-check\";\nimport { cn } from \"@/registry/ouro/lib/ouro/cn\";\nimport { useDevWarnings, type DevWarning } from \"@/registry/ouro/lib/ouro/use-dev-messages\";\n\n/** A reaction someone can add: its key, its spoken name and what it shows. */\nexport interface ReactionOption {\n  /** Identifies the reaction (\"like\"); `onReact` receives it. */\n  key: string;\n  /** What screen readers hear for it (\"Like\"). */\n  label: string;\n  /** What it shows: an emoji (\"👍\") or an icon element. Screen readers hear `label` instead. */\n  emoji: ReactNode;\n}\n\n/** A reaction on a message, with how many people chose it. */\nexport interface Reaction extends ReactionOption {\n  /** How many people reacted this way. */\n  count: number;\n  /** The person using the app is one of them: the reaction is pressed and tinted. */\n  mine?: boolean | undefined;\n  /**\n   * Who reacted, shown in a tooltip on hover and keyboard focus, which screen readers hear as its\n   * description: \"You and Riley Example\". A tooltip never opens on touch, so keep the count\n   * meaningful without it. Without it, the tooltip shows the reaction's name.\n   *\n   * @claim \"A tooltip never opens on touch\" registry/ouro/components/ouro/tooltip/tooltip.test.tsx verify:testExists(registry/ouro/components/ouro/tooltip/tooltip.test.tsx::Tooltip > never opens after a touch on the trigger, even when the touch focuses it)\n   * @claim \"screen readers hear as its description\" registry/ouro/components/ouro/reaction-bar/reaction-bar.test.tsx verify:testExists(registry/ouro/components/ouro/reaction-bar/reaction-bar.test.tsx::ReactionBar > shows who reacted in a tooltip on hover and keyboard focus, read as the reaction's description, and after a read-only one)\n   */\n  tooltip?: string | undefined;\n}\n\n/** A reaction on a message, by the emoji it is, for a ReactionBar with a `catalogue`. */\nexport interface CatalogueReaction {\n  /** The emoji's id in the catalogue, or a tone's id (`\"thumbs-up-tone3\"`); `onReact` receives it. */\n  key: string;\n  /** How many people reacted this way. */\n  count: number;\n  /** The person using the app is one of them: the reaction is pressed and tinted. */\n  mine?: boolean | undefined;\n  /** What screen readers hear for it. @default the emoji's name in the catalogue */\n  label?: string | undefined;\n  /**\n   * Who reacted, shown in a tooltip on hover and keyboard focus, which screen readers hear as its\n   * description: \"You and Riley Example\". A tooltip never opens on touch, so keep the count\n   * meaningful without it. Without it, the tooltip shows the reaction's name.\n   *\n   * @claim \"A tooltip never opens on touch\" registry/ouro/components/ouro/tooltip/tooltip.test.tsx verify:testExists(registry/ouro/components/ouro/tooltip/tooltip.test.tsx::Tooltip > never opens after a touch on the trigger, even when the touch focuses it)\n   * @claim \"screen readers hear as its description\" registry/ouro/components/ouro/reaction-bar/reaction-bar.test.tsx verify:testExists(registry/ouro/components/ouro/reaction-bar/reaction-bar.test.tsx::ReactionBar > shows who reacted in a tooltip on hover and keyboard focus, read as the reaction's description, and after a read-only one)\n   */\n  tooltip?: string | undefined;\n  /**\n   * What it shows when the catalogue has no emoji with this id, such as an emoji the catalogue dropped. @default the id as a `:token:`\n   *\n   * @claim \"What it shows when the catalogue has no emoji\" registry/ouro/components/ouro/reaction-bar/reaction-bar.catalogue.test.tsx verify:testExists(registry/ouro/components/ouro/reaction-bar/reaction-bar.catalogue.test.tsx::ReactionBar with a catalogue > shows a reaction the catalogue lacks as the app's fallback, else as its id, and names it in development)\n   */\n  emoji?: ReactNode;\n}\n\n/** The props ReactionBar adds to the `<div>` attributes it passes through, whichever way its reactions come. */\nexport interface ReactionBarOwnProps {\n  /**\n   * The message's reactions, in the order they show: each with its own emoji, or, with\n   * `catalogue`, by emoji id.\n   *\n   * @claim \"each with its own emoji, or\" registry/ouro/components/ouro/reaction-bar/reaction-bar.test.tsx verify:testExists(registry/ouro/components/ouro/reaction-bar/reaction-bar.test.tsx::ReactionBar > shows each reaction as a toggle button named by its label and count)\n   * @claim \"each with its own emoji, or\" registry/ouro/components/ouro/reaction-bar/reaction-bar.catalogue.test.tsx verify:testExists(registry/ouro/components/ouro/reaction-bar/reaction-bar.catalogue.test.tsx::ReactionBar with a catalogue > draws each reaction and quick reaction as the catalogue's image, named by the emoji's name and count)\n   */\n  reactions: readonly Reaction[] | readonly CatalogueReaction[];\n  /**\n   * Reactions offered for a single press, after the counts: each with its own emoji, or, with\n   * `catalogue`, an emoji's id. One that is already in `reactions` shows there instead, and an\n   * id the catalogue lacks is left out. Shown only with `onReact`.\n   *\n   * @claim \"after the counts: each with its own emoji\" registry/ouro/components/ouro/reaction-bar/reaction-bar.test.tsx verify:testExists(registry/ouro/components/ouro/reaction-bar/reaction-bar.test.tsx::ReactionBar > offers quick reactions that are not there yet, and moves one to the counts once chosen)\n   * @claim \"after the counts: each with its own emoji\" registry/ouro/components/ouro/reaction-bar/reaction-bar.catalogue.test.tsx verify:testExists(registry/ouro/components/ouro/reaction-bar/reaction-bar.catalogue.test.tsx::ReactionBar with a catalogue > offers quick reactions by id that are not there yet, leaving out ids the catalogue lacks)\n   * @claim \"an id the catalogue lacks is left out\" registry/ouro/components/ouro/reaction-bar/reaction-bar.catalogue.test.tsx verify:testExists(registry/ouro/components/ouro/reaction-bar/reaction-bar.catalogue.test.tsx::ReactionBar with a catalogue > offers quick reactions by id that are not there yet, leaving out ids the catalogue lacks)\n   */\n  quick?: readonly (ReactionOption | string)[] | undefined;\n  /**\n   * An image emoji catalogue, the same as the app's `EmojiPicker`: reactions and quick\n   * reactions then go by emoji id, each showing the catalogue's image, named by the emoji's\n   * name, an animated one playing while its button is under the mouse or in focus.\n   *\n   * @claim \"each showing the catalogue's image, named\" registry/ouro/components/ouro/reaction-bar/reaction-bar.catalogue.test.tsx verify:testExists(registry/ouro/components/ouro/reaction-bar/reaction-bar.catalogue.test.tsx::ReactionBar with a catalogue > draws each reaction and quick reaction as the catalogue's image, named by the emoji's name and count)\n   * @claim \"an animated one playing while\" registry/ouro/components/ouro/reaction-bar/reaction-bar.catalogue.test.tsx verify:testExists(registry/ouro/components/ouro/reaction-bar/reaction-bar.catalogue.test.tsx::ReactionBar with a catalogue > plays an animated reaction while its button is under the mouse or in focus, and never with reduced motion)\n   */\n  catalogue?: EmojiCatalogue | undefined;\n  /**\n   * Called with a reaction's key when it is pressed, to add the person's reaction or take\n   * it back. The click event comes second, so the app can check `event.isTrusted` before\n   * it acts. Without it the reactions are read-only.\n   */\n  onReact?: ((key: string, event: MouseEvent<HTMLElement>) => void) | undefined;\n  /**\n   * Called when the \"Add reaction\" button at the end is pressed, to open the app's own\n   * reaction picker. The button shows only with `onMore`. Anchor the picker to\n   * `event.currentTarget`, and pass `moreOpen` while it is open.\n   */\n  onMore?: ((event: MouseEvent<HTMLElement>) => void) | undefined;\n  /**\n   * Whether the picker that `onMore` opens is open, so the \"Add reaction\" button says so\n   * (`aria-expanded`).\n   */\n  moreOpen?: boolean | undefined;\n  /** The \"Add reaction\" button's name and tooltip, for other languages. @default \"Add reaction\" */\n  moreLabel?: string | undefined;\n  /** Keeps the counts but turns off reacting, for example while the app is offline. */\n  disabled?: boolean | undefined;\n  /** What screen readers hear for the group, for other languages. @default \"Reactions\" */\n  label?: string | undefined;\n  /** What screen readers hear after a read-only reaction that is the person's own. @default \"including you\" */\n  mineLabel?: string | undefined;\n  /** Layout only: margins, placement (`mt-1`). Appearance classes warn in development. */\n  className?: string | undefined;\n  ref?: Ref<HTMLDivElement> | undefined;\n\n  /** Not a prop. A pressed reaction calls `onReact`: `<ReactionBar onReact={(key) => react(key)}>`. */\n  onReactionClick?: { 'Use onReact={(key) => react(key)}': never };\n  /** Not a prop. The reactions are `reactions`: `<ReactionBar reactions={message.reactions}>`. */\n  items?: { 'Use reactions={message.reactions}': never };\n  /** Not a prop. The \"Add reaction\" button calls `onMore`: `<ReactionBar onMore={openPicker}>`. */\n  onAddReaction?: { 'Use onMore={openPicker}': never };\n}\n\n/** Props for {@link ReactionBar}: its own props and the `<div>` attributes it passes through. */\nexport type ReactionBarProps = Omit<HTMLAttributes<HTMLDivElement>, keyof ReactionBarOwnProps> & ReactionBarOwnProps;\n\n/**\n * A message's reactions: each one's emoji and how many chose it, with the person's own\n * pressed and tinted, and quick reactions to add with a single press. Pressing a reaction\n * calls `onReact` with its key, so the app adds the person's reaction or takes it back.\n * Each reaction is a toggle button (`aria-pressed`) that screen readers hear by name and\n * count (\"Like, 3\"), with a tooltip of its name, or of who reacted (`tooltip`, which screen\n * readers hear as its description). Without `onReact` the reactions are read-only, and with nothing to show\n * it renders nothing. `onMore` adds an \"Add reaction\" button at the end, with a tooltip,\n * that opens the app's own picker.\n *\n * With `catalogue`, reactions go by emoji id and show the catalogue's images, as `EmojiPicker`\n * with the same catalogue chooses them.\n *\n * Place it in `Message`'s `attachments`. Use `ToggleGroup` instead for a choice between\n * options, and `Badge` for a single count.\n *\n * @group Chat\n * @see https://ui.ouroboros.bot/docs/reaction-bar\n *\n * @example\n * <ReactionBar reactions={message.reactions} quick={quickReactions} onReact={(key) => toggleReaction(message.id, key)} />\n * <ReactionBar reactions={message.reactions} onReact={react} onMore={(event) => openPicker(event.currentTarget)} moreOpen={pickerOpen} />\n * <ReactionBar catalogue={catalogue} reactions={[{ key: \"party\", count: 2, mine: true }]} quick={[\"like\", \"heart\"]} onReact={react} />\n * @claim \"reactions: each one's emoji and\" registry/ouro/components/ouro/reaction-bar/reaction-bar.test.tsx verify:testExists(registry/ouro/components/ouro/reaction-bar/reaction-bar.test.tsx::ReactionBar > shows each reaction as a toggle button named by its label and count)\n * @claim \"reactions: each one's emoji and\" registry/ouro/components/ouro/reaction-bar/reaction-bar.test.tsx verify:testExists(registry/ouro/components/ouro/reaction-bar/reaction-bar.test.tsx::ReactionBar > tints the person's own reaction)\n * @claim \"reactions: each one's emoji and\" registry/ouro/components/ouro/reaction-bar/reaction-bar.test.tsx verify:testExists(registry/ouro/components/ouro/reaction-bar/reaction-bar.test.tsx::ReactionBar > offers quick reactions that are not there yet, and moves one to the counts once chosen)\n * @claim \"Each reaction is a toggle button\" registry/ouro/components/ouro/reaction-bar/reaction-bar.test.tsx verify:testExists(registry/ouro/components/ouro/reaction-bar/reaction-bar.test.tsx::ReactionBar > shows each reaction as a toggle button named by its label and count)\n * @claim \"Without `onReact` the reactions are\" registry/ouro/components/ouro/reaction-bar/reaction-bar.test.tsx verify:testExists(registry/ouro/components/ouro/reaction-bar/reaction-bar.test.tsx::ReactionBar > is read-only without onReact, and says which reaction is yours)\n * @claim \"Without `onReact` the reactions are\" registry/ouro/components/ouro/reaction-bar/reaction-bar.test.tsx verify:testExists(registry/ouro/components/ouro/reaction-bar/reaction-bar.test.tsx::ReactionBar > renders nothing with nothing to show)\n * @claim \"`onMore` adds an\" registry/ouro/components/ouro/reaction-bar/reaction-bar.test.tsx verify:testExists(registry/ouro/components/ouro/reaction-bar/reaction-bar.test.tsx::ReactionBar > adds an Add reaction button with onMore, last, that opens the app's picker)\n */\nexport function ReactionBar(props: ReactionBarProps): JSX.Element | null {\n  const {\n    reactions,\n    quick,\n    catalogue,\n    onReact,\n    onMore,\n    moreOpen,\n    moreLabel = \"Add reaction\",\n    disabled = false,\n    label = \"Reactions\",\n    mineLabel = \"including you\",\n    className,\n    // Guard props (hint types), dropped here so they never reach the DOM.\n    onReactionClick,\n    items,\n    onAddReaction,\n    ...rest\n  } = props;\n  const id = useId();\n  const given: readonly (Reaction | CatalogueReaction)[] = reactions ?? [];\n  const shown = (catalogue ? given.map((reaction) => fromCatalogue(reaction, catalogue)) : given) as readonly Reaction[];\n  const quickOptions = (quick ?? []).flatMap((option) =>\n    typeof option !== \"string\" ? [option] : catalogue && catalogueIndex(catalogue).byId.has(option) ? [fromCatalogue({ key: option }, catalogue)] : [],\n  );\n  useAppearanceClassNameCheck(\n    \"ReactionBar\",\n    className,\n    process.env.NODE_ENV !== \"production\"\n      ? (token: string) => `remove \"${token}\"; ReactionBar takes its colors from the theme`\n      : // Stryker disable next-line StringLiteral: production only; the check never runs there.\n        /* istanbul ignore next @preserve -- production only */ \"\",\n  );\n  useDevWarnings(\n    \"ReactionBar\",\n    process.env.NODE_ENV !== \"production\"\n      ? () => [\n          reactions === undefined && [\"reactions is missing\", \"<ReactionBar reactions={message.reactions} onReact={react}>\"],\n          onReactionClick !== undefined && [\"onReactionClick is not a prop\", \"<ReactionBar onReact={(key) => react(key)}>\"],\n          items !== undefined && [\"items is not a prop\", \"<ReactionBar reactions={message.reactions}>\"],\n          onAddReaction !== undefined && [\"onAddReaction is not a prop\", \"<ReactionBar onMore={openPicker}>\"],\n          onMore === undefined && moreOpen !== undefined && [\"moreOpen needs onMore, which opens the picker\", \"<ReactionBar onMore={openPicker} moreOpen={pickerOpen}>\"],\n          onReact === undefined && quick !== undefined && [\"quick reactions need onReact, so they are hidden\", \"<ReactionBar quick={quick} onReact={react}>\"],\n          ...given\n            .filter((reaction) => (catalogue ? !catalogueIndex(catalogue).byId.has(reaction.key) : true) && reaction.emoji === undefined)\n            .map((reaction): DevWarning =>\n              catalogue\n                ? [`reaction \"${reaction.key}\" is not in the catalogue, so it shows as text`, `{ key: \"${reaction.key}\", count, emoji: <Fallback /> }`]\n                : [`reaction \"${reaction.key}\" has no emoji; pass catalogue to draw it by id`, \"<ReactionBar catalogue={catalogue} reactions={reactions}>\"],\n            ),\n          !catalogue && quick?.some((option) => typeof option === \"string\") && [\"quick reactions by id need catalogue, so they are hidden\", '<ReactionBar catalogue={catalogue} quick={[\"like\", \"heart\"]}>'],\n        ]\n      : /* istanbul ignore next @preserve -- production only */ undefined,\n  );\n\n  const offered = onReact ? quickOptions.filter((option) => !shown.some((reaction) => reaction.key === option.key)) : [];\n  if (shown.length === 0 && offered.length === 0 && !onMore) return null;\n  const buttons = (\n    <>\n      {/* One keyed list, counts then quick reactions: a quick reaction once chosen, or the last one\n          taken back, keeps its button, so keyboard focus stays on it. */}\n      {[...shown, ...offered].map((entry, index) => {\n        const reaction: Partial<Reaction> & ReactionOption = entry;\n        const described = reaction.tooltip ? `${id}-${index}` : undefined;\n        const counted = reaction.count !== undefined;\n        const look = reaction.mine ? ({ tone: \"primary\", variant: \"soft\" } as const) : counted ? ({ tone: \"secondary\", variant: \"outline\" } as const) : ({ tone: \"secondary\", variant: \"soft\" } as const);\n        // The emoji, then its name and count for screen readers, as siblings rather than fragments, so each draws no component of its own.\n        const emoji = <span aria-hidden=\"true\">{reaction.emoji}</span>;\n        const name = <span className=\"sr-only\">{counted ? `${reaction.label}, ` : reaction.label}</span>;\n        // Every pressable reaction has a tooltip, its name or who reacted, so a reaction keeps its button as one comes.\n        return onReact ? (\n          <Tooltip key={reaction.key} content={reaction.tooltip ?? reaction.label}>\n            <Badge\n              data-ouro-control=\"reaction-bar\"\n              data-ouro-part={counted ? \"reaction\" : \"quick\"}\n              {...look}\n              aria-pressed={reaction.mine === true}\n              aria-describedby={described}\n              disabled={disabled}\n              onClick={(event) => onReact(reaction.key, event)}\n            >\n              {emoji}\n              {name}\n              {counted && reaction.count}\n              {described && (\n                <span id={described} hidden>\n                  {reaction.tooltip}\n                </span>\n              )}\n            </Badge>\n          </Tooltip>\n        ) : (\n          <Badge key={reaction.key} {...look}>\n            {emoji}\n            {name}\n            {counted && reaction.count}\n            {reaction.mine && <span className=\"sr-only\">, {mineLabel}</span>}\n            {reaction.tooltip && <span className=\"sr-only\">, {reaction.tooltip}</span>}\n          </Badge>\n        );\n      })}\n      {onMore && (\n        <Tooltip content={moreLabel}>\n          <Badge\n            data-ouro-control=\"reaction-bar\"\n            data-ouro-part=\"more\"\n            tone=\"secondary\"\n            variant=\"soft\"\n            icon={AddReactionIcon}\n            aria-haspopup=\"dialog\"\n            aria-expanded={moreOpen}\n            disabled={disabled}\n            onClick={onMore}\n          >\n            <span className=\"sr-only\">{moreLabel}</span>\n          </Badge>\n        </Tooltip>\n      )}\n    </>\n  );\n  return (\n    <div {...rest} role=\"group\" aria-label={label} data-ouro=\"reaction-bar\" className={cn(\"flex min-w-0 flex-wrap items-center gap-1.5\", className)}>\n      {buttons}\n    </div>\n  );\n}\n\n/** A catalogue reaction as one with its own emoji: the catalogue's image and name, else the app's fallback or the id as a token. */\nfunction fromCatalogue(reaction: Partial<CatalogueReaction | Reaction> & { key: string }, catalogue: EmojiCatalogue): Reaction {\n  const found = catalogueIndex(catalogue).byId.get(reaction.key);\n  return {\n    ...(reaction as Reaction),\n    label: reaction.label ?? found?.item.name ?? reaction.key,\n    emoji: found ? <Emoji item={found.item} skinTone={found.tone} /> : (reaction.emoji ?? `:${reaction.key}:`),\n  };\n}\n\n/** A smiling face with a plus: add a reaction. */\nfunction AddReactionIcon(props: SVGProps<SVGSVGElement>): JSX.Element {\n  return (\n    <svg aria-hidden=\"true\" viewBox=\"0 0 24 24\" fill=\"none\" stroke=\"currentColor\" strokeWidth=\"2\" strokeLinecap=\"round\" strokeLinejoin=\"round\" {...props}>\n      <path d=\"M22 11v1a10 10 0 1 1-9-10\" />\n      <path d=\"M8 14s1.5 2 4 2 4-2 4-2\" />\n      <path d=\"M9 9h.01\" />\n      <path d=\"M15 9h.01\" />\n      <path d=\"M16 5h6\" />\n      <path d=\"M19 2v6\" />\n    </svg>\n  );\n}\n",
      "type": "registry:ui",
      "target": "@components/ouro/reaction-bar/reaction-bar.tsx"
    }
  ],
  "docs": "A message's reactions: each one's emoji and how many chose it, with the person's own pressed and tinted, and quick reactions to add with a single press. Import: import { ReactionBar } from \"@/components/ouro/reaction-bar/reaction-bar\", with @/components replaced by your components alias (aliases.components in components.json, such as ~/components). Also installed: badge, emoji, tooltip, the helpers they import in lib/ouro. Needs ouro-base in your stylesheet: add that item once per app, from the same place as this one, if you have not. Docs: https://ui.ouroboros.bot/docs/reaction-bar.md Ouro UI v1.3.257.",
  "type": "registry:ui"
}