Response Skeleton
Placeholder lines that cascade in and shimmer while a reply loads.
Code
components/thinking-ui/response-skeleton.tsx
"use client";
import { motion } from "motion/react";
import { useMotion } from "@/lib/motion";
import { cn } from "@/lib/utils";
export type ResponseSkeletonProps = {
/** Number of placeholder lines. */
lines?: number;
className?: string;
};
// Ragged widths read as prose rather than a table
const widths = ["100%", "94%", "86%", "97%", "72%", "58%"];
export function ResponseSkeleton({ lines = 4, className }: ResponseSkeletonProps) {
const m = useMotion();
const enter = m.fadeUp(m.distance.sm);
return (
<div role="status" aria-label="Loading response" className={cn("flex w-full flex-col gap-2.5", className)}>
{Array.from({ length: lines }, (_, i) => (
<motion.span
key={i}
className="relative block h-3 overflow-hidden rounded-full bg-skeleton"
style={{ width: i === lines - 1 ? "55%" : widths[i % widths.length] }}
initial={enter.initial}
animate={enter.animate}
transition={{ ...m.spring("base"), delay: m.stagger(i) }}
>
{!m.reduce && (
<motion.span
aria-hidden
className="absolute inset-y-0 w-1/2"
style={{ background: "linear-gradient(90deg, transparent, var(--skeleton-highlight), transparent)" }}
initial={{ x: "-100%" }}
animate={{ x: "250%" }}
transition={{
duration: 1.6 * m.scale,
ease: m.personality.ease.inOut,
repeat: Infinity,
delay: m.stagger(i),
}}
/>
)}
</motion.span>
))}
</div>
);
}Motion notes
- Ragged line widths read as prose, so the placeholder hints at what's coming.
- The lines cascade in, and their shimmers are offset by the same stagger so the light travels diagonally.
- With reduced motion, the shimmer is removed and only static lines remain.
Installation
- 1
Install dependencies
Terminalnpm install motion clsx tailwind-merge - 2
Add the design tokens and motion system (once per project)
Copy
styles/tokens/*,lib/motion.tsxandlib/utils.tsfrom Get started. - 3
Paste the source into components/thinking-ui/response-skeleton.tsx
Copy it from the Code tab, or use Copy prompt to let your coding agent do all of this.
Usage
Example
{isLoading && <ResponseSkeleton lines={4} />}Props
| Prop | Type | Default | Description |
|---|---|---|---|
| lines | number | 4 | Number of placeholder lines. |