Reaction burst button
A like button that pops with a ring of confetti sparks while the count rolls up a digit, and quietly rolls back when you undo.
"use client";
import { useState, type CSSProperties } from "react";
import "./reaction-button.css";
type ReactionButtonProps = {
count: number;
label?: string;
initiallyLiked?: boolean;
theme?: "light" | "dark";
};
const SPARKS = 10;
/**
* ReactionButton
* - Toggling on: the heart pops, 10 sparks fly out in a ring, the count rolls up.
* - Toggling off: the count rolls down, no fireworks.
* - Each digit is its own little column so only the digits that change roll.
*/
export function ReactionButton({
count,
label = "Like",
initiallyLiked = false,
theme = "light",
}: ReactionButtonProps) {
const [liked, setLiked] = useState(initiallyLiked);
const [burst, setBurst] = useState(0); // a new key replays the spark animation
const total = count + (liked ? 1 : 0) - (initiallyLiked ? 1 : 0);
return (
<button
type="button"
className="gu-react"
data-theme={theme}
data-liked={liked || undefined}
aria-pressed={liked}
aria-label={`${label}, ${total.toLocaleString()}`}
onClick={() => {
setLiked((l) => !l);
if (!liked) setBurst((b) => b + 1);
}}
>
<span className="gu-react__icon" aria-hidden="true">
<svg viewBox="0 0 24 24">
<path d="M12 20s-7-4.4-7-10a4 4 0 0 1 7-2.6A4 4 0 0 1 19 10c0 5.6-7 10-7 10z" />
</svg>
{burst > 0 && (
<span key={burst} className="gu-react__sparks">
{Array.from({ length: SPARKS }, (_, i) => (
<i
key={i}
style={{ "--a": `${(360 / SPARKS) * i}deg` } as CSSProperties}
/>
))}
</span>
)}
</span>
<span className="gu-react__count" aria-hidden="true">
{String(total)
.split("")
.map((d, i, arr) => (
// Key by position from the right, so the ones digit stays the ones digit.
<span key={arr.length - i} className="gu-react__digit">
<span style={{ transform: `translateY(${-Number(d) * 10}%)` }}>
{"0123456789".split("").map((n) => (
<span key={n}>{n}</span>
))}
</span>
</span>
))}
</span>
</button>
);
}
Paste this into ChatGPT, Claude, Cursor, v0, Lovable or Bolt. It describes the layout, motion, colors and accessibility and includes the code, so the AI can rebuild it in any framework.
# Build this UI piece: Reaction burst button
You are a senior front-end engineer. Recreate the piece below in my project. If I don't say which framework I use, ask once, then build it in that framework (React, Vue, Svelte, Angular, Astro, plain HTML/CSS/JS or anything else). Keep the behavior, motion, colors, spacing and accessibility exactly as described. Keep the code clean and commented for beginners.
## What it is
A pill-shaped like button with a heart and a counter. Liking pops the heart, fires a ring of 10 confetti sparks and rolls the changed digits up like an odometer. Unliking rolls back without sparks.
## Layout and look
- Pill 52px tall, 1.5px border, background #fbf8f2 (dark #1f1f23), 17px weight 800 tabular numbers.
- Heart: 26px outline. Liked: filled orange #ff5a1f, the pill border turns orange and the background gets a 12% orange tint.
- Sparks: alternating 6px orange and 4px lime (#d7ff3a) rounded squares.
## Behavior and motion
1. On like: heart scales 0.6 → 1.3 → 1 with an overshoot spring (550ms). Sparks start 6px from the center and fly to 30px along 10 evenly spaced angles while shrinking to 0 (700ms). Replaying uses a new key.
2. Each digit is a hidden-overflow 1em window over a column 0-9, translated by -digit × 10%, transition 500ms spring. Key digits by their position from the right so only changed ones move.
3. Pressing scales the pill to 0.95.
## Touch
Tap-only interaction; nothing depends on hover.
## Accessibility
- <button aria-pressed> with an aria-label that includes the total count; the visual digits are aria-hidden.
- prefers-reduced-motion: no sparks, no pop, digits swap instantly.
## Props
count, label, initiallyLiked, theme.
## Reference implementation
The original is written in React with one plain CSS file. Dependencies: none (plain React and CSS). Translate it faithfully; do not add new libraries unless my framework needs them.
### ReactionButton.tsx
```tsx
"use client";
import { useState, type CSSProperties } from "react";
import "./reaction-button.css";
type ReactionButtonProps = {
count: number;
label?: string;
initiallyLiked?: boolean;
theme?: "light" | "dark";
};
const SPARKS = 10;
/**
* ReactionButton
* - Toggling on: the heart pops, 10 sparks fly out in a ring, the count rolls up.
* - Toggling off: the count rolls down, no fireworks.
* - Each digit is its own little column so only the digits that change roll.
*/
export function ReactionButton({
count,
label = "Like",
initiallyLiked = false,
theme = "light",
}: ReactionButtonProps) {
const [liked, setLiked] = useState(initiallyLiked);
const [burst, setBurst] = useState(0); // a new key replays the spark animation
const total = count + (liked ? 1 : 0) - (initiallyLiked ? 1 : 0);
return (
<button
type="button"
className="gu-react"
data-theme={theme}
data-liked={liked || undefined}
aria-pressed={liked}
aria-label={`${label}, ${total.toLocaleString()}`}
onClick={() => {
setLiked((l) => !l);
if (!liked) setBurst((b) => b + 1);
}}
>
<span className="gu-react__icon" aria-hidden="true">
<svg viewBox="0 0 24 24">
<path d="M12 20s-7-4.4-7-10a4 4 0 0 1 7-2.6A4 4 0 0 1 19 10c0 5.6-7 10-7 10z" />
</svg>
{burst > 0 && (
<span key={burst} className="gu-react__sparks">
{Array.from({ length: SPARKS }, (_, i) => (
<i
key={i}
style={{ "--a": `${(360 / SPARKS) * i}deg` } as CSSProperties}
/>
))}
</span>
)}
</span>
<span className="gu-react__count" aria-hidden="true">
{String(total)
.split("")
.map((d, i, arr) => (
// Key by position from the right, so the ones digit stays the ones digit.
<span key={arr.length - i} className="gu-react__digit">
<span style={{ transform: `translateY(${-Number(d) * 10}%)` }}>
{"0123456789".split("").map((n) => (
<span key={n}>{n}</span>
))}
</span>
</span>
))}
</span>
</button>
);
}
```
### reaction-button.css
```css
/* ReactionButton: change these colors to match your brand. */
.gu-react {
--idle: #fbf8f2;
--text: #0e0e10;
--line: rgb(14 14 16 / 0.14);
--heart: #ff5a1f; /* liked heart + pill tint */
--spark-a: #ff5a1f;
--spark-b: #d7ff3a;
--focus: #2b35ff;
--spring: cubic-bezier(0.34, 1.56, 0.64, 1);
display: inline-flex;
align-items: center;
gap: 10px;
min-height: 52px;
padding: 0 20px 0 14px;
border: 1.5px solid var(--line);
border-radius: 999px;
background: var(--idle);
color: var(--text);
font:
800 1.05rem/1 system-ui,
sans-serif;
font-variant-numeric: tabular-nums;
cursor: pointer;
transition:
border-color 0.3s,
background-color 0.3s,
transform 0.2s;
}
.gu-react[data-theme="dark"] {
--idle: #1f1f23;
--text: #f3eee3;
--line: rgb(243 238 227 / 0.16);
--focus: #d7ff3a;
}
.gu-react:active {
transform: scale(0.95);
}
.gu-react:focus-visible {
outline: 2px solid var(--focus);
outline-offset: 3px;
}
.gu-react[data-liked] {
border-color: var(--heart);
background: color-mix(in srgb, var(--heart) 12%, var(--idle));
}
.gu-react__icon {
position: relative;
display: grid;
place-items: center;
width: 28px;
height: 28px;
}
.gu-react__icon svg {
width: 26px;
height: 26px;
fill: transparent;
stroke: currentColor;
stroke-width: 1.8;
stroke-linejoin: round;
transition:
fill 0.2s,
stroke 0.2s;
}
.gu-react[data-liked] .gu-react__icon svg {
fill: var(--heart);
stroke: var(--heart);
animation: gu-react-pop 0.55s var(--spring);
}
@keyframes gu-react-pop {
0% {
transform: scale(0.6);
}
50% {
transform: scale(1.3);
}
}
/* Sparks: each flies out along its own angle and shrinks away */
.gu-react__sparks {
position: absolute;
inset: 50% auto auto 50%;
}
.gu-react__sparks i {
position: absolute;
width: 6px;
height: 6px;
margin: -3px;
border-radius: 2px;
background: var(--spark-a);
animation: gu-react-spark 0.7s cubic-bezier(0.16, 1, 0.3, 1) forwards;
}
.gu-react__sparks i:nth-child(even) {
background: var(--spark-b);
width: 4px;
height: 4px;
}
@keyframes gu-react-spark {
from {
transform: rotate(var(--a)) translateX(6px) scale(1);
}
to {
transform: rotate(var(--a)) translateX(30px) scale(0);
}
}
/* Rolling digits: a column 0-9 shifted by translateY */
.gu-react__count {
display: inline-flex;
}
.gu-react__digit {
display: inline-block;
height: 1em;
overflow: hidden;
line-height: 1;
}
.gu-react__digit > span {
display: flex;
flex-direction: column;
transition: transform 0.5s var(--spring);
}
@media (prefers-reduced-motion: reduce) {
.gu-react__sparks {
display: none;
}
.gu-react[data-liked] .gu-react__icon svg {
animation: none;
}
.gu-react__digit > span {
transition: none;
}
}
```
You might also want
Next piece: Reading progress barActivity rings
Components, intermediate
Cart drawer
Components, advanced
Copy field
Components, beginner