Particle loaders
Five particle loaders: a swarm, a scatter, a converge, a trail and a firefly. 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/loaders-particleDependencies, the @ai2/tokens theme and the component file are installed together.
Install dependencies
npm install motionCopy the source
components/ui/loaders-particle.tsx"use client"
import type * as React from "react"
import { motion, useReducedMotion } from "motion/react"
import { cn } from "@/lib/utils"
/* Particle loader family: 5 decorative indicators on a particle and scatter theme. Colour comes ONLY from tokens (currentColor / bg-current). Size = the box scale. DELIBERATE: the loader keeps moving under reduced-motion too. The angles and delays are index-derived and fixed (NO Math.random) - 8 dots land at 45-degree steps. */
export type StyledSize = "sm" | "md" | "lg" | "xl"
const box: Record<StyledSize, string> = {
sm: "size-4",
md: "size-5",
lg: "size-6",
xl: "size-8",
}
type Props = React.ComponentProps<"div"> & { size?: StyledSize; label?: string }
const ANGLES = [0, 45, 90, 135, 180, 225, 270, 315]
/* Swarm: 8 nokta sabit acilarda dongude nabiz atar. */
export function SwarmLoader({ className, size = "md", label = "Loading", ...props }: Props) {
return (
<div
data-slot="styled-loader"
role="status"
aria-label={label}
className={cn("relative inline-block text-primary", box[size], className)}
{...props}
>
{ANGLES.map((deg, i) => (
<span
key={deg}
className="absolute inset-0"
style={{ transform: `rotate(${deg}deg)` }}
>
<motion.span
className="absolute left-1/2 top-0 size-1/5 -translate-x-1/2 rounded-full bg-current"
animate={{ scale: [0.3, 1, 0.3], opacity: [0.3, 1, 0.3] }}
transition={{ duration: 1.2, ease: "easeInOut", repeat: Infinity, delay: i * 0.12 }}
/>
</span>
))}
</div>
)
}
/* Scatter: noktalar disari savrulup geri doner (dongu). */
export function ScatterLoader({ className, size = "md", label = "Loading", ...props }: Props) {
return (
<div
data-slot="styled-loader"
role="status"
aria-label={label}
className={cn("relative inline-block text-info", box[size], className)}
{...props}
>
{ANGLES.map((deg) => (
<span
key={deg}
className="absolute inset-0"
style={{ transform: `rotate(${deg}deg)` }}
>
<motion.span
className="absolute left-1/2 top-1/2 size-1/5 -translate-x-1/2 -translate-y-1/2 rounded-full bg-current"
animate={{ y: ["0%", "-260%", "0%"], opacity: [1, 0.2, 1] }}
transition={{ duration: 1.6, ease: "easeInOut", repeat: Infinity }}
/>
</span>
))}
</div>
)
}
/* Converge: noktalar disaridan merkeze tekrar tekrar toplanir. */
export function ConvergeLoader({ className, size = "md", label = "Loading", ...props }: Props) {
return (
<div
data-slot="styled-loader"
role="status"
aria-label={label}
className={cn("relative inline-block text-brand", box[size], className)}
{...props}
>
{ANGLES.map((deg) => (
<span
key={deg}
className="absolute inset-0"
style={{ transform: `rotate(${deg}deg)` }}
>
<motion.span
className="absolute left-1/2 top-1/2 size-1/5 -translate-x-1/2 -translate-y-1/2 rounded-full bg-current"
animate={{ y: ["-230%", "0%", "-230%"], opacity: [0.3, 1, 0.3] }}
transition={{ duration: 1.5, ease: "easeInOut", repeat: Infinity }}
/>
</span>
))}
</div>
)
}
/* Trail: lider nokta + kademeli gecikmeli iz noktalari daire boyunca. */
export function TrailLoader({ className, size = "md", label = "Loading", ...props }: Props) {
const trail = [0, 1, 2, 3, 4]
return (
<div
data-slot="styled-loader"
role="status"
aria-label={label}
className={cn("relative inline-block text-success", box[size], className)}
{...props}
>
{trail.map((i) => (
<motion.span
key={i}
className="absolute inset-0"
animate={{ rotate: 360 }}
transition={{ duration: 1.2, ease: "linear", repeat: Infinity, delay: i * -0.1 }}
>
<span
className="absolute left-1/2 top-0 -translate-x-1/2 rounded-full bg-current"
style={{ width: `${26 - i * 4}%`, height: `${26 - i * 4}%`, opacity: 1 - i * 0.18 }}
/>
</motion.span>
))}
</div>
)
}
/* Firefly: birkac nokta sabit pozisyonlarda kademeli sonup yanar. */
export function FireflyLoader({ className, size = "md", label = "Loading", ...props }: Props) {
const reduce = useReducedMotion()
const spots = [
{ top: "10%", left: "20%" },
{ top: "25%", left: "70%" },
{ top: "60%", left: "35%" },
{ top: "70%", left: "80%" },
{ top: "45%", left: "12%" },
{ top: "82%", left: "55%" },
]
return (
<div
data-slot="styled-loader"
role="status"
aria-label={label}
className={cn("relative inline-block text-warning", box[size], className)}
{...props}
>
{spots.map((s, i) => (
<motion.span
key={i}
className="absolute size-1 rounded-full bg-current"
style={{ top: s.top, left: s.left }}
animate={{ opacity: [0, 1, 0], scale: [0.5, 1, 0.5] }}
transition={{ duration: 1.6, ease: "easeInOut", repeat: Infinity, delay: reduce ? 0 : i * 0.24 }}
/>
))}
</div>
)
}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.
Swarm
Dots on fixed angles pulse in a loop.
import { SwarmLoader } from "@/components/ui/loaders-particle"
<SwarmLoader />Scatter
Dots fly out and return.
import { ScatterLoader } from "@/components/ui/loaders-particle"
<ScatterLoader />Converge
Dots converge to the center repeatedly.
import { ConvergeLoader } from "@/components/ui/loaders-particle"
<ConvergeLoader />Trail
A lead dot with staggered trailing dots.
import { TrailLoader } from "@/components/ui/loaders-particle"
<TrailLoader />Firefly
Dots fade in and out at fixed positions.
import { FireflyLoader } from "@/components/ui/loaders-particle"
<FireflyLoader />ai2 Particle loaders: 5 styled variations on the token system
The ai2 Particle loaders are a set of 5 decorative button variations from the styled layer of the @ai2 design system, built around particle-based loading indicators. 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 particles 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 keep moving on purpose, like the base Spinner, because a frozen loader reads as a hang.
What is in the ai2 Particle loaders?
5 exports in one file: Swarm, Scatter, Converge, Trail and Firefly. 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 particles along fixed deterministic paths.
- Reduced-motion aware: Under prefers-reduced-motion, the particles keep moving on purpose, like the base Spinner, because a frozen loader reads as a hang.
- 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 loaders 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.