Text skeletons
Five text placeholders with realistic line rhythm: a single line, a paragraph, a heading, a mixed block and a caption. Line widths are fixed and index derived, never random, so the server and client render the same thing.
Installation
The styled layer is free and installs like any other ai2 component.
Run the following command
npx shadcn@latest add @ai2/skeleton-textDependencies, the @ai2/tokens theme and the component file are installed together.
Install dependencies
npm install motionCopy the source
components/ui/skeleton-text.tsx"use client"
import type * as React from "react"
import { motion, useReducedMotion } from "motion/react"
import { cn } from "@/lib/utils"
/* Text skeleton family: 5 text-line layouts. The difference is not in the ANIMATION but in the STRUCTURE - the line count, the line height and realistic varying widths. The widths are picked by index from a FIXED list (NO Math.random, deterministic SSR). Colour comes ONLY from tokens. Skeletons are decorative: the root is aria-hidden. The pulse stops under reduced motion. */
export type StyledSize = "sm" | "md" | "lg" | "xl"
type Props = React.ComponentProps<"div"> & { size?: StyledSize }
/* Shared calm pulse (framer-motion, NO keyframes). */
function Block({ className, delay = 0 }: { className?: string; delay?: number }) {
const reduce = useReducedMotion()
return (
<motion.span
className={cn("block rounded-md bg-secondary", className)}
animate={reduce ? undefined : { opacity: [0.5, 1, 0.5] }}
transition={
reduce ? undefined : { duration: 1.6, ease: "easeInOut", repeat: Infinity, delay }
}
/>
)
}
/* Govde satiri yuksekligi. */
const line: Record<StyledSize, string> = {
sm: "h-2.5",
md: "h-3",
lg: "h-3.5",
xl: "h-4",
}
/* Baslik cubugu yuksekligi. */
const head: Record<StyledSize, string> = {
sm: "h-4",
md: "h-5",
lg: "h-6",
xl: "h-8",
}
const gap: Record<StyledSize, string> = {
sm: "gap-2",
md: "gap-2.5",
lg: "gap-3",
xl: "gap-3.5",
}
/* A realistic paragraph rhythm: a fixed width cycle with a short last line. */
const widths = ["w-full", "w-11/12", "w-full", "w-10/12", "w-11/12", "w-9/12"]
const root = "flex w-full flex-col"
/* Line: tek metin satiri. */
export function LineSkeleton({ className, size = "md", ...props }: Props) {
return (
<div
data-slot="styled-skeleton"
aria-hidden="true"
className={cn(root, className)}
{...props}
>
<Block className={cn("w-full", line[size])} />
</div>
)
}
/* Paragraph: an n-line block whose last line is cut short. */
export function ParagraphSkeleton({
className,
size = "md",
lines = 4,
...props
}: Props & { lines?: number }) {
return (
<div
data-slot="styled-skeleton"
aria-hidden="true"
className={cn(root, gap[size], className)}
{...props}
>
{Array.from({ length: lines }, (_, i) => (
<Block
key={i}
delay={i * 0.12}
className={cn(line[size], i === lines - 1 ? "w-3/5" : widths[i % widths.length])}
/>
))}
</div>
)
}
/* Heading: kalin baslik cubugu + altinda tek destek satiri. */
export function HeadingSkeleton({ className, size = "md", ...props }: Props) {
return (
<div
data-slot="styled-skeleton"
aria-hidden="true"
className={cn(root, gap[size], className)}
{...props}
>
<Block className={cn("w-2/3 rounded-lg", head[size])} />
<Block className={cn("w-2/5", line[size])} delay={0.12} />
</div>
)
}
/* Mixed: baslik + paragraf + kisa alt not, tek blokta gercekci makale ritmi. */
export function MixedSkeleton({ className, size = "md", ...props }: Props) {
return (
<div
data-slot="styled-skeleton"
aria-hidden="true"
className={cn(root, gap[size], className)}
{...props}
>
<Block className={cn("w-1/2 rounded-lg", head[size])} />
{widths.slice(0, 3).map((w, i) => (
<Block key={w} delay={(i + 1) * 0.12} className={cn(w, line[size])} />
))}
<Block className={cn("w-1/4", line[size])} delay={0.48} />
</div>
)
}
/* Caption: tek kisa alt yazi satiri (yari opak, ikincil metin gibi). */
export function CaptionSkeleton({ className, size = "md", ...props }: Props) {
return (
<div
data-slot="styled-skeleton"
aria-hidden="true"
className={cn(root, className)}
{...props}
>
<Block
className={cn(
"w-2/5 bg-[color-mix(in_oklab,var(--color-secondary)_70%,transparent)]",
line[size]
)}
/>
</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 text line placeholder.
import { LineSkeleton } from "@/components/ui/skeleton-text"
<LineSkeleton />Paragraph
Several lines with a short last line.
import { ParagraphSkeleton } from "@/components/ui/skeleton-text"
<ParagraphSkeleton />Heading
A heavy title bar over one support line.
import { HeadingSkeleton } from "@/components/ui/skeleton-text"
<HeadingSkeleton />Mixed
A heading, a paragraph and a short note.
import { MixedSkeleton } from "@/components/ui/skeleton-text"
<MixedSkeleton />Caption
One short, quieter secondary line.
import { CaptionSkeleton } from "@/components/ui/skeleton-text"
<CaptionSkeleton />ai2 Text skeletons: 5 styled variations on the token system
The ai2 Text skeletons are a set of 5 decorative button variations from the styled layer of the @ai2 design system, built around text line placeholders with realistic varying widths. 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 runs one calm opacity pulse, staggered line by line. The styled layer is opt-in, so the dependency only lands if you use it; the base components stay lean. Under reduced motion, the pulse stops and the lines stay static.
What is in the ai2 Text skeletons?
5 exports in one file: Line, Paragraph, Heading, Mixed and Caption. 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 runs one calm opacity pulse, staggered line by line.
- Reduced-motion aware: Under prefers-reduced-motion, the pulse stops and the lines stay static.
- 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 Text skeletons 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.