Skeleton
Placeholder while content loads (> 300ms).
Motion: Gentle pulse. SkeletonReveal cross-fades + cross-blurs from the placeholder to the loaded content.
Installation
npx shadcn@latest add @craft/skeletonSource
components/ui/skeleton.tsx
import { cn } from "cn"
function Skeleton({ className, ...props }: React.ComponentProps<"div">) {
return (
<div
data-slot="skeleton"
className={cn("animate-pulse rounded-md bg-muted", className)}
{...props}
/>
)
}
export { Skeleton }
components/ui/skeleton-reveal.tsx
"use client"
import { AnimatePresence, motion } from "motion/react"
import { cn } from "cn"
import { duration, ease } from "@/lib/motion"
/**
* Swaps a skeleton for the loaded content with a cross-fade and cross-blur,
* instead of a hard cut. Both sit in the same grid cell while they cross, so
* nothing jumps. Shape the `fallback` like the content (same heights) for the
* smoothest hand-off. First render doesn't animate.
*
* <SkeletonReveal loading={isLoading} fallback={<RowsSkeleton />}><Rows /></SkeletonReveal>
*/
function SkeletonReveal({
loading,
fallback,
className,
children,
}: {
loading: boolean
fallback: React.ReactNode
className?: string
children: React.ReactNode
}) {
return (
<div data-slot="skeleton-reveal" aria-busy={loading || undefined} className={cn("grid *:[grid-area:1/1] *:min-w-0", className)}>
<AnimatePresence initial={false}>
{loading ? (
<motion.div
key="skeleton"
initial={{ opacity: 0 }}
animate={{ opacity: 1, transition: { duration: duration.fast, ease: ease.out } }}
exit={{ opacity: 0, filter: "blur(4px)", transition: { duration: duration.slow, ease: ease.in } }}
>
{fallback}
</motion.div>
) : (
<motion.div
key="content"
initial={{ opacity: 0, filter: "blur(6px)", y: 4 }}
animate={{ opacity: 1, filter: "blur(0px)", y: 0, transition: { duration: 0.4, ease: ease.out } }}
exit={{ opacity: 0, transition: { duration: duration.fast, ease: ease.in } }}
>
{children}
</motion.div>
)}
</AnimatePresence>
</div>
)
}
export { SkeletonReveal }