{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "emoji-reactions",
  "type": "registry:ui",
  "title": "Emoji reactions",
  "description": "A compact emoji reaction picker that swaps the emoji on your message with a short spring bounce, persistent selection, and keyboard navigation.",
  "author": "Aditya Ojha <https://akoder.xyz>",
  "categories": [
    "chat",
    "animation",
    "interactive",
    "accessibility"
  ],
  "dependencies": [
    "motion",
    "radix-ui"
  ],
  "registryDependencies": [],
  "meta": {
    "docs": "https://akoder.xyz/components/emoji-reactions",
    "source": "https://github.com/AdityaKodez/adityaojha/blob/main/components/ui/emoji-reactions.tsx"
  },
  "files": [
    {
      "path": "components/ui/emoji-reactions.tsx",
      "content": "\"use client\";\n\nimport { AnimatePresence, motion, useReducedMotion } from \"motion/react\";\nimport { Popover as PopoverPrimitive } from \"radix-ui\";\nimport { useId, useRef, useState, type KeyboardEvent } from \"react\";\n\nimport { cn } from \"@/lib/utils\";\n\nexport interface EmojiReaction {\n  /** Unique, stable identifier for this reaction. */\n  id: string;\n  /** Emoji displayed in the picker and selected badge. */\n  emoji: string;\n  /** Accessible name, such as \"Love\". */\n  label: string;\n}\n\nexport interface EmojiReactionsProps {\n  reactions?: EmojiReaction[];\n  /** Controlled selection. Null means no reaction. Pair with onValueChange. */\n  value?: string | null;\n  /** Initial selection for an uncontrolled picker. */\n  defaultValue?: string | null;\n  onValueChange?: (value: string) => void;\n  disabled?: boolean;\n  /** Extra classes on the compact trigger. */\n  className?: string;\n}\n\nconst DEFAULT_REACTIONS: EmojiReaction[] = [\n  { id: \"love\", emoji: \"❤️\", label: \"Love\" },\n  { id: \"laugh\", emoji: \"😂\", label: \"Laugh\" },\n  { id: \"fire\", emoji: \"🔥\", label: \"Fire\" },\n  { id: \"crown\", emoji: \"👑\", label: \"Crown\" },\n  { id: \"like\", emoji: \"👍\", label: \"Like\" },\n];\n\n/** A compact emoji reaction picker that animates the selection on its trigger. */\nexport function EmojiReactions({\n  reactions = DEFAULT_REACTIONS,\n  value,\n  defaultValue = null,\n  onValueChange,\n  disabled = false,\n  className,\n}: EmojiReactionsProps) {\n  const [internalValue, setInternalValue] = useState(defaultValue);\n  const [open, setOpen] = useState(false);\n  const [focusedId, setFocusedId] = useState<string | null>(null);\n  const [keyboardSelection, setKeyboardSelection] = useState(false);\n  const buttons = useRef<Array<HTMLButtonElement | null>>([]);\n  const reduceMotion = useReducedMotion();\n  const instanceId = useId();\n  const selectedId = value === undefined ? internalValue : value;\n  const ids = new Set<string>();\n\n  for (const reaction of reactions) {\n    if (!reaction.id.trim() || ids.has(reaction.id) || typeof reaction.emoji !== \"string\" || !reaction.emoji.trim() || !reaction.label.trim()) {\n      throw new Error(\"EmojiReactions requires unique, non-empty ids, non-empty emoji strings, and non-empty labels.\");\n    }\n    ids.add(reaction.id);\n  }\n  if (selectedId !== null && !ids.has(selectedId)) {\n    throw new Error(`EmojiReactions value \"${selectedId}\" does not match a reaction id.`);\n  }\n\n  const selected = reactions.find((reaction) => reaction.id === selectedId);\n  const unavailable = disabled || reactions.length === 0 || (value !== undefined && !onValueChange);\n  // Disabling an open picker closes it without reopening when enabled again.\n  if (unavailable && open) setOpen(false);\n  const isOpen = open && !unavailable;\n  const tabbableId = focusedId && ids.has(focusedId) ? focusedId : selectedId ?? reactions[0]?.id;\n  const still = reduceMotion || keyboardSelection;\n  const selectionTransition = still\n    ? { duration: reduceMotion ? 0.1 : 0 }\n    : { type: \"spring\" as const, duration: 0.28, bounce: 0.25 };\n\n  function selectReaction(id: string, keyboard: boolean) {\n    if (unavailable || id === selectedId) return;\n    setKeyboardSelection(keyboard);\n    if (value === undefined) setInternalValue(id);\n    onValueChange?.(id);\n  }\n\n  function moveFocus(event: KeyboardEvent<HTMLButtonElement>, index: number) {\n    let next: number;\n    switch (event.key) {\n      case \"Tab\":\n        event.preventDefault();\n        setOpen(false);\n        return;\n      case \"ArrowRight\":\n      case \"ArrowDown\":\n        next = (index + 1) % reactions.length;\n        break;\n      case \"ArrowLeft\":\n      case \"ArrowUp\":\n        next = (index - 1 + reactions.length) % reactions.length;\n        break;\n      case \"Home\":\n        next = 0;\n        break;\n      case \"End\":\n        next = reactions.length - 1;\n        break;\n      default:\n        return;\n    }\n    event.preventDefault();\n    buttons.current[next]?.focus();\n  }\n\n  return (\n    <PopoverPrimitive.Root open={isOpen} onOpenChange={setOpen}>\n      <PopoverPrimitive.Trigger asChild>\n        <motion.button\n          type=\"button\"\n          disabled={unavailable}\n          aria-label={selected ? `Change reaction, ${selected.label} selected` : \"Add reaction\"}\n          whileTap={reduceMotion || unavailable ? undefined : { scale: 0.97 }}\n          className={cn(\n            \"relative inline-flex size-9 shrink-0 cursor-pointer items-center justify-center rounded-full bg-background p-2 text-muted-foreground shadow-xs ring-1 ring-inset ring-border outline-none transition-colors hover:bg-muted focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-ring disabled:cursor-not-allowed disabled:opacity-50\",\n            selected && \"text-primary\",\n            className,\n          )}\n        >\n          <AnimatePresence initial={false}>\n            <motion.span\n              key={selectedId ?? \"empty\"}\n              aria-hidden=\"true\"\n              initial={{ opacity: 0, y: still ? 0 : 6, scale: still ? 1 : 0.95, rotate: still ? 0 : -10 }}\n              animate={{ opacity: 1, y: 0, scale: 1, rotate: 0 }}\n              exit={{ opacity: 0, transition: { duration: still ? 0 : 0.08 } }}\n              transition={{ ...selectionTransition, opacity: { duration: still && !reduceMotion ? 0 : 0.1 } }}\n              className=\"pointer-events-none absolute inset-0 flex items-center justify-center text-xl leading-none\"\n            >\n              {selected?.emoji ?? \"🙂\"}\n            </motion.span>\n          </AnimatePresence>\n        </motion.button>\n      </PopoverPrimitive.Trigger>\n\n      <PopoverPrimitive.Portal forceMount>\n        <AnimatePresence>\n          {isOpen && (\n            <PopoverPrimitive.Content\n              key=\"picker\"\n              forceMount\n              asChild\n              side=\"bottom\"\n              align=\"end\"\n              sideOffset={8}\n              collisionPadding={12}\n              aria-label=\"Choose a reaction\"\n              onOpenAutoFocus={(event) => {\n                event.preventDefault();\n                const index = Math.max(0, reactions.findIndex((reaction) => reaction.id === selectedId));\n                buttons.current[index]?.focus();\n              }}\n            >\n              <motion.div\n                initial={{ opacity: 0, y: reduceMotion ? 0 : -6, scale: reduceMotion ? 1 : 0.95 }}\n                animate={{ opacity: 1, y: 0, scale: 1 }}\n                exit={{ opacity: 0, y: reduceMotion ? 0 : -4, scale: reduceMotion ? 1 : 0.95, transition: { duration: reduceMotion ? 0.1 : 0.12 } }}\n                transition={{ duration: reduceMotion ? 0.1 : 0.18, ease: [0.23, 1, 0.32, 1] }}\n                className=\"z-50 max-w-[min(20rem,var(--radix-popover-content-available-width))] origin-(--radix-popover-content-transform-origin) outline-none data-[state=closed]:pointer-events-none\"\n              >\n                <div role=\"toolbar\" aria-label=\"Reactions\" className=\"flex flex-wrap justify-center gap-1 rounded-3xl bg-popover p-1.5 text-popover-foreground shadow-lg ring-1 ring-inset ring-border\">\n                  {reactions.map((reaction, index) => (\n                    <motion.button\n                      key={reaction.id}\n                      ref={(button) => { buttons.current[index] = button; }}\n                      type=\"button\"\n                      aria-label={reaction.label}\n                      aria-pressed={selectedId === reaction.id}\n                      tabIndex={reaction.id === tabbableId ? 0 : -1}\n                      onFocus={() => setFocusedId(reaction.id)}\n                      onKeyDown={(event) => moveFocus(event, index)}\n                      onClick={(event) => selectReaction(reaction.id, event.detail === 0)}\n                      whileTap={reduceMotion ? undefined : { scale: 0.97 }}\n                      className={cn(\n                        \"relative flex size-9 cursor-pointer items-center justify-center rounded-full text-muted-foreground outline-none transition-colors hover:bg-muted hover:text-foreground focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-ring\",\n                        selectedId === reaction.id && \"text-primary hover:text-primary\",\n                      )}\n                    >\n                      {selectedId === reaction.id && (\n                        <motion.span\n                          layoutId={`${instanceId}-reaction`}\n                          initial={false}\n                          transition={selectionTransition}\n                          className=\"pointer-events-none absolute inset-0 rounded-full bg-muted\"\n                        />\n                      )}\n                      <span aria-hidden=\"true\" className=\"relative text-xl leading-none\">{reaction.emoji}</span>\n                    </motion.button>\n                  ))}\n                </div>\n                <PopoverPrimitive.Arrow width={10} height={5} className=\"fill-popover\" />\n                <span role=\"status\" className=\"sr-only\">{selected ? `${selected.label} selected` : \"No reaction selected\"}</span>\n              </motion.div>\n            </PopoverPrimitive.Content>\n          )}\n        </AnimatePresence>\n      </PopoverPrimitive.Portal>\n    </PopoverPrimitive.Root>\n  );\n}\n",
      "type": "registry:ui"
    }
  ],
  "docs": "## Installation\n\n```bash\nnpx shadcn add @akoder/emoji-reactions\n```\n\n## Usage\n\n```tsx\nimport { EmojiReactions } from \"@/components/ui/emoji-reactions\";\n\nexport function Message() {\n  return (\n    <div className=\"relative max-w-72 rounded-2xl bg-muted p-4\">\n      <p>A little bounce makes everything better.</p>\n      <EmojiReactions className=\"absolute -bottom-4 right-3\" />\n    </div>\n  );\n}\n```\n\nClick the trigger to open the reaction picker. Selection swaps the reaction on the message badge with a short spring bounce while the compact picker stays open below it. Use value and onValueChange for controlled state, or defaultValue for local state. Custom reactions require unique ids, non-empty emoji strings, and accessible labels. Arrow keys move focus; Enter or Space selects; Escape dismisses. Reduced motion uses brief fades. See https://akoder.xyz/components/emoji-reactions for the full props reference."
}