Particle badges
Five particle badges: sparks, a burst, an orbit trail, confetti and glitter. Each is sized and token-driven.
Installation
The styled layer is free and installs like any other ai2 component.
Run the following command
npx shadcn@latest add @ai2/badges-particleDependencies, the @ai2/tokens theme and the component file are installed together.
Install dependencies
npm install motionCopy the source
components/ui/badges-particle.tsx"use client"
import * as React from "react"
import { motion, useReducedMotion } from "motion/react"
import { cn } from "@/lib/utils"
/* Particle badge family: 5 badges emitting token particles. Colour comes ONLY from tokens (alpha via color-mix or a utility), the size is aligned with the base badge scale (+xl). framer-motion (motion/react) is used only for the particle motion; every particle stops under reduced-motion. The positions are deterministic (no Math.random). */
export type StyledSize = "sm" | "md" | "lg" | "xl"
const box: Record<StyledSize, string> = {
sm: "h-5 gap-1 rounded-md px-1.5 text-xs",
md: "h-6 gap-1.5 rounded-md px-2 text-xs",
lg: "h-7 gap-1.5 rounded-lg px-2.5 text-sm",
xl: "h-8 gap-2 rounded-lg px-3 text-sm",
}
const base =
"relative inline-flex w-fit shrink-0 items-center justify-center whitespace-nowrap font-medium [&_svg]:size-3 [&_svg]:shrink-0 [&_i]:text-xs [&_i]:leading-none"
type Props = React.ComponentProps<"span"> & { size?: StyledSize }
/* Spark: birkac token kivilcim yukari dogru dongude suzulur. */
export function SparkBadge({ className, size = "md", children, ...props }: Props) {
const reduce = useReducedMotion()
const sparks = [
{ left: "22%", delay: 0 },
{ left: "50%", delay: 0.55 },
{ left: "78%", delay: 1.1 },
]
return (
<span
data-slot="styled-badge"
className={cn(base, box[size], "overflow-visible border border-border bg-secondary text-secondary-foreground", className)}
{...props}
>
{!reduce &&
sparks.map((s, i) => (
<motion.span
key={i}
aria-hidden="true"
className="pointer-events-none absolute bottom-1 size-1 rounded-full bg-info"
style={{ left: s.left }}
animate={{ y: [0, -9, -12], opacity: [0, 1, 0], scale: [0.4, 1, 0.3] }}
transition={{ duration: 1.6, delay: s.delay, ease: "easeOut", repeat: Infinity }}
/>
))}
<span className="relative">{children}</span>
</span>
)
}
/* Burst: token particles scatter outwards on hover. */
export function BurstBadge({ className, size = "md", children, ...props }: Props) {
const reduce = useReducedMotion()
const [on, setOn] = React.useState(false)
const angles = [0, 45, 90, 135, 180, 225, 270, 315]
return (
<span
data-slot="styled-badge"
className={cn(base, box[size], "overflow-visible border border-border bg-secondary text-secondary-foreground", className)}
{...props}
onMouseEnter={(e) => {
setOn(true)
props.onMouseEnter?.(e)
}}
onMouseLeave={(e) => {
setOn(false)
props.onMouseLeave?.(e)
}}
>
{!reduce &&
angles.map((a, i) => {
const rad = (a * Math.PI) / 180
return (
<motion.span
key={i}
aria-hidden="true"
className="pointer-events-none absolute left-1/2 top-1/2 size-1 rounded-full bg-info"
initial={false}
animate={
on
? { x: Math.cos(rad) * 14, y: Math.sin(rad) * 14, opacity: [1, 0], scale: [1, 0.3] }
: { x: 0, y: 0, opacity: 0, scale: 0.3 }
}
transition={{ duration: 0.5, ease: "easeOut" }}
/>
)
})}
<span className="relative">{children}</span>
</span>
)
}
/* Trail: kucuk bir token kuyruklu yildiz label etrafinda yorunge cizer. */
export function TrailBadge({ className, size = "md", children, ...props }: Props) {
const reduce = useReducedMotion()
return (
<span
data-slot="styled-badge"
className={cn(base, box[size], "overflow-visible border border-border bg-secondary text-secondary-foreground", className)}
{...props}
>
{!reduce && (
<motion.span
aria-hidden="true"
className="pointer-events-none absolute inset-0"
animate={{ rotate: 360 }}
transition={{ duration: 3, ease: "linear", repeat: Infinity }}
>
<span className="absolute left-1/2 top-0 size-1.5 -translate-x-1/2 rounded-full bg-info shadow-[0_0_6px_var(--color-info)]" />
</motion.span>
)}
<span className="relative">{children}</span>
</span>
)
}
/* Confetti: tiny multi-token confetti falls on hover. */
export function ConfettiBadge({ className, size = "md", children, ...props }: Props) {
const reduce = useReducedMotion()
const [on, setOn] = React.useState(false)
const bits = [
{ left: "18%", tone: "bg-info", dx: -6 },
{ left: "38%", tone: "bg-success", dx: 4 },
{ left: "58%", tone: "bg-warning", dx: -3 },
{ left: "78%", tone: "bg-danger", dx: 6 },
]
return (
<span
data-slot="styled-badge"
className={cn(base, box[size], "overflow-visible border border-border bg-secondary text-secondary-foreground", className)}
{...props}
onMouseEnter={(e) => {
setOn(true)
props.onMouseEnter?.(e)
}}
onMouseLeave={(e) => {
setOn(false)
props.onMouseLeave?.(e)
}}
>
{!reduce &&
bits.map((b, i) => (
<motion.span
key={i}
aria-hidden="true"
className={cn("pointer-events-none absolute -top-1 size-1 rounded-[1px]", b.tone)}
style={{ left: b.left }}
initial={false}
animate={on ? { y: [0, 14], x: [0, b.dx], opacity: [1, 0], rotate: [0, 120] } : { y: 0, opacity: 0 }}
transition={{ duration: 0.6, ease: "easeIn" }}
/>
))}
<span className="relative">{children}</span>
</span>
)
}
/* Glitter: label etrafinda parildayan token noktalar. */
export function GlitterBadge({ className, size = "md", children, ...props }: Props) {
const reduce = useReducedMotion()
const dots = [
{ left: "8%", top: "20%", delay: 0 },
{ left: "92%", top: "30%", delay: 0.4 },
{ left: "15%", top: "80%", delay: 0.8 },
{ left: "85%", top: "75%", delay: 1.2 },
]
return (
<span
data-slot="styled-badge"
className={cn(base, box[size], "overflow-visible border border-border bg-secondary text-secondary-foreground", className)}
{...props}
>
{!reduce &&
dots.map((d, i) => (
<motion.span
key={i}
aria-hidden="true"
className="pointer-events-none absolute size-1 rounded-full bg-warning"
style={{ left: d.left, top: d.top }}
animate={{ opacity: [0, 1, 0], scale: [0.4, 1, 0.4] }}
transition={{ duration: 1.4, delay: d.delay, ease: "easeInOut", repeat: Infinity }}
/>
))}
<span className="relative">{children}</span>
</span>
)
}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.
Spark
Token sparks drift on a loop.
import { SparkBadge } from "@/components/ui/badges-particle"
<SparkBadge>Pro</SparkBadge>Burst
Particles burst on hover.
import { BurstBadge } from "@/components/ui/badges-particle"
<BurstBadge>New</BurstBadge>Trail
A token comet orbits the label.
import { TrailBadge } from "@/components/ui/badges-particle"
<TrailBadge>Live</TrailBadge>Confetti
Tiny confetti pops on hover.
import { ConfettiBadge } from "@/components/ui/badges-particle"
<ConfettiBadge>Win</ConfettiBadge>Glitter
Twinkling token dots surround the label.
import { GlitterBadge } from "@/components/ui/badges-particle"
<GlitterBadge>VIP</GlitterBadge>ai2 Particle badges: 5 styled variations on the token system
The ai2 Particle badges are a set of 5 decorative button variations from the styled layer of the @ai2 design system, built around badges that emit 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 moves the sparks, bursts and orbits along fixed deterministic paths. The styled layer is opt-in, so the dependency only lands if you use it; the base components stay lean. Under reduced motion, the particles stop and the badges stay still.
What is in the ai2 Particle badges?
5 exports in one file: Spark, Burst, Trail, Confetti and Glitter. 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 moves the sparks, bursts and orbits along fixed deterministic paths.
- Reduced-motion aware: Under prefers-reduced-motion, the particles stop and the badges stay still.
- 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 badges 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.