Reactions

Emoji reactions under a message, with a picker to add one.

Mira Patel · 10:14 AM

Invoices v2 is live for every EU workspace. VAT shows once now.

Installation

pnpm dlx shadcn@latest add checkfu/uicontext/reactions

Usage

import { Reactions } from "./ui/uicontext/components/kit/Reactions.ts"import type { Reaction } from "./ui/uicontext/components/kit/Reactions.ts"
const Message = UiSchema.TaggedEnum({	ToggledReaction: { emoji: Schema.String, on: Schema.Boolean },	ToggledPicker: { open: Schema.Boolean },})// update with `toggleReaction(reactions, emoji, on, me)`, then send it to your serverexport const MessageReactions = (h: Html.H<typeof Message.Type>, reactions: ReadonlyArray<Reaction>, pickerOpen: boolean) =>	Reactions(h, {		reactions,		onToggle: (emoji, on) => Message.ToggledReaction({ emoji, on }),		picker: { id: "message-42-reactions", open: pickerOpen, onToggle: (open) => Message.ToggledPicker({ open }) },	})

Examples

Read-only

Without react in can, the chips still say who reacted, but can't be pressed, and there's no picker.

Omar Haddad · Nov 14 · archived

The Lisbon office closes for the holidays from December 23 to January 2.

API reference

ReactionChipsView function

Options

ReactionChips options
NameTypeDescription
reactionsrequiredReaction[]Each emoji with its count, who reacted, and whether the reader did
chiprequired(button: ButtonBuilder<Message>, emoji: string, on: boolean) => ButtonBuilder<Message>Binds each chip's press: gets the button, the emoji, and whether pressing adds the reader's reaction
disabledbooleanShows the chips without letting the reader press them

ReactionGridView function

Options

ReactionGrid options
NameTypeDescription
minestring[]What the reader has already reacted with, shown chosen
choicesstring[]The emoji to offer; a common set by default
choicerequired(button: ButtonBuilder<Message>, emoji: string, on: boolean) => ButtonBuilder<Message>Binds each emoji's press: gets the button, the emoji, and whether pressing adds it

ReactionPickerView function

Options

ReactionPicker options
NameTypeDescription
idrequiredstringUnique on the page: the popover's id
openrequiredbooleanWhether the grid shows
onTogglerequired(open: boolean) => MessageThe browser opened or closed it (its button, Escape, a click outside)
onPickrequired(emoji: string, on: boolean) => MessageThe reader picked an emoji: add theirs, or take it back if it's already theirs
minestring[]What the reader has already reacted with, shown chosen
choicesstring[]The emoji to offer; a common set by default

ReactionsView function

Options

Reactions options
NameTypeDescription
reactionsrequiredReaction[]Each emoji with its count, who reacted, and whether the reader did
onTogglerequired(emoji: string, on: boolean) => MessageThe reader pressed a chip: on adds theirs, false takes it back
pickerOmit<ReactionPickerOptions<Message>, "onPick" | "mine">A picker after the chips, to add a new one
canReadonlyArray<"react">"react" when the reader may react; read-only chips without it

Accessibility

  • Each reaction is a toggle button (aria-pressed) that says the emoji, the count and who reacted, including you.
  • Add a reaction opens a grid of emoji buttons in a popover that closes with Escape; emoji you've already used are marked pressed.

Source