{"$schema":"https://ui.shadcn.com/schema/registry-item.json","name":"skeleton-swap","type":"registry:ui","title":"Skeleton Swap","description":"A shimmering placeholder that dissolves into the real content when loading ends: the skeleton blurs out, the content sharpens in and the box eases to its new height.","dependencies":["motion","react-use-measure"],"registryDependencies":["utils"],"files":[{"path":"registry/ui/skeleton-swap.tsx","type":"registry:ui","content":"\"use client\";\n\nimport { AnimatePresence, MotionConfig, motion } from \"motion/react\";\nimport type { ReactNode } from \"react\";\nimport useMeasure from \"react-use-measure\";\nimport { cn } from \"@/lib/utils\";\n\nexport interface SkeletonSwapProps {\n  /** Show the skeleton while true; the content cross-fades in when it turns false. */\n  loading: boolean;\n  /** The real content. */\n  children: ReactNode;\n  /** Custom placeholder. Defaults to an avatar and text lines. */\n  skeleton?: ReactNode;\n  /** Text lines in the default placeholder. */\n  lines?: number;\n  /** Show a round avatar in the default placeholder. */\n  avatar?: boolean;\n  /** Sweep a highlight across the placeholder. */\n  shimmer?: boolean;\n  /** Cross-fade length in seconds. */\n  duration?: number;\n  className?: string;\n}\n\n// Deterministic widths so server and client render the same placeholder.\nconst WIDTHS = [92, 78, 85, 64, 88, 71];\n\nconst css = `\n@keyframes skeleton-swap-sweep { from { background-position: 150% 0 } to { background-position: -50% 0 } }\n.skeleton-swap-bar {\n  background: color-mix(in oklab, var(--muted-foreground) 16%, transparent);\n}\n.skeleton-swap-shimmer .skeleton-swap-bar {\n  background-image: linear-gradient(100deg, transparent 30%, color-mix(in oklab, var(--foreground) 9%, transparent) 50%, transparent 70%);\n  background-size: 200% 100%;\n  animation: skeleton-swap-sweep 1.4s ease-in-out infinite;\n}\n@media (prefers-reduced-motion: reduce) { .skeleton-swap-shimmer .skeleton-swap-bar { animation: none } }\n`;\n\nfunction DefaultSkeleton({ lines, avatar }: { lines: number; avatar: boolean }) {\n  return (\n    <div className=\"flex gap-3\">\n      {avatar && <div className=\"skeleton-swap-bar size-10 shrink-0 rounded-full\" />}\n      <div className=\"flex-1 space-y-2.5 pt-1\">\n        {Array.from({ length: lines }, (_, i) => (\n          <div key={i} className=\"skeleton-swap-bar h-3 rounded-full\" style={{ width: `${i === 0 ? 45 : WIDTHS[i % WIDTHS.length]}%` }} />\n        ))}\n      </div>\n    </div>\n  );\n}\n\n/**\n * Holds a pulsing placeholder while data loads, then dissolves it into the real\n * content: the placeholder blurs out, the content sharpens in, and the box eases\n * to the content's height instead of jumping.\n */\nexport function SkeletonSwap({\n  loading,\n  children,\n  skeleton,\n  lines = 3,\n  avatar = true,\n  shimmer = true,\n  duration = 0.45,\n  className,\n}: SkeletonSwapProps) {\n  const [ref, { height }] = useMeasure();\n  const fade = { duration, ease: [0.22, 1, 0.36, 1] as const };\n\n  return (\n    <MotionConfig reducedMotion=\"user\">\n      <style href=\"skeleton-swap\" precedence=\"default\">\n        {css}\n      </style>\n      <motion.div\n        className={cn(\"relative overflow-hidden\", shimmer && \"skeleton-swap-shimmer\", className)}\n        animate={{ height: height || \"auto\" }}\n        initial={false}\n        transition={fade}\n        aria-busy={loading}\n      >\n        <div ref={ref} className=\"grid\">\n          <AnimatePresence initial={false}>\n            {loading ? (\n              <motion.div\n                key=\"skeleton\"\n                aria-hidden\n                className=\"[grid-area:1/1]\"\n                exit={{ opacity: 0, filter: \"blur(6px)\" }}\n                transition={fade}\n              >\n                {skeleton ?? <DefaultSkeleton lines={lines} avatar={avatar} />}\n              </motion.div>\n            ) : (\n              <motion.div\n                key=\"content\"\n                className=\"[grid-area:1/1]\"\n                initial={{ opacity: 0, filter: \"blur(6px)\", y: 4 }}\n                animate={{ opacity: 1, filter: \"blur(0px)\", y: 0 }}\n                transition={fade}\n              >\n                {children}\n              </motion.div>\n            )}\n          </AnimatePresence>\n        </div>\n      </motion.div>\n    </MotionConfig>\n  );\n}\n"}]}