Minor Chords
CopyButton
One-click copy with animated icon toggle — zero hook dependencies.
Overview
CopyButton wraps ActionBarPrimitive.Copy and provides a visual toggle between a copy icon and a check icon. The toggle is entirely CSS-driven using the data-copied attribute — no hooks needed.
Demo
Send a message, then hover over the assistant response to see the copy button. Click it to see the icon toggle.
<MessagePrimitive.Root>
<MessagePrimitive.Content />
<CopyButton />
</MessagePrimitive.Root><MessagePrimitive.Root>
<MessagePrimitive.Content />
<ActionBarPrimitive.Copy asChild>
<button className="group ...">
{/* Conditional icon based on copied state */}
<CopyIcon className="group-data-[copied]:hidden" />
<CheckIcon className="hidden group-data-[copied]:block" />
</button>
</ActionBarPrimitive.Copy>
</MessagePrimitive.Root>How It Works
ActionBarPrimitive.Copyhandles the clipboard API call- After copying, it sets a
data-copiedattribute on the button forcopiedDurationms CopyButtonVisualuses Tailwind'sgroup-data-[copied]variant to swap icons- No state hooks required — purely CSS-driven
Props
Prop
Type
Underlying Primitives
ActionBarPrimitive.Copy— handles clipboard anddata-copiedattribute- Must be rendered inside a message context (
MessagePrimitive.Root)