Morph loaders
Five shape-shifting loaders: a morphing blob, a flip, a stretch, a triangle cycle and a spinning square. 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/loaders-morphDependencies, the @ai2/tokens theme and the component file are installed together.
Install dependencies
npm install motionCopy the source
components/ui/loaders-morph.tsx"use client"
import type * as React from "react"
import { motion, useReducedMotion } from "motion/react"
import { cn } from "@/lib/utils"
/* Morph loader family: 5 decorative indicators that change shape and form. Colour comes ONLY from tokens (currentColor / bg-current). Size = the box scale (aligned with the base spinner). DELIBERATE: the loader keeps moving under reduced-motion too (a stopped loader reads as "hung"). Every value is fixed and deterministic, nothing random. */
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 }
/* Blob: bir sekil border-radius'unu surekli akiskan degistirir. */
export function BlobLoader({ className, size = "md", label = "Loading", ...props }: Props) {
return (
<div
data-slot="styled-loader"
role="status"
aria-label={label}
className={cn("inline-flex items-center justify-center text-primary", box[size], className)}
{...props}
>
<motion.span
className="block size-full bg-current"
animate={{
borderRadius: [
"42% 58% 63% 37% / 41% 44% 56% 59%",
"67% 33% 40% 60% / 62% 57% 43% 38%",
"38% 62% 55% 45% / 55% 38% 62% 45%",
"42% 58% 63% 37% / 41% 44% 56% 59%",
],
rotate: [0, 120, 240, 360],
}}
transition={{ duration: 2.6, ease: "easeInOut", repeat: Infinity }}
/>
</div>
)
}
/* Flip: bir kare donerek daireye yuvarlaniyor ve geri donuyor. */
export function FlipLoader({ className, size = "md", label = "Loading", ...props }: Props) {
return (
<div
data-slot="styled-loader"
role="status"
aria-label={label}
className={cn("inline-flex items-center justify-center text-info", box[size], className)}
{...props}
>
<motion.span
className="block size-4/5 bg-current"
animate={{
borderRadius: ["12%", "50%", "12%"],
rotate: [0, 180, 360],
}}
transition={{ duration: 1.4, ease: "easeInOut", repeat: Infinity }}
/>
</div>
)
}
/* Stretch: a pill stretches and flattens with scaleX/scaleY. */
export function StretchLoader({ className, size = "md", label = "Loading", ...props }: Props) {
return (
<div
data-slot="styled-loader"
role="status"
aria-label={label}
className={cn("inline-flex items-center justify-center text-brand", box[size], className)}
{...props}
>
<motion.span
className="block size-1/2 rounded-full bg-current"
animate={{ scaleX: [1, 1.9, 0.8, 1], scaleY: [1, 0.6, 1.6, 1] }}
transition={{ duration: 1.1, ease: "easeInOut", repeat: Infinity }}
/>
</div>
)
}
/* Triad: 3 nokta ucgen dongusunde pozisyon degistirir. */
export function TriadLoader({ className, size = "md", label = "Loading", ...props }: Props) {
const corners = [
{ top: "0%", left: "50%" },
{ top: "80%", left: "8%" },
{ top: "80%", left: "92%" },
]
return (
<div
data-slot="styled-loader"
role="status"
aria-label={label}
className={cn("relative inline-block text-success", box[size], className)}
{...props}
>
{corners.map((_, i) => (
<motion.span
key={i}
className="absolute size-1/4 -translate-x-1/2 -translate-y-1/2 rounded-full bg-current"
animate={{
top: [corners[i].top, corners[(i + 1) % 3].top, corners[(i + 2) % 3].top, corners[i].top],
left: [corners[i].left, corners[(i + 1) % 3].left, corners[(i + 2) % 3].left, corners[i].left],
}}
transition={{ duration: 1.8, ease: "easeInOut", repeat: Infinity }}
/>
))}
</div>
)
}
/* SpinSquare: yuvarlatilmis kare easing duraklamalariyla doner. */
export function SpinSquareLoader({ className, size = "md", label = "Loading", ...props }: Props) {
return (
<div
data-slot="styled-loader"
role="status"
aria-label={label}
className={cn("inline-flex items-center justify-center text-warning", box[size], className)}
{...props}
>
<motion.span
className="block size-4/5 rounded-[30%] border-2 border-current"
animate={{ rotate: [0, 90, 180, 270, 360] }}
transition={{ duration: 2, ease: "easeInOut", times: [0, 0.25, 0.5, 0.75, 1], repeat: Infinity }}
/>
</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.
Blob
A shape morphs its border-radius endlessly.
import { BlobLoader } from "@/components/ui/loaders-morph"
<BlobLoader />Flip
A square rotates and rounds into a circle and back.
import { FlipLoader } from "@/components/ui/loaders-morph"
<FlipLoader />Stretch
A pill stretches and squashes.
import { StretchLoader } from "@/components/ui/loaders-morph"
<StretchLoader />Triad
Three dots cycle around a triangle.
import { TriadLoader } from "@/components/ui/loaders-morph"
<TriadLoader />Spin square
A rounded square rotates with eased pauses.
import { SpinSquareLoader } from "@/components/ui/loaders-morph"
<SpinSquareLoader />ai2 Morph loaders: 5 styled variations on the token system
The ai2 Morph loaders are a set of 5 decorative button variations from the styled layer of the @ai2 design system, built around shape-shifting 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 morphs the radius, flip, stretch and rotation. The styled layer is opt-in, so the dependency only lands if you use it; the base components stay lean. Under reduced motion, the morphs keep running on purpose, like the base Spinner, because a frozen loader reads as a hang.
What is in the ai2 Morph loaders?
5 exports in one file: Blob, Flip, Stretch, Triad and Spin square. 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 morphs the radius, flip, stretch and rotation.
- Reduced-motion aware: Under prefers-reduced-motion, the morphs keep running 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 Morph 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.