{"version":3,"file":"ReactionSelectorWithButton.mjs","names":[],"sources":["../../../../src/components/Reactions/ReactionSelectorWithButton.tsx"],"sourcesContent":["import type { ComponentRef } from 'react';\nimport React, { useRef } from 'react';\nimport { ReactionSelector as DefaultReactionSelector } from './ReactionSelector';\nimport { DialogAnchor, useDialogIsOpen, useDialogOnNearestManager } from '../Dialog';\nimport {\n  useComponentContext,\n  useComponentContextIcons,\n  useMessageContext,\n  useTranslationContext,\n} from '../../context';\n\nimport type { IconProps } from '../../types/types';\nimport { QuickMessageActionsButton } from '../MessageActions';\n\ntype ReactionSelectorWithButtonProps = {\n  /** Icon of the button that opens the selector. Defaults to the `icons.IconEmoji` slot. */\n  ReactionIcon?: React.ComponentType<IconProps>;\n};\n\n/** Button that toggles the reaction selector dialog, with its anchor. Not a package export. */\nexport const ReactionSelectorWithButton = ({\n  ReactionIcon,\n}: ReactionSelectorWithButtonProps) => {\n  const { t } = useTranslationContext();\n  const { isMyMessage, message } = useMessageContext();\n  const { ReactionSelector = DefaultReactionSelector } = useComponentContext();\n  const { IconEmoji } = useComponentContextIcons();\n  // The prop wins: it targets one message's button, while the icon slot applies to all of them.\n  const ResolvedReactionIcon = ReactionIcon ?? IconEmoji;\n  const buttonRef = useRef<ComponentRef<'button'>>(null);\n  // Must equal the ID `MessageActions` derives from `ReactionSelector.getDialogId`: it keeps\n  // `.str-chat__message-options--active` applied while the dialog is open. A mismatch hides the\n  // button when focus moves into the portal, collapsing the popover's reference element.\n  const dialogId = DefaultReactionSelector.getDialogId({ messageId: message.id });\n  const { dialog, dialogManager } = useDialogOnNearestManager({ id: dialogId });\n  const dialogIsOpen = useDialogIsOpen(dialogId, dialogManager?.id);\n\n  return (\n    <>\n      <DialogAnchor\n        dialogManagerId={dialogManager?.id}\n        id={dialogId}\n        offset={8}\n        placement={isMyMessage() ? 'top-end' : 'top-start'}\n        referenceElement={buttonRef.current}\n        trapFocus\n        updatePositionOnContentResize\n      >\n        <ReactionSelector />\n      </DialogAnchor>\n      <QuickMessageActionsButton\n        aria-expanded={dialogIsOpen}\n        aria-label={t('common.openReactionSelector.ariaLabel', 'Open Reaction Selector')}\n        className='str-chat__message-reactions-button'\n        data-testid='message-reaction-action'\n        onClick={() => dialog?.toggle()}\n        ref={buttonRef}\n      >\n        <ResolvedReactionIcon className='str-chat__message-action-icon' />\n      </QuickMessageActionsButton>\n    </>\n  );\n};\n"],"mappings":";;;;;;;;;;;;AAoBA,IAAa,8BAA8B,EACzC,mBACqC;CACrC,MAAM,EAAE,MAAM,sBAAsB;CACpC,MAAM,EAAE,aAAa,YAAY,kBAAkB;CACnD,MAAM,EAAE,kBAAA,qBAAmB,qBAA4B,oBAAoB;CAC3E,MAAM,EAAE,cAAc,yBAAyB;CAE/C,MAAM,uBAAuB,gBAAgB;CAC7C,MAAM,YAAY,OAA+B,IAAI;CAIrD,MAAM,WAAW,iBAAwB,YAAY,EAAE,WAAW,QAAQ,GAAG,CAAC;CAC9E,MAAM,EAAE,QAAQ,kBAAkB,0BAA0B,EAAE,IAAI,SAAS,CAAC;CAC5E,MAAM,eAAe,gBAAgB,UAAU,eAAe,EAAE;CAEhE,OACE,qBAAA,YAAA,EAAA,UAAA,CACE,oBAAC,cAAD;EACE,iBAAiB,eAAe;EAChC,IAAI;EACJ,QAAQ;EACR,WAAW,YAAY,IAAI,YAAY;EACvC,kBAAkB,UAAU;EAC5B,WAAA;EACA,+BAAA;YAEA,oBAAC,oBAAD,CAAmB,CAAA;CACP,CAAA,GACd,oBAAC,2BAAD;EACE,iBAAe;EACf,cAAY,EAAE,yCAAyC,wBAAwB;EAC/E,WAAU;EACV,eAAY;EACZ,eAAe,QAAQ,OAAO;EAC9B,KAAK;YAEL,oBAAC,sBAAD,EAAsB,WAAU,gCAAiC,CAAA;CACxC,CAAA,CAC3B,EAAA,CAAA;AAEN"}