UnflowUI
Components

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

PropTypeDefaultDescription
reactionsReaction[]—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
disabledboolean—Disables every pill and the add button
maxNamesnumber10Names listed in a pill's tooltip before "and N more"

Reaction

FieldTypeDescription
emojistringRequired. The unicode emoji
countnumberRequired. How many people reacted
reactedByMebooleanMarks the person's own reaction: accent colors and aria-pressed
peoplestring[]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-pressed set 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.