aiellie

Search

Find a component, template or page

GitHub
Components

Reactions

Emoji counts under a message that you press to add or take back your own.

The release notes are up. Have a look before Friday.
Open full screen
fig. 01 · open it full screen from the corner

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

  1. 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))}
        />
      )
    }
  2. Offer more

    onAdd puts 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

PropTypeDefaultDescription
reactionsReaction[]required
onToggle(emoji: string) => voidCalled when one is pressed.
onAdd() => voidAdds a button for a new one.

All other div props are forwarded.

Reaction

FieldTypeDefaultDescription
emojistringrequired
countnumberrequired
reactedbooleanWhether you are one of the count.
peoplestring[]Who else reacted.