reactionSync
Makes every ReactionBar on the page answer at once.
import { reactionSync } from "@sdxc/ui/chat";View code
// One host anywhere on the page carries reactionSync(); every ReactionBar then answers at once.
<span hidden mix={[reactionSync()]} />
<ReactionBar aria-label="Reactions">
<form method="post" action="/messages/42/reactions">
<input type="hidden" name="emoji" value="🎉" />
<ReactionBar.Reaction emoji="🎉" label="Party popper" count={4} pressed title="You, Mira, Theo and Kenji" />
</form>
<form method="post" action="/messages/42/reactions">
<input type="hidden" name="emoji" value="👀" />
<ReactionBar.Reaction emoji="👀" label="Eyes" count={1} title="Theo" />
</form>
<form method="post" action="/messages/42/reactions">
<input type="hidden" name="emoji" value="🚀" />
<ReactionBar.Reaction emoji="🚀" label="Rocket" count={2} title="Mira and Priya" />
</form>
</ReactionBar>Usage
Put on one element that stays on the page, such as an island's host: from then on every
reaction chip under document flips at once and posts in the background, and
ui:reaction-add events add reactions in place. Submits are claimed in the capture phase,
before any navigation handler sees them.
Signature
reactionSync(): MixinDescriptor<HTMLElement>Returns a mixin with no visible effect on its host.
Examples
<span hidden mix={[reactionSync()]} />Used with it
The events, constants and types its module publishes, each imported from @sdxc/ui/chat too.
ReactionAddEvent
Dispatched on a ReactionBar (or any element inside the message holding one) to add the
reader's reaction: an existing chip is pressed, a missing one is cloned from the row's
ReactionBar.Template, and either posts through its form.
new ReactionAddEvent(detail: ReactionAddDetail)| Property | Type | Required | Description |
|---|---|---|---|
detail | readonly ReactionAddDetail | Yes |
REACTION_ADD_EVENT
DOM event type that asks a ReactionBar to add, or press, a reaction.
const REACTION_ADD_EVENT = "ui:reaction-add" as constReactionAddDetail
What a ReactionAddEvent asks for.
| Member | Type | Required | Description |
|---|---|---|---|
emoji | string | Yes | The emoji as the chip's form submits it: a character, or a custom's :shortcode:. |
label | string | Yes | What the emoji is called, for the chip's accessible name. |
image | string | No | A custom emoji's image. |
toggle | boolean | No | Takes the reader's reaction off when they already reacted with this emoji. |