本文へ移動
日本語
「リアクションピッカー」は Pro に含まれます。解除するとプレビューが表示されます。

仕組み

A wrapping row of soft chips (yours tinted with the accent and ringed) plus a round smiley trigger that turns ink while open. The tray is positioned above the row and lined up with its start, so nothing moves and it stays inside: it scales out of the trigger with a spring and its reactions pop in 32ms apart, outward from the one nearest the trigger. Under the pointer a reaction grows to 1.42 and lifts 7px while its neighbours lean 5px aside (transforms only, through :has()). Picking copies the emoji into an absolutely positioned flight that rises 120px along an arc with a little drift and spin and fades out over 900ms, while the tray closes; the chip then pops in, or its count rolls: the old number leaves through a clipped window as the new one arrives.

向いている場面

  • Light responses to messages, comments, updates and photos, where a reply would be too much.
  • Team feeds and threads where people acknowledge, agree or celebrate without adding noise.
  • Any list of posts that shows how others responded at a glance.

向かない場面

  • Ratings that are averaged or ranked: use rating stars.
  • A single like with a count: the like button is simpler.
  • Formal approval or votes that need a record of who decided what.

使い方

import { useState } from 'react'
import { ReactionPicker } from './ReactionPicker.jsx'

const reactions = [
  { id: 'up', emoji: '👍', label: 'Thumbs up' },
  { id: 'party', emoji: '🎉', label: 'Celebrate' },
  { id: 'eyes', emoji: '👀', label: 'Looking' },
]

export function MessageReactions({ message }) {
  // Your own reaction; counts hold everybody else's
  const [mine, setMine] = useState(message.myReaction ?? null)
  return (
    <ReactionPicker
      reactions={reactions}
      counts={message.otherReactions} // e.g. { up: 3, party: 2 }
      value={mine}
      onChange={(id) => {
        setMine(id)
        saveReaction(message.id, id)
      }}
    />
  )
}

プロパティ

プロパティ型既定値説明
reactions{ id, emoji, label }[]six everyday reactionsThe reactions in the tray, in order. label names each one for screen readers and tooltips.
countsRecord<id, number>{}How many other people chose each reaction. A chip shows counts[id], plus one when it is yours; reactions at zero have no chip.
value / defaultValue / onChangestring | null / string | null / (id | null) => void- / null / -Your own reaction (one per person), controlled or not. Picking it again, or pressing its chip, sets null.
launchbooleantrueLaunch a copy of the picked reaction up and away along an arc.
align'start' | 'end''start'Which end of the row the tray lines up with, so it stays inside the row; use end when the row sits at the right edge.
labelsobject—Replaces built-in text: add (trigger name), tray (menu name), chip(label, count, mine). Shallow-merged over the English defaults.
...restHTMLAttributes—Other attributes go to the root <div>.

アクセシビリティ

  • The trigger is a <button> with aria-haspopup, aria-expanded and aria-controls; the tray is a menu of menuitemradio buttons with aria-checked on yours.
  • Arrow keys, Home and End move through the tray with a roving tabindex, Enter or Space picks, Escape closes and returns focus to the trigger; opening from the keyboard focuses the current reaction.
  • Each chip is a toggle button (aria-pressed) whose name says the reaction, its count and whether it includes you.
  • Emoji are hidden from screen readers; the label of each reaction is read instead, and shown as a tooltip.
  • On touch screens the trigger, chips and reactions grow to 36–44px.
  • Reduced motion fades the tray in place and drops the stagger, swell, lean, flight and rolling count.

モーション

Tray: scale 0.5 → 1 with a spring over 360ms from the trigger corner; reactions pop over 420ms, 32ms apart. Swell: 260ms spring. Flight: 900ms, rising 120px with drift and spin, fading out. Chip: pops in over 360ms after 220ms; counts roll over 360ms ease-out. Closing: 160ms ease-in.

プロジェクトに追加

Pro メンバーはプロンプトをコピーし、コーディングエージェントが無料コンポーネントと同じ手順でソースを導入します。

ReactionPicker.jsxreaction-picker.csstokens.cssREADME.md

2 つのファイルを一緒に導入します。スタイルは tokens.css の変数を読み、予備の値も持つため、単体でも表示できます。

ボタン
「オーロラ縁ボタン」は Pro に含まれます。解除するとプレビューが表示されます。
「かじりボタン」は Pro に含まれます。解除するとプレビューが表示されます。