Loaders
Five loading indicators: bouncing dots, an equalizer, a spinning ring, a pulse and an orbit. Each is sized and token-driven, and keeps animating under reduced motion because the movement is the message.
Installation
The styled layer is free and installs like any other ai2 component.
Run the following command
npx shadcn@latest add @ai2/loaders-styledDependencies, the @ai2/tokens theme and the component file are installed together.
Install dependencies
npm install motionCopy the source
components/ui/loaders-styled.tsx"use client"
import type * as React from "react"
import { motion, useReducedMotion } from "motion/react"
import { cn } from "@/lib/utils"
/* Loader family: 5 decorative loading indicators. Colour comes ONLY from tokens (currentColor / bg-primary). Size = the box scale (aligned with the base spinner). DELIBERATE: a loader's rotation is INFORMATION; like the base Spinner exception it keeps turning under reduced-motion too (a stopped loader reads as "hung"). Only a slowdown may be applied. */
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 }
/* Dots: uc nokta sirayla zipla-sön. */
export function DotsLoader({ className, size = "md", label = "Loading", ...props }: Props) {
const reduce = useReducedMotion()
return (
<div
data-slot="styled-loader"
role="status"
aria-label={label}
className={cn("inline-flex items-center gap-1 text-primary", box[size], className)}
{...props}
>
{[0, 1, 2].map((i) => (
<motion.span
key={i}
className="inline-block size-1/4 rounded-full bg-current"
animate={{ y: [0, -3, 0], opacity: [0.4, 1, 0.4] }}
transition={{ duration: 0.7, ease: "easeInOut", repeat: Infinity, delay: reduce ? 0 : i * 0.15 }}
/>
))}
</div>
)
}
/* Bars: ses cubugu gibi yukselip alcalan cubuklar. */
export function BarsLoader({ className, size = "md", label = "Loading", ...props }: Props) {
return (
<div
data-slot="styled-loader"
role="status"
aria-label={label}
className={cn("inline-flex items-end justify-center gap-0.5 text-primary", box[size], className)}
{...props}
>
{[0, 1, 2, 3].map((i) => (
<motion.span
key={i}
className="inline-block w-1/5 rounded-sm bg-current"
animate={{ height: ["30%", "100%", "30%"] }}
transition={{ duration: 0.8, ease: "easeInOut", repeat: Infinity, delay: i * 0.12 }}
/>
))}
</div>
)
}
/* Ring: token halka surekli doner (klasik). */
export function RingLoader({ className, size = "md", label = "Loading", ...props }: Props) {
return (
<div
data-slot="styled-loader"
role="status"
aria-label={label}
className={cn("inline-block text-primary", box[size], className)}
{...props}
>
<motion.span
className="block size-full rounded-full border-2 border-current/25 border-t-current"
animate={{ rotate: 360 }}
transition={{ duration: 0.8, ease: "linear", repeat: Infinity }}
/>
</div>
)
}
/* Pulse: dolu token daire nabiz gibi buyuyup soner. */
export function PulseLoader({ 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}
>
<motion.span
className="absolute inset-0 rounded-full bg-current"
animate={{ scale: [0.4, 1], opacity: [0.7, 0] }}
transition={{ duration: 1, ease: "easeOut", repeat: Infinity }}
/>
<span className="absolute inset-[35%] rounded-full bg-current" />
</div>
)
}
/* Orbit: bir nokta token yorunge boyunca doner. */
export function OrbitLoader({ 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}
>
<span className="absolute inset-[42%] rounded-full bg-current/40" />
<motion.span
className="absolute inset-0"
animate={{ rotate: 360 }}
transition={{ duration: 1, ease: "linear", repeat: Infinity }}
>
<span className="absolute left-1/2 top-0 size-1/4 -translate-x-1/2 rounded-full bg-current" />
</motion.span>
</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.
Dots
Three token dots bounce in sequence.
import { DotsLoader } from "@/components/ui/loaders-styled"
<DotsLoader />Bars
Token bars rise and fall like an equalizer.
import { BarsLoader } from "@/components/ui/loaders-styled"
<BarsLoader />Ring
A token ring spins continuously.
import { RingLoader } from "@/components/ui/loaders-styled"
<RingLoader />Pulse
A token circle pulses outward.
import { PulseLoader } from "@/components/ui/loaders-styled"
<PulseLoader />Orbit
A dot orbits a token center.
import { OrbitLoader } from "@/components/ui/loaders-styled"
<OrbitLoader />ai2 Loaders: 5 styled variations on the token system
The ai2 Loaders are a set of 5 decorative button variations from the styled layer of the @ai2 design system, built around 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 loops drive the dots, bars, ring, pulse and orbit. The styled layer is opt-in, so the dependency only lands if you use it; the base components stay lean. Under reduced motion, the loaders keep animating on purpose, like the base Spinner, because a frozen loader reads as a hang.
What is in the ai2 Loaders?
5 exports in one file: Dots, Bars, Ring, Pulse and Orbit. 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 loops drive the dots, bars, ring, pulse and orbit.
- Reduced-motion aware: Under prefers-reduced-motion, the loaders keep animating 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 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.