Reactions
Emoji counts under a message that you press to add or take back your own.
Installation
npx shadcn@latest add "@aiellie/reactions"shadcn needs the @aiellie registry in components.json first. npx aiellie add reactions adds it on its first run, then installs the same way.
Reactions shows the emoji a message has collected, each with its count. Pressing one adds yours, and pressing it again takes it back. The ones you gave are tinted, so you can find them in a long row, and a tooltip says who reacted.
toggleReaction returns the list with an emoji added or taken back, which is the update every app writes once a row is wired up.
Getting started
Keep the list
components/message-reactions.tsx"use client" import * as React from "react" import { Reactions, toggleReaction, type Reaction, } from "@/components/aiellie/reactions" export function MessageReactionsRow({ initial }: { initial: Reaction[] }) { const [reactions, setReactions] = React.useState(initial) return ( <Reactions reactions={reactions} onToggle={(emoji) => setReactions((list) => toggleReaction(list, emoji))} /> ) }Offer more
onAddputs a button at the end. Open your emoji picker from it.components/message-reactions.tsx<Reactions reactions={reactions} onToggle={toggle} onAdd={openPicker} />
Anatomy
<div data-slot="reactions" role="group">
<button data-slot="reaction" data-reacted aria-pressed /> {/* emoji and count */}
<button data-slot="reactions-add" />
</div>Each reaction is a toggle button, so screen readers hear whether it's yours. A reaction that drops to zero leaves the row.
It sits under a message, or inside MessageReactions to hang off the bubble's corner.
Examples
Who reacted
Give people and the tooltip names them, with you first.
API reference
Reactions
| Prop | Type | Default | Description |
|---|---|---|---|
reactions | Reaction[] | required | |
onToggle | (emoji: string) => void | Called when one is pressed. | |
onAdd | () => void | Adds a button for a new one. |
All other div props are forwarded.
Reaction
| Field | Type | Default | Description |
|---|---|---|---|
emoji | string | required | |
count | number | required | |
reacted | boolean | Whether you are one of the count. | |
people | string[] | Who else reacted. |