Skeleton loaders
Five skeleton placeholders: a line, a card, an avatar row, a text block and a list. Each uses a moving token shimmer and 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-skeletonDependencies, the @ai2/tokens theme and the component file are installed together.
Install dependencies
npm install motionCopy the source
components/ui/loaders-skeleton.tsx"use client"
import type * as React from "react"
import { motion, useReducedMotion } from "motion/react"
import { cn } from "@/lib/utils"
/* Skeleton loader family: 5 skeleton indicators with a token shimmer sweep. The blocks are bg-secondary; a foreground-derived highlight moves left to right across them (NOT a keyframe but a motion.span - the registry stays self-contained). Colour comes ONLY from tokens. Size = the overall scale (height and width are measured sensibly). role=status. DELIBERATE: it keeps sweeping under reduced-motion too (a stopped skeleton reads as "hung"). */
export type StyledSize = "sm" | "md" | "lg" | "xl"
const box: Record<StyledSize, string> = {
sm: "size-4",
md: "size-5",
lg: "size-6",
xl: "size-8",
}
const scale: Record<StyledSize, string> = {
sm: "w-40",
md: "w-56",
lg: "w-72",
xl: "w-96",
}
type Props = React.ComponentProps<"div"> & { size?: StyledSize; label?: string }
const SHIMMER =
"bg-[linear-gradient(90deg,transparent,color-mix(in_oklab,var(--color-foreground)_10%,transparent),transparent)]"
/* Tekrar kullanilabilen iskelet blok: bg-secondary + hareketli shimmer overlay. */
function Block({ className }: { className?: string }) {
return (
<span className={cn("relative block overflow-hidden rounded-md bg-secondary", className)}>
<motion.span
aria-hidden="true"
className={cn("absolute inset-y-0 left-0 w-2/3", SHIMMER)}
animate={{ x: ["-100%", "250%"] }}
transition={{ duration: 1.4, ease: "easeInOut", repeat: Infinity }}
/>
</span>
)
}
/* Line: tek yuvarlatilmis cubuk + token shimmer supurmesi. */
export function LineSkeleton({ className, size = "md", label = "Loading", ...props }: Props) {
return (
<div
data-slot="styled-loader"
role="status"
aria-label={label}
className={cn("inline-block max-w-full", scale[size], className)}
{...props}
>
<Block className="h-4 w-full" />
</div>
)
}
/* Card: one block plus two lines. */
export function CardSkeleton({ className, size = "md", label = "Loading", ...props }: Props) {
return (
<div
data-slot="styled-loader"
role="status"
aria-label={label}
className={cn("inline-flex max-w-full flex-col gap-3", scale[size], className)}
{...props}
>
<Block className="h-24 w-full" />
<Block className="h-3 w-full" />
<Block className="h-3 w-4/5" />
</div>
)
}
/* Avatar: a circle plus two lines beside it. */
export function AvatarSkeleton({ className, size = "md", label = "Loading", ...props }: Props) {
return (
<div
data-slot="styled-loader"
role="status"
aria-label={label}
className={cn("inline-flex max-w-full items-center gap-3", scale[size], className)}
{...props}
>
<Block className="size-10 shrink-0 rounded-full" />
<div className="flex flex-1 flex-col gap-2">
<Block className="h-3 w-3/4" />
<Block className="h-3 w-1/2" />
</div>
</div>
)
}
/* Text: 3-4 lines of varying width. */
export function TextSkeleton({ className, size = "md", label = "Loading", ...props }: Props) {
const widths = ["w-full", "w-11/12", "w-4/5", "w-2/3"]
return (
<div
data-slot="styled-loader"
role="status"
aria-label={label}
className={cn("inline-flex max-w-full flex-col gap-2", scale[size], className)}
{...props}
>
{widths.map((w, i) => (
<Block key={i} className={cn("h-3", w)} />
))}
</div>
)
}
/* List: 3 rows, each a small circle plus a line. */
export function ListSkeleton({ className, size = "md", label = "Loading", ...props }: Props) {
const rows = [0, 1, 2]
return (
<div
data-slot="styled-loader"
role="status"
aria-label={label}
className={cn("inline-flex max-w-full flex-col gap-3", scale[size], className)}
{...props}
>
{rows.map((i) => (
<div key={i} className="flex items-center gap-3">
<Block className="size-6 shrink-0 rounded-full" />
<Block className="h-3 flex-1" />
</div>
))}
</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.
Line
A single bar with a token shimmer sweep.
import { LineSkeleton } from "@/components/ui/loaders-skeleton"
<LineSkeleton />Card
A media block with two lines.
import { CardSkeleton } from "@/components/ui/loaders-skeleton"
<CardSkeleton />Avatar
A circle with two lines beside it.
import { AvatarSkeleton } from "@/components/ui/loaders-skeleton"
<AvatarSkeleton />Text
Several lines of varying width.
import { TextSkeleton } from "@/components/ui/loaders-skeleton"
<TextSkeleton />List
Rows of a small circle and a line.
import { ListSkeleton } from "@/components/ui/loaders-skeleton"
<ListSkeleton />ai2 Skeleton loaders: 5 styled variations on the token system
The ai2 Skeleton loaders are a set of 5 decorative button variations from the styled layer of the @ai2 design system, built around content placeholders. 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 sweeps a soft token shimmer across the placeholder blocks. The styled layer is opt-in, so the dependency only lands if you use it; the base components stay lean. Under reduced motion, the shimmer keeps sweeping on purpose, like the base Spinner, because a frozen placeholder reads as a hang.
What is in the ai2 Skeleton loaders?
5 exports in one file: Line, Card, Avatar, Text and List. 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 sweeps a soft token shimmer across the placeholder blocks.
- Reduced-motion aware: Under prefers-reduced-motion, the shimmer keeps sweeping on purpose, like the base Spinner, because a frozen placeholder 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 Skeleton 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.