Particle buttons
Five takes on emitted particles: a hover burst, a click confetti, a continuous sparkle, rising sparks and a click pop. Each is sized and token-driven, with fixed deterministic angles.
Installation
The styled layer is free and installs like any other ai2 component.
Run the following command
npx shadcn@latest add @ai2/buttons-particleDependencies, the @ai2/tokens theme and the component file are installed together.
Install dependencies
npm install motionCopy the source
components/ui/buttons-particle.tsx"use client"
import * as React from "react"
import { AnimatePresence, motion, useReducedMotion } from "motion/react"
import { cn } from "@/lib/utils"
/* Particle button family: 5 variations on particle emission. The particles fly and fade with framer-motion at fixed angles (deterministic, nothing random). All are sized, take colour ONLY from tokens, and there are no particles under reduced-motion. */
export type StyledSize = "sm" | "md" | "lg" | "xl"
const sizes: Record<StyledSize, string> = {
sm: "h-8 gap-1.5 rounded-md px-3 text-sm",
md: "h-9 gap-2 rounded-lg px-4 text-sm",
lg: "h-10 gap-2 rounded-lg px-5 text-sm",
xl: "h-12 gap-2.5 rounded-xl px-6 text-base",
}
const base =
"relative inline-flex shrink-0 select-none items-center justify-center bg-primary font-medium whitespace-nowrap text-primary-foreground outline-none focus-visible:ring-[3px] focus-visible:ring-ring/50 disabled:pointer-events-none disabled:opacity-50 [&_svg]:pointer-events-none [&_svg]:size-4 [&_svg]:shrink-0 [&_i]:text-base [&_i]:leading-none"
const RADIAL = Array.from({ length: 10 }, (_, i) => {
const a = (i / 10) * Math.PI * 2
return { dx: Math.cos(a) * 26, dy: Math.sin(a) * 26 }
})
const CONFETTI_TONES = ["bg-info", "bg-success", "bg-warning", "bg-danger", "bg-brand"]
type Props = React.ComponentProps<"button"> & { size?: StyledSize }
/* Burst: token dots fly outwards on hover (replays on every hover). */
export function BurstButton({ className, size = "md", children, onPointerEnter, ...props }: Props) {
const reduce = useReducedMotion()
const [burst, setBurst] = React.useState(0)
return (
<button
data-slot="styled-button"
onPointerEnter={(e) => {
if (!reduce) setBurst((b) => b + 1)
onPointerEnter?.(e)
}}
className={cn(base, sizes[size], "rounded-lg", className)}
{...props}
>
<span aria-hidden="true" className="pointer-events-none absolute inset-0 overflow-visible">
<AnimatePresence>
{burst > 0 && (
<span key={burst} className="absolute left-1/2 top-1/2">
{RADIAL.map((p, i) => (
<motion.span
key={i}
className="absolute size-1 rounded-full bg-info"
initial={{ x: 0, y: 0, opacity: 0.9, scale: 1 }}
animate={{ x: p.dx, y: p.dy, opacity: 0, scale: 0.4 }}
transition={{ duration: 0.5, ease: "easeOut" }}
/>
))}
</span>
)}
</AnimatePresence>
</span>
<span className="relative flex items-center gap-2">{children}</span>
</button>
)
}
/* Confetti: tiklamada cok tonlu (token) parcaciklar yukari sacilir. */
export function ConfettiButton({ className, size = "md", children, onPointerDown, ...props }: Props) {
const reduce = useReducedMotion()
const [pop, setPop] = React.useState(0)
return (
<button
data-slot="styled-button"
onPointerDown={(e) => {
if (!reduce) setPop((b) => b + 1)
onPointerDown?.(e)
}}
className={cn(base, sizes[size], "rounded-lg", className)}
{...props}
>
<span aria-hidden="true" className="pointer-events-none absolute inset-0 overflow-visible">
<AnimatePresence>
{pop > 0 && (
<span key={pop} className="absolute left-1/2 top-0">
{Array.from({ length: 10 }).map((_, i) => {
const dx = (i - 4.5) * 8
return (
<motion.span
key={i}
className={cn("absolute size-1.5 rounded-[1px]", CONFETTI_TONES[i % CONFETTI_TONES.length])}
initial={{ x: 0, y: 0, opacity: 1, rotate: 0 }}
animate={{ x: dx, y: -22 - (i % 3) * 6, opacity: 0, rotate: 180 }}
transition={{ duration: 0.6, ease: "easeOut" }}
/>
)
})}
</span>
)}
</AnimatePresence>
</span>
<span className="relative flex items-center gap-2">{children}</span>
</button>
)
}
/* Sparkle: cevrede surekli parildayan token yildiz noktalari. */
export function SparkleButton({ className, size = "md", children, ...props }: Props) {
const reduce = useReducedMotion()
const spots = [
{ left: "8%", top: "20%", delay: 0 },
{ left: "88%", top: "30%", delay: 0.4 },
{ left: "20%", top: "78%", delay: 0.8 },
{ left: "70%", top: "72%", delay: 1.2 },
{ left: "50%", top: "12%", delay: 0.6 },
]
return (
<button data-slot="styled-button" className={cn(base, sizes[size], "relative rounded-lg", className)} {...props}>
<span aria-hidden="true" className="pointer-events-none absolute inset-0">
{!reduce &&
spots.map((s, i) => (
<motion.span
key={i}
className="absolute size-1 rounded-full bg-primary-foreground"
style={{ left: s.left, top: s.top }}
animate={{ opacity: [0, 1, 0], scale: [0.4, 1, 0.4] }}
transition={{ duration: 1.6, ease: "easeInOut", repeat: Infinity, delay: s.delay }}
/>
))}
</span>
<span className="relative flex items-center gap-2">{children as React.ReactNode}</span>
</button>
)
}
/* Rise: tabandan surekli yukselen token kivilcimlar (kor/ates hissi). */
export function RiseButton({ className, size = "md", children, ...props }: Props) {
const reduce = useReducedMotion()
const cols = [15, 32, 50, 68, 85]
return (
<button data-slot="styled-button" className={cn(base, sizes[size], "relative overflow-hidden rounded-lg", className)} {...props}>
<span aria-hidden="true" className="pointer-events-none absolute inset-0">
{!reduce &&
cols.map((left, i) => (
<motion.span
key={i}
className="absolute bottom-0 size-1 rounded-full bg-warning"
style={{ left: `${left}%` }}
animate={{ y: [4, -18], opacity: [0, 0.9, 0] }}
transition={{ duration: 1.4, ease: "easeOut", repeat: Infinity, delay: i * 0.25 }}
/>
))}
</span>
<span className="relative flex items-center gap-2">{children as React.ReactNode}</span>
</button>
)
}
/* Pop: tiklamada birkac buyuk token parcacik disari firlar. */
export function PopButton({ className, size = "md", children, onPointerDown, ...props }: Props) {
const reduce = useReducedMotion()
const [pop, setPop] = React.useState(0)
const dirs = Array.from({ length: 6 }, (_, i) => {
const a = (i / 6) * Math.PI * 2
return { dx: Math.cos(a) * 30, dy: Math.sin(a) * 30 }
})
return (
<button
data-slot="styled-button"
onPointerDown={(e) => {
if (!reduce) setPop((b) => b + 1)
onPointerDown?.(e)
}}
className={cn(base, sizes[size], "rounded-lg", className)}
{...props}
>
<span aria-hidden="true" className="pointer-events-none absolute inset-0 overflow-visible">
<AnimatePresence>
{pop > 0 && (
<span key={pop} className="absolute left-1/2 top-1/2">
{dirs.map((p, i) => (
<motion.span
key={i}
className="absolute size-1.5 rounded-full bg-brand"
initial={{ x: 0, y: 0, opacity: 1, scale: 1.2 }}
animate={{ x: p.dx, y: p.dy, opacity: 0, scale: 0.5 }}
transition={{ duration: 0.45, ease: "easeOut" }}
/>
))}
</span>
)}
</AnimatePresence>
</span>
<span className="relative flex items-center gap-2">{children}</span>
</button>
)
}Manual installs skip the @ai2/tokens theme, so add the token CSS from the theming guide or the tone colors will be missing.
Variations
5 takes on the same idea. Each is its own export, and every one accepts a size prop (sm, md, lg, xl) aligned to the base Button scale.
Burst
Token dots scatter outward on hover.
import { BurstButton } from "@/components/ui/buttons-particle"
<BurstButton>Burst</BurstButton>Confetti
Multi-token pieces spray upward on click.
import { ConfettiButton } from "@/components/ui/buttons-particle"
<ConfettiButton>Confetti</ConfettiButton>Sparkle
Token star dots twinkle continuously around the label.
import { SparkleButton } from "@/components/ui/buttons-particle"
<SparkleButton>Sparkle</SparkleButton>Rise
Warm token sparks rise continuously from the base.
import { RiseButton } from "@/components/ui/buttons-particle"
<RiseButton>Rise</RiseButton>Pop
A few larger token particles fire out on click.
import { PopButton } from "@/components/ui/buttons-particle"
<PopButton>Pop</PopButton>ai2 Particle buttons: 5 styled variations on the token system
The ai2 Particle buttons are a set of 5 decorative button variations from the styled layer of the @ai2 design system, built around emitted token particles. They are free and MIT licensed, and every color comes from a semantic token, so they theme with the rest of ai2 in light and dark.
Motion runs on framer-motion: framer-motion fires the particles along fixed deterministic angles on hover, click, or in a loop. The styled layer is opt-in, so the dependency only lands if you use it; the base components stay lean. Under reduced motion, no particles are emitted and the buttons behave plainly.
What is in the ai2 Particle buttons?
5 exports in one file: Burst, Confetti, Sparkle, Rise and Pop. Each renders a native button and takes a size prop (sm, md, lg, xl) aligned to the base Button. They are separate from the base Button on purpose: the base keeps its clean variant, tone and size axes, while the styled layer carries the effects.
You own the file. Copy the one category file and you have all 5 variations, with no runtime dependency on ai2 itself.
Why use it
- On-system by construction: Every color resolves to an ai2 semantic token, so the buttons follow your theme in light and dark with no extra work.
- Effect without the sprawl: The decorations live in a dedicated styled file, so the base Button keeps its clean, predictable API.
- Accessible and honest: Each renders a real button element, keeps a visible focus ring, and respects prefers-reduced-motion.
Features
- Token-driven color: No hardcoded hex or oklch; the look recolors with your theme tokens.
- framer-motion: framer-motion fires the particles along fixed deterministic angles on hover, click, or in a loop.
- Reduced-motion aware: Under prefers-reduced-motion, no particles are emitted and the buttons behave plainly.
- Size aligned to the base: Every variation takes sm, md, lg and xl matching the base Button height scale, so styled and base buttons line up in a row.
Production tips
- Use it for emphasis, not everywhere: Styled buttons draw the eye. Reserve them for the one action you want people to take on a screen, and use the base Button for the rest.
- Keep labels as verbs: The decoration adds weight, so a clear action label keeps the button scannable.
- Pick one variation per surface: The variations share a family; using two different ones in the same view competes for attention.
Works with the rest of ai2
The Particle buttons sit alongside the base Button and the rest of the @ai2 registry. They share the same token file, so a styled action next to a base button or a badge stays visually consistent in both modes.