ReactionBar
Emoji reaction pills with counts, a tooltip of who reacted and an add button.
Overview
ReactionBar shows the reactions on a message or comment as pills with their counts. The person's own reactions use the accent, and hovering or focusing a pill lists who reacted.
It is stateless: pressing a pill calls onToggle, and the add button calls onAdd with itself so you can anchor an EmojiPicker to it. Your app updates reactions.
Import
import { ReactionBar } from '@unflowio/ui/components/ReactionBar';Props
| Prop | Type | Default | Description |
|---|---|---|---|
reactions | Reaction[] | — | Required. The reactions to show, in order |
onToggle | (emoji: string) => void | — | Required. Called when a pill is pressed. The app adds or removes the person's reaction |
onAdd | (anchor: HTMLButtonElement) => void | — | Called by the add button with that button, to anchor an EmojiPicker. The button is hidden when this is unset |
disabled | boolean | — | Disables every pill and the add button |
maxNames | number | 10 | Names listed in a pill's tooltip before "and N more" |
Reaction
| Field | Type | Description |
|---|---|---|
emoji | string | Required. The unicode emoji |
count | number | Required. How many people reacted |
reactedByMe | boolean | Marks the person's own reaction: accent colors and aria-pressed |
people | string[] | Names shown in the tooltip, in display order. May hold fewer names than count |
Basic usage
const [reactions, setReactions] = useState<Reaction[]>(initial);
const [anchor, setAnchor] = useState<HTMLButtonElement | null>(null);
<ReactionBar
reactions={reactions}
onToggle={(emoji) => setReactions((list) => toggle(list, emoji))}
onAdd={setAnchor}
/>
<EmojiPicker
open={!!anchor}
anchorEl={anchor}
onOpenChange={(open) => !open && setAnchor(null)}
onSelect={(emoji) => setReactions((list) => toggle(list, emoji))}
/>toggle is your own update: increment and add the person when they haven't reacted with that emoji, decrement and remove them when they have, and append a new reaction for an emoji that isn't in the list yet. See the preview's source for a full version.
Who reacted
The tooltip lists people up to maxNames, then "and N more". N counts everyone in count who isn't listed, so you can send only the first few names for a busy reaction.
<ReactionBar reactions={reactions} onToggle={toggle} maxNames={5} />
<ReactionBar reactions={reactions} onToggle={toggle} onAdd={openPicker} disabled />Accessibility
- The bar is a group named "Reactions".
- Each pill is a toggle button named by its emoji and count (e.g. "👍, 2 reactions"), with
aria-pressedset for the person's own reactions. It works with Enter and Space. - The add button is named "Add reaction".
- The list of who reacted is shown on hover and on keyboard focus.
- All labels are translated, with plural forms.
Distribution
Shows where the middle (p50 to p75) and the tail (p75 to p90) of a distribution sit, one row per series on a shared scale.
Dropdown
A floating container positioned relative to an anchor element. The low-level primitive underlying ActionsDropdown — use when you need custom dropdown content.